Changeset 20210


Ignore:
Timestamp:
02/18/16 16:06:14 (9 years ago)
Author:
Eric.Larour
Message:

CHG: simplifying, adding some capabilities (provide a basin name for each step, so you can duplicate
steps if they deal with separate basins).

File:
1 edited

Legend:

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

    r20130 r20210  
    1 %ORGANIZER class definition
     1%XORGANIZER class definition
    22%
    33%   Supported options:
     
    55%      prefix:     prefix for saved model names
    66%      steps:      requested steps
    7 %      trunkprefix:prefix of previous run with a different prefix. Used to branch.
    87%
    98%   Usage:
    10 %      org = organizer(varargin)
     9%      org = xorganizer(varargin)
    1110%
    1211%   Examples:
    13 %      org = organizer('repository','Models/','prefix','AGU2015','steps',0);  %build an empty organizer object with a given repository
     12%      org = xorganizer('repository','Models/','prefix','AGU2015','steps',0);  %build an empty organizer object with a given repository
    1413
    15 classdef organizer < handle
     14classdef xorganizer < handle
    1615    properties (SetAccess=private)
    1716                % {{{
     
    2120                repository    ='./';
    2221                prefix        ='model.';
    23                 trunkprefix   ='';
    2422                steps         =[];
    2523                requestedsteps=[0];
    26                 upload_server='';
    27                 upload_path='';
    28                 upload_login='';
    29                 upload_port=0;
    30                 download=0;
    3124                %}}}
    3225        end
    3326        methods
    34                 function org=organizer(varargin) % {{{
     27                function org=xorganizer(varargin) % {{{
    3528
    3629                        %process options
     
    5245                        org.requestedsteps=getfieldvalue(options,'steps',0);
    5346
    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'); end
    58                                 if ~strcmp(regexprep(trunkprefix,'\s+',''),trunkprefix), error('trunkprefix should not have any white space'); end
    59                                 org.trunkprefix=trunkprefix;
    60                         end
    61 
    62                         %Get upload information, if provided
    63                         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 
    6947                end
    7048                %}}}
    7149                function disp(org) % {{{
    7250                        disp(sprintf('   Repository: ''%s''',org.repository));
    73                         disp(sprintf('   Prefix:     ''%s''',org.prefix));
     51                        disp(sprintf('   Prefix:     ''%s''\n',org.prefix));
    7452                        if isempty(org.steps)
    7553                                disp('   no step');
     
    7856                                        disp(sprintf('   step #%2i: ''%s''',org.steps(i).id,org.steps(i).string));
    7957                                end
    80                         end
    81                         if isempty(org.upload_server),
    82                                 disp('   no upload info');
    83                         else
    84                                 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));
    8858                        end
    8959                end
     
    12393                        end
    12494
    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 ]);
    13897                end%}}}
    13998                function loaddata(org,string),% {{{
     
    149108                        end
    150109
    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 ]);
    164112                end%}}}
    165                 function bool=perform(org,string) % {{{
     113                function bool=perform(org,varargin) % {{{
    166114
    167115                        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
    168123
    169124                        %Some checks
     
    192147                                bool=true;
    193148                        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 download
    198                                 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                                                 end
    207                                         end
    208                                 end
    209 
    210                                 %reset bool to false, so we stick with only downloading
    211                                 bool=false;
    212                         end
    213 
    214149                end%}}}
    215150                function savemodel(org,md) % {{{
Note: See TracChangeset for help on using the changeset viewer.