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

CHG: can now load old models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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');
Note: See TracChangeset for help on using the changeset viewer.