Changeset 20210
- Timestamp:
- 02/18/16 16:06:14 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/organizer.m
r20130 r20210 1 % ORGANIZER class definition1 %XORGANIZER class definition 2 2 % 3 3 % Supported options: … … 5 5 % prefix: prefix for saved model names 6 6 % steps: requested steps 7 % trunkprefix:prefix of previous run with a different prefix. Used to branch.8 7 % 9 8 % Usage: 10 % org = organizer(varargin)9 % org = xorganizer(varargin) 11 10 % 12 11 % Examples: 13 % org = organizer('repository','Models/','prefix','AGU2015','steps',0); %build an empty organizer object with a given repository12 % org = xorganizer('repository','Models/','prefix','AGU2015','steps',0); %build an empty organizer object with a given repository 14 13 15 classdef organizer < handle14 classdef xorganizer < handle 16 15 properties (SetAccess=private) 17 16 % {{{ … … 21 20 repository ='./'; 22 21 prefix ='model.'; 23 trunkprefix ='';24 22 steps =[]; 25 23 requestedsteps=[0]; 26 upload_server='';27 upload_path='';28 upload_login='';29 upload_port=0;30 download=0;31 24 %}}} 32 25 end 33 26 methods 34 function org= organizer(varargin) % {{{27 function org=xorganizer(varargin) % {{{ 35 28 36 29 %process options … … 52 45 org.requestedsteps=getfieldvalue(options,'steps',0); 53 46 54 %Get trunk prefix (only if provided by user)55 if exist(options,'trunkprefix'),56 trunkprefix=getfieldvalue(options,'trunkprefix','');57 if ~ischar(trunkprefix), error('trunkprefix is not a string'); end58 if ~strcmp(regexprep(trunkprefix,'\s+',''),trunkprefix), error('trunkprefix should not have any white space'); end59 org.trunkprefix=trunkprefix;60 end61 62 %Get upload information, if provided63 org.upload_server=getfieldvalue(options,'upload_server','');64 org.upload_path=getfieldvalue(options,'upload_path','');65 org.upload_login=getfieldvalue(options,'upload_login','');66 org.upload_port=getfieldvalue(options,'upload_port',0);67 org.download=getfieldvalue(options,'download',0);68 69 47 end 70 48 %}}} 71 49 function disp(org) % {{{ 72 50 disp(sprintf(' Repository: ''%s''',org.repository)); 73 disp(sprintf(' Prefix: ''%s'' ',org.prefix));51 disp(sprintf(' Prefix: ''%s''\n',org.prefix)); 74 52 if isempty(org.steps) 75 53 disp(' no step'); … … 78 56 disp(sprintf(' step #%2i: ''%s''',org.steps(i).id,org.steps(i).string)); 79 57 end 80 end81 if isempty(org.upload_server),82 disp(' no upload info');83 else84 disp(sprintf(' upload_server: ''%s''',org.upload_server));85 disp(sprintf(' upload_login: ''%s''',org.upload_login));86 disp(sprintf(' upload_path: ''%s''',org.upload_path));87 disp(sprintf(' upload_port: ''%i''',org.upload_port));88 58 end 89 59 end … … 123 93 end 124 94 125 %If we are here, the model has not been found. Try trunk prefix if provided 126 if ~isempty(org.trunkprefix), 127 path2=[org.repository '/' org.trunkprefix string]; 128 if ~exist(path2,'file'), 129 error(['Could find neither ' path ', nor ' path2]); 130 else 131 disp(['--> Branching ' org.prefix ' from trunk ' org.trunkprefix]); 132 md=loadmodel(path2); 133 return; 134 end 135 else 136 error(['Could not find ' path ]); 137 end 95 %If we are here, the data has not been found. 96 error(['Could not find ' path ]); 138 97 end%}}} 139 98 function loaddata(org,string),% {{{ … … 149 108 end 150 109 151 %If we are here, the data has not been found. Try trunk prefix if provided 152 if ~isempty(org.trunkprefix), 153 path2=[org.repository '/' org.trunkprefix string]; 154 if ~exist(path2,'file'), 155 error(['Could find neither ' path ', nor ' path2]); 156 else 157 disp(['--> Branching ' org.prefix ' from trunk ' org.trunkprefix]); 158 evalin('caller',['load -mat ' path2]); 159 return; 160 end 161 else 162 error(['Could not find ' path ]); 163 end 110 %If we are here, the data has not been found. 111 error(['Could not find ' path ]); 164 112 end%}}} 165 function bool=perform(org, string) % {{{113 function bool=perform(org,varargin) % {{{ 166 114 167 115 bool=false; 116 117 %group,string are the variable arguments length: 118 if nargin==2, 119 string=varargin{1}; 120 elseif nargin==3, 121 string=sprintf('%s.%s',varargin{1},varargin{2}); 122 end 168 123 169 124 %Some checks … … 192 147 bool=true; 193 148 end 194 195 %But if download is requested, we are downloading and skipping the step:196 if ismember(org.currentstep,org.requestedsteps) & org.download,197 %load the model if it exists, and download198 name=[org.repository '/' org.prefix org.steps(org.currentstep).string ];199 if exist(name,'file'),200 md=loadmodel(name);201 if isa(md,'model'),202 if ~isempty(md.settings.upload_filename),203 disp(sprintf(' downloading model'));204 md=download(md);205 save(name,'md','-v7.3');206 end207 end208 end209 210 %reset bool to false, so we stick with only downloading211 bool=false;212 end213 214 149 end%}}} 215 150 function savemodel(org,md) % {{{
Note:
See TracChangeset
for help on using the changeset viewer.