Changeset 15768


Ignore:
Timestamp:
08/09/13 10:07:08 (12 years ago)
Author:
Mathieu Morlighem
Message:

CHG: can now load old models

Location:
issm/trunk-jpl/src/m/classes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/classes/masstransport.m

    r15767 r15768  
    1414                 requested_outputs      = NaN;
    1515        end
     16        methods (Static)
     17                function obj = loadobj(obj) % {{{
     18                        % This function is directly called by matlab when a model object is
     19                        % loaded. If the input is a struct it is an old version of this class and
     20                        % old fields must be recovered (make sure they are in the deprecated
     21                        % model properties)
     22
     23                        if verLessThan('matlab','7.9'),
     24                                disp('Warning: your matlab version is old and there is a risk that load does not work correctly');
     25                                disp('         if the model is not loaded correctly, rename temporarily loadobj so that matlab does not use it');
     26
     27                                % This is a Matlab bug: all the fields of md have their default value
     28                                % Example of error message:
     29                                % Warning: Error loading an object of class 'model':
     30                                % Undefined function or method 'exist' for input arguments of type 'cell'
     31                                %
     32                                % This has been fixed in MATLAB 7.9 (R2009b) and later versions
     33                        end
     34
     35                        if isstruct(obj)
     36                                disp('Recovering masstransport from older version');
     37                                objstruct = obj;
     38                                obj = structtoobj(masstransport(),objstruct);
     39                        end
     40                end% }}}
     41        end
    1642        methods
    1743                function obj = masstransport(varargin) % {{{
     
    1945                                case 0
    2046                                        obj=setdefaultparameters(obj);
     47                                case 1
     48                                        inputstruct=varargin{1};
     49                                        list1 = properties('masstransport');
     50                                        list2 = fieldnames(inputstruct);
     51                                        for i=1:length(list1)
     52                                                fieldname = list1{i};
     53                                                if ismember(fieldname,list2),
     54                                                        obj.(fieldname) = inputstruct.(fieldname);
     55                                                end
     56                                        end
    2157                                otherwise
    2258                                        error('constructor not supported');
  • TabularUnified issm/trunk-jpl/src/m/classes/model/model.m

    r15767 r15768  
    865865                        if isfield(structmd,'max_steadystate_iterations'), md.steadystate.maxiter=structmd.max_steadystate_iterations; end
    866866                        if isfield(structmd,'isdiagnostic'), md.transient.isdiagnostic=structmd.isdiagnostic; end
    867                         if isfield(structmd,'ismasstransport'), md.transient.ismasstransport=structmd.ismasstransport; end
     867                        if isfield(structmd,'isprognostic'), md.transient.ismasstransport=structmd.isprognostic; end
    868868                        if isfield(structmd,'isthermal'), md.transient.isthermal=structmd.isthermal; end
    869869                        if isfield(structmd,'control_analysis'), md.inversion.iscontrol=structmd.control_analysis; end
     
    942942                                md.verbose=verbose;
    943943                        end
    944                         if size(md.diagnostic.icefront,2)==3 || size(md.diagnostic.icefront,2)==5,
    945                                 front=md.diagnostic.icefront;
    946                                 md.diagnostic.icefront=[front 1*md.mask.elementonfloatingice(front(:,end))];
    947                         end
     944
    948945                        if isfield(structmd,'spcvelocity'),
    949946                                md.diagnostic.spcvx=NaN*ones(md.mesh.numberofvertices,1);
     
    10461043                                md.diagnostic.referential=NaN*ones(md.mesh.numberofvertices,6);
    10471044                        end
    1048 
    10491045                        if ~isfield(structmd,'loadingforce');
    10501046                                md.diagnostic.loadingforce=0*ones(md.mesh.numberofvertices,3);
     1047                        end
     1048
     1049                        %2013 August 9
     1050                        if isfield(structmd,'prognostic') & isa(structmd.prognostic,'prognostic'),
     1051                                disp('Recovering old prognostic class');
     1052                                md.masstransport=masstransport(structmd.prognostic);
    10511053                        end
    10521054                end% }}}
  • TabularUnified issm/trunk-jpl/src/m/classes/oldclasses/diagnostic.m

    r15614 r15768  
    2626                requested_outputs        = NaN;
    2727        end
     28        methods (Static)
     29                function obj = loadobj(obj) % {{{
     30                        % This function is directly called by matlab when a model object is
     31                        % loaded. If the input is a struct it is an old version of this class and
     32                        % old fields must be recovered (make sure they are in the deprecated
     33                        % model properties)
     34
     35                        if verLessThan('matlab','7.9'),
     36                                disp('Warning: your matlab version is old and there is a risk that load does not work correctly');
     37                                disp('         if the model is not loaded correctly, rename temporarily loadobj so that matlab does not use it');
     38
     39                                % This is a Matlab bug: all the fields of md have their default value
     40                                % Example of error message:
     41                                % Warning: Error loading an object of class 'model':
     42                                % Undefined function or method 'exist' for input arguments of type 'cell'
     43                                %
     44                                % This has been fixed in MATLAB 7.9 (R2009b) and later versions
     45                        end
     46
     47                        if size(md.diagnostic.icefront,2)==3 || size(md.diagnostic.icefront,2)==5,
     48                                front=md.diagnostic.icefront;
     49                                md.diagnostic.icefront=[front 1*md.mask.elementonfloatingice(front(:,end))];
     50                        end
     51                end% }}}
     52        end
    2853        methods
    2954                function obj = diagnostic(varargin) % {{{
     
    151176
    152177                end % }}}
     178
    153179                function marshall(obj,md,fid) % {{{
    154180                        WriteData(fid,'object',obj,'fieldname','spcvx','format','DoubleMat','mattype',1,'forcinglength',md.mesh.numberofvertices+1);
Note: See TracChangeset for help on using the changeset viewer.