Changeset 14278


Ignore:
Timestamp:
01/19/13 22:24:37 (12 years ago)
Author:
Eric.Larour
Message:

CHG: added savedata and loaddata classes in organizer, very handy when a step does not act on a model, but you want to save an arbitrary number of variables

File:
1 edited

Legend:

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

    r14228 r14278  
    112112                        end
    113113                end%}}}
     114                function md=loaddata(org,string),% {{{
     115
     116                        %Get model path
     117                        if ~ischar(string), error('argument provided is not a string'); end
     118                        path=[org.repository '/' org.prefix string];
     119
     120                        %figure out if the data is there, otherwise, we have to use the default path supplied by user.
     121                        if exist(path,'file') | exist([path '.mat'],'file'),
     122                                evalin('caller',['load -mat ' path]);
     123                                return;
     124                        end
     125
     126                        %If we are here, the data has not been found. Try trunk prefix if provided
     127                        if ~isempty(org.trunkprefix),
     128                                path2=[org.repository '/' org.trunkprefix string];
     129                                if ~exist(path2,'file'),
     130                                        error(['Could find neither ' path ', nor ' path2]);
     131                                else
     132                                        disp(['--> Branching ' org.prefix ' from trunk ' org.trunkprefix]);
     133                                        evalin('caller',['load -mat ' path2]);
     134                                        return;
     135                                end
     136                        else
     137                                error(['Could not find ' path ]);
     138                        end
     139                end%}}}
    114140                function bool=perform(org,string) % {{{
    115141
     
    159185                        save(name,'md','-v7.3');
    160186                end%}}}
     187                function savedata(org,varargin) % {{{
     188
     189                        %check
     190                        if (org.currentstep==0), error('Cannot save data because organizer (org) is empty! Make sure you did not skip any perform call'); end
     191                        if (org.currentstep>length(org.steps)), error('Cannot save data because organizer (org) is not up to date!'); end
     192
     193                        name=[org.repository '/' org.prefix org.steps(org.currentstep).string ];
     194                        disp(['saving data in: ' name]);
     195
     196                        %check that md is a model
     197                        if (org.currentstep>length(org.steps)), error(['organizer error message: element with id ' num2str(org.currentstep) ' not found']); end
     198
     199                        %list of variable names:
     200                        variables='';
     201                        for i=2:nargin,
     202                                variables=[variables ',' '''' inputname(i) ''''];
     203                                eval([inputname(i) '= varargin{' num2str(i-1) '};']);
     204                        end
     205                        eval(['save(''' name '''' variables ',''-v7.3'');']);
     206                end%}}}
    161207        end
    162208end
Note: See TracChangeset for help on using the changeset viewer.