source: issm/trunk/test/NightlyRun/runme.m@ 14067

Last change on this file since 14067 was 14067, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 14066

  • Property svn:executable set to *
File size: 7.5 KB
Line 
1function 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
34ISSM_DIR=issmdir();
35
36%Check inputs
37% {{{
38if nargout>1
39 help runme
40 error('runme error message: bad usage');
41end
42
43%recover options
44options=pairoptions(varargin{:});
45% }}}
46
47%Process options
48%GET benchmark {{{
49benchmark=getfieldvalue(options,'benchmark','nightly');
50if ~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';
53end
54% }}}
55%GET procedure {{{
56procedure=getfieldvalue(options,'procedure','check');
57if ~ismember(procedure,{'check','update'})
58 disp('runme warning: procedure not supported, defaulting to test ''check''')
59 procedure='check';
60end
61% }}}
62%GET output {{{
63output=getfieldvalue(options,'output','none');
64if ~ismember(output,{'nightly','daily','none'})
65 disp('runme warning: output not supported, defaulting to test ''none''')
66 output='none';
67end
68% }}}
69%GET RANK and NUMPROCS for multithreaded runs {{{
70rank=getfieldvalue(options,'rank',1);
71numprocs=getfieldvalue(options,'numprocs',1);
72if (numprocs<rank), numprocs=1; end
73% }}}
74%GET ids {{{
75flist=dir;%use dir, as it seems to act OS independent
76list_ids=[];
77for 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 list_ids(end+1)=eval(flist(i).name(5:end-2)); %Keep test id only (skip 'test' and '.m')
82 end
83end
84[i1,i2]=parallelrange(rank,numprocs,length(list_ids)); %Get tests for this cpu only
85list_ids=list_ids(i1:i2);
86
87test_ids=getfieldvalue(options,'id',list_ids);
88test_ids=intersect(test_ids,list_ids);
89% }}}
90%GET exclude {{{
91exclude_ids=getfieldvalue(options,'exclude',[]);
92exclude_ids=[exclude_ids];
93pos=find(ismember(test_ids,exclude_ids));
94test_ids(pos)=[];
95% }}}
96%Process Ids according to benchmarks{{{
97if strcmpi(benchmark,'nightly'),
98 test_ids=intersect(test_ids,[1:999]);
99elseif strcmpi(benchmark,'validation'),
100 test_ids=intersect(test_ids,[1001:1999]);
101elseif strcmpi(benchmark,'ismip'),
102 test_ids=intersect(test_ids,[1101:1199]);
103elseif strcmpi(benchmark,'eismint'),
104 test_ids=intersect(test_ids,[1201:1299]);
105elseif strcmpi(benchmark,'thermal'),
106 test_ids=intersect(test_ids,[1301:1399]);
107elseif strcmpi(benchmark,'mesh'),
108 test_ids=intersect(test_ids,[1401:1499]);
109elseif strcmpi(benchmark,'tranforcing'),
110 test_ids=intersect(test_ids,[1501:1502]);
111elseif strcmpi(benchmark,'referential'),
112 test_ids=intersect(test_ids,[1601:1602]);
113elseif strcmpi(benchmark,'adolc'),
114 test_ids=intersect(test_ids,[3001:3020]);
115end
116% }}}
117
118%Loop over tests and launch sequence
119root=pwd;
120for id=test_ids,
121 try,
122
123 %Execute test
124 eval(['cd ' root ]);
125 id_string=IdToName(id);
126 eval(['test' num2str(id)]);
127
128 %UPDATE ARCHIVE?
129 archive_name=['Archive' num2str(id) ];
130 if strcmpi(procedure,'update'),
131 delete(['../Archives/' archive_name '.nc'])
132 for k=1:length(field_names),
133 field=field_values{k};
134 % matlab writes the dimensions reversed and matrices transposed into netcdf, so compensate for that
135 nccreate(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)],...
136 'Dimensions',{[archive_name '_field' num2str(k) '_2'] size(field,2) [archive_name '_field' num2str(k) '_1'] size(field,1)},...
137 'Format','classic');
138 ncwrite(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)],transpose(field));
139 end
140 disp(sprintf(['File ./../Archives/' archive_name '.nc saved\n']));
141
142 %ELSE: CHECK TEST
143 else,
144 for k=1:length(field_names),
145
146 try,
147 %Get field and tolerance
148 field=field_values{k};
149 fieldname=field_names{k};
150 tolerance=field_tolerances{k};
151
152 %compare to archive
153 % matlab reads the dimensions reversed and matrices transposed from netcdf, so compensate for that
154 archive=transpose(ncread(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)]));
155 error_diff=full(max(abs(archive(:)-field(:)))/(max(abs(archive))+eps));
156
157 %disp test result
158 if (error_diff>tolerance);
159 disp(sprintf(['ERROR difference: %-7.2g > %7.2g test id: %i test name: %s field: %s'],...
160 error_diff,tolerance,id,id_string,fieldname));
161 else
162 disp(sprintf(['SUCCESS difference: %-7.2g < %7.2g test id: %i test name: %s field: %s'],...
163 error_diff,tolerance,id,id_string,fieldname));
164 end
165
166 catch me2
167
168 %something went wrong, print failure message:
169 directory=strsplit(pwd,'/');
170 message=getReport(me2);
171 if strcmpi(output,'nightly')
172 fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
173 fprintf(fid,'%s',message);
174 fprintf(fid,'\n------------------------------------------------------------------\n');
175 fclose(fid);
176 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
177 elseif strcmpi(output,'daily');
178 fid=fopen([ISSM_DIR '/dailylog/matlaberror.log'], 'at');
179 fprintf(fid,'%s',message);
180 fprintf(fid,'\n------------------------------------------------------------------\n');
181 fclose(fid);
182 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
183 else
184 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
185 rethrow(me2);
186 end
187 end
188 end
189 end
190
191 catch me,
192
193 %something went wrong, print failure message:
194 directory=strsplit(pwd,'/');
195 message=getReport(me);
196 if strcmpi(output,'nightly')
197 fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
198 fprintf(fid,'%s',message);
199 fprintf(fid,'\n------------------------------------------------------------------\n');
200 fclose(fid);
201 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
202 elseif strcmpi(output,'daily');
203 fid=fopen([ISSM_DIR '/dailylog/matlaberror.log'], 'at');
204 fprintf(fid,'%s',message);
205 fprintf(fid,'\n------------------------------------------------------------------\n');
206 fclose(fid);
207 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
208 else
209 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
210 rethrow(me);
211 end
212 end
213end
214
215%output md if requested
216if nargout==1
217 varargout{1}=md;
218end
Note: See TracBrowser for help on using the repository browser.