1 | function varargout=runme(varargin)
|
---|
2 | %RUNME - test deck for ISSM nightly runs
|
---|
3 | %
|
---|
4 | % In a test deck directory (tests/Vertification/NightlyRun for example)
|
---|
5 | % The following command will launch all the existing tests:
|
---|
6 | % >> runme
|
---|
7 | % To run the tests 101 and 102:
|
---|
8 | % >> runme('id',[101 102])
|
---|
9 | % etc...
|
---|
10 | %
|
---|
11 | % Available options:
|
---|
12 | % 'id' followed by the list of ids requested
|
---|
13 | % 'exclude' ids to be excluded from the test
|
---|
14 | % 'benchmark' 'nightly' (nightly run/ daily run)
|
---|
15 | % 'ismip' : validation of ismip-hom tests
|
---|
16 | % 'eismint': validation of eismint tests
|
---|
17 | % 'thermal': validation of thermal tests
|
---|
18 | % 'mesh' : validation of mesh tests
|
---|
19 | % 'adolc' : validation of adolc tests
|
---|
20 | % ...
|
---|
21 | % 'procedure' 'check' : run the test (default)
|
---|
22 | % 'update': update the archive
|
---|
23 | % 'model' : prepare the model but no test is run
|
---|
24 | %
|
---|
25 | % Usage:
|
---|
26 | % md=runme(varargin);
|
---|
27 | %
|
---|
28 | % Examples:
|
---|
29 | % runme;
|
---|
30 | % runme('exclude',101);
|
---|
31 | % md=runme('id',102,'procedure','model');
|
---|
32 |
|
---|
33 | %Get ISSM_DIR variable
|
---|
34 | ISSM_DIR=issmdir();
|
---|
35 |
|
---|
36 | %Check inputs
|
---|
37 | % {{{
|
---|
38 | if nargout>1
|
---|
39 | help runme
|
---|
40 | error('runme error message: bad usage');
|
---|
41 | end
|
---|
42 |
|
---|
43 | %recover options
|
---|
44 | options=pairoptions(varargin{:});
|
---|
45 | % }}}
|
---|
46 |
|
---|
47 | %Process options
|
---|
48 | %GET benchmark {{{
|
---|
49 | benchmark=getfieldvalue(options,'benchmark','nightly');
|
---|
50 | if ~ismember(benchmark,{'all','nightly','ismip','eismint','thermal','mesh','validation','tranforcing','adolc'})
|
---|
51 | disp('runme warning: benchmark not supported, defaulting to test ''nightly''')
|
---|
52 | benchmark='nightly';
|
---|
53 | end
|
---|
54 | % }}}
|
---|
55 | %GET procedure {{{
|
---|
56 | procedure=getfieldvalue(options,'procedure','check');
|
---|
57 | if ~ismember(procedure,{'check','update'})
|
---|
58 | disp('runme warning: procedure not supported, defaulting to test ''check''')
|
---|
59 | procedure='check';
|
---|
60 | end
|
---|
61 | % }}}
|
---|
62 | %GET output {{{
|
---|
63 | output=getfieldvalue(options,'output','none');
|
---|
64 | if ~ismember(output,{'nightly','daily','none'})
|
---|
65 | disp('runme warning: output not supported, defaulting to test ''none''')
|
---|
66 | output='none';
|
---|
67 | end
|
---|
68 | % }}}
|
---|
69 | %GET RANK and NUMPROCS for multithreaded runs {{{
|
---|
70 | rank=getfieldvalue(options,'rank',1);
|
---|
71 | numprocs=getfieldvalue(options,'numprocs',1);
|
---|
72 | if (numprocs<rank), numprocs=1; end
|
---|
73 | % }}}
|
---|
74 | %GET ids {{{
|
---|
75 | flist=dir;%use dir, as it seems to act OS independent
|
---|
76 | list_ids=[];
|
---|
77 | for i=1:numel(flist),
|
---|
78 | if ( strncmp(flist(i).name,'test',4) &... %File name must start with 'test'
|
---|
79 | strncmp(fliplr(flist(i).name),fliplr('.m'),2)&... %File name must end by '.m'
|
---|
80 | ~strcmp(flist(i).name,'test.m')) %File name must be different than 'test.m'
|
---|
81 | id=str2num(flist(i).name(5:end-2));
|
---|
82 | if isempty(id),
|
---|
83 | disp(['WARNING: ignore file ' flist(i).name ]);
|
---|
84 | else
|
---|
85 | list_ids(end+1)=eval(flist(i).name(5:end-2)); %Keep test id only (skip 'test' and '.m')
|
---|
86 | end
|
---|
87 | end
|
---|
88 | end
|
---|
89 | [i1,i2]=parallelrange(rank,numprocs,length(list_ids)); %Get tests for this cpu only
|
---|
90 | list_ids=list_ids(i1:i2);
|
---|
91 |
|
---|
92 | test_ids=getfieldvalue(options,'id',list_ids);
|
---|
93 | test_ids=intersect(test_ids,list_ids);
|
---|
94 | % }}}
|
---|
95 | %GET exclude {{{
|
---|
96 | exclude_ids=getfieldvalue(options,'exclude',[]);
|
---|
97 | exclude_ids=[exclude_ids];
|
---|
98 | pos=find(ismember(test_ids,exclude_ids));
|
---|
99 | test_ids(pos)=[];
|
---|
100 | % }}}
|
---|
101 | %Process Ids according to benchmarks{{{
|
---|
102 | if strcmpi(benchmark,'nightly'),
|
---|
103 | test_ids=intersect(test_ids,[1:999]);
|
---|
104 | elseif strcmpi(benchmark,'validation'),
|
---|
105 | test_ids=intersect(test_ids,[1001:1999]);
|
---|
106 | elseif strcmpi(benchmark,'ismip'),
|
---|
107 | test_ids=intersect(test_ids,[1101:1199]);
|
---|
108 | elseif strcmpi(benchmark,'eismint'),
|
---|
109 | test_ids=intersect(test_ids,[1201:1299]);
|
---|
110 | elseif strcmpi(benchmark,'thermal'),
|
---|
111 | test_ids=intersect(test_ids,[1301:1399]);
|
---|
112 | elseif strcmpi(benchmark,'mesh'),
|
---|
113 | test_ids=intersect(test_ids,[1401:1499]);
|
---|
114 | elseif strcmpi(benchmark,'tranforcing'),
|
---|
115 | test_ids=intersect(test_ids,[1501:1502]);
|
---|
116 | elseif strcmpi(benchmark,'referential'),
|
---|
117 | test_ids=intersect(test_ids,[1601:1602]);
|
---|
118 | elseif strcmpi(benchmark,'adolc'),
|
---|
119 | test_ids=intersect(test_ids,[3001:3020]);
|
---|
120 | end
|
---|
121 | % }}}
|
---|
122 |
|
---|
123 | %Loop over tests and launch sequence
|
---|
124 | root=pwd;
|
---|
125 | for id=test_ids,
|
---|
126 | try,
|
---|
127 |
|
---|
128 | %Execute test
|
---|
129 | eval(['cd ' root ]);
|
---|
130 | id_string=IdToName(id);
|
---|
131 | eval(['test' num2str(id)]);
|
---|
132 |
|
---|
133 | %UPDATE ARCHIVE?
|
---|
134 | archive_name=['Archive' num2str(id) ];
|
---|
135 | if strcmpi(procedure,'update'),
|
---|
136 | delete(['../Archives/' archive_name '.nc'])
|
---|
137 | for k=1:length(field_names),
|
---|
138 | field=field_values{k};
|
---|
139 | % matlab writes the dimensions reversed and matrices transposed into netcdf, so compensate for that
|
---|
140 | nccreate(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)],...
|
---|
141 | 'Dimensions',{[archive_name '_field' num2str(k) '_2'] size(field,2) [archive_name '_field' num2str(k) '_1'] size(field,1)},...
|
---|
142 | 'Format','classic');
|
---|
143 | ncwrite(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)],transpose(field));
|
---|
144 | end
|
---|
145 | disp(sprintf(['File ./../Archives/' archive_name '.nc saved\n']));
|
---|
146 |
|
---|
147 | %ELSE: CHECK TEST
|
---|
148 | else,
|
---|
149 | for k=1:length(field_names),
|
---|
150 |
|
---|
151 | try,
|
---|
152 | %Get field and tolerance
|
---|
153 | field=field_values{k};
|
---|
154 | fieldname=field_names{k};
|
---|
155 | tolerance=field_tolerances{k};
|
---|
156 |
|
---|
157 | %compare to archive
|
---|
158 | % matlab reads the dimensions reversed and matrices transposed from netcdf, so compensate for that
|
---|
159 | archive=transpose(ncread(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)]));
|
---|
160 | error_diff=full(max(abs(archive(:)-field(:)))/(max(abs(archive))+eps));
|
---|
161 |
|
---|
162 | %disp test result
|
---|
163 | if (error_diff>tolerance);
|
---|
164 | disp(sprintf(['ERROR difference: %-7.2g > %7.2g test id: %i test name: %s field: %s'],...
|
---|
165 | error_diff,tolerance,id,id_string,fieldname));
|
---|
166 | else
|
---|
167 | disp(sprintf(['SUCCESS difference: %-7.2g < %7.2g test id: %i test name: %s field: %s'],...
|
---|
168 | error_diff,tolerance,id,id_string,fieldname));
|
---|
169 | end
|
---|
170 |
|
---|
171 | catch me2
|
---|
172 |
|
---|
173 | %something went wrong, print failure message:
|
---|
174 | directory=strsplit(pwd,'/');
|
---|
175 | message=getReport(me2);
|
---|
176 | if strcmpi(output,'nightly')
|
---|
177 | fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
|
---|
178 | fprintf(fid,'%s',message);
|
---|
179 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
---|
180 | fclose(fid);
|
---|
181 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
---|
182 | elseif strcmpi(output,'daily');
|
---|
183 | fid=fopen([ISSM_DIR '/dailylog/matlaberror.log'], 'at');
|
---|
184 | fprintf(fid,'%s',message);
|
---|
185 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
---|
186 | fclose(fid);
|
---|
187 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
---|
188 | else
|
---|
189 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
---|
190 | rethrow(me2);
|
---|
191 | end
|
---|
192 | end
|
---|
193 | end
|
---|
194 | end
|
---|
195 |
|
---|
196 | catch me,
|
---|
197 |
|
---|
198 | %something went wrong, print failure message:
|
---|
199 | directory=strsplit(pwd,'/');
|
---|
200 | message=getReport(me);
|
---|
201 | if strcmpi(output,'nightly')
|
---|
202 | fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
|
---|
203 | fprintf(fid,'%s',message);
|
---|
204 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
---|
205 | fclose(fid);
|
---|
206 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
---|
207 | elseif strcmpi(output,'daily');
|
---|
208 | fid=fopen([ISSM_DIR '/dailylog/matlaberror.log'], 'at');
|
---|
209 | fprintf(fid,'%s',message);
|
---|
210 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
---|
211 | fclose(fid);
|
---|
212 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
---|
213 | else
|
---|
214 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
---|
215 | rethrow(me);
|
---|
216 | end
|
---|
217 | end
|
---|
218 | end
|
---|
219 |
|
---|
220 | %output md if requested
|
---|
221 | if nargout==1
|
---|
222 | varargout{1}=md;
|
---|
223 | end
|
---|