Debian Codegraph @

debian/tests/build2

raw symbols SCIP
1 #!/bin/sh
2 # autopkgtest check: Build and run a program against libmedc
3 # (C) 2013 Thomas Moulard
4 # (C) 2014 Anton Gladky
5 # Author: Thomas Moulard <[email protected]>
6 # Anton Gladky <[email protected]>
7
8 set -e
9
10 WORKDIR=$(mktemp -d)
11 trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
12 cd $WORKDIR
13 cat <<EOF > usescase.c
14 /* This file is part of MED.
15 *
16 * COPYRIGHT (C) 1999 - 2012 EDF R&D, CEA/DEN
17 * MED is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Lesser General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * MED is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public License
28 * along with MED. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31 /*
32 * Unitary tests to create parameters in MED files
33 */
34
35 #include <med.h>
36 #define MESGERR 1
37 #include <med_utils.h>
38
39 #include <string.h>
40
41 int main (int argc, char **argv)
42 {
43 med_idt fid;
44 const char filename[] = "Unittest_MEDparameter_1.med";
45 const char comment[] = "Parameters unit tests";
46 const char p1name[] = "FLOAT_PARAMETER";
47 const char p2name[] = "INT_PARAMETER_1";
48 const char p3name[] = "INT_PARAMETER_2";
49 const med_parameter_type p1type = MED_FLOAT64;
50 const med_parameter_type p2type = MED_INT;
51 const med_parameter_type p3type = MED_INT;
52 const char p1description[] = "PARAMETER 1 DESCRIPTION";
53 const char p2description[] = "PARAMETER 2 DESCRIPTION";
54 const char p3description[] = "PARAMETER 3 DESCRIPTION";
55 const char dtunit1[] = "DT UNIT P1";
56 const char dtunit2[] = "DT UNIT P2";
57 const char dtunit3[] = "DT UNIT P3";
58 med_int np;
59 char nameToRead[MED_NAME_SIZE+1];
60 char descriptionToRead[MED_COMMENT_SIZE+1];
61 med_parameter_type typeToRead;
62 char dtunitToRead[MED_SNAME_SIZE+1];
63 med_int nstepToRead;
64 int i,j;
65 med_float p1v1 = 6.98;
66 med_float p1v2 = 19.07;
67 med_float p1v3 = 78.0;
68 med_int p1numdt1 = MED_NO_DT;
69 med_int p1numdt2 = 1;
70 med_int p1numdt3 = 1;
71 med_int p1numit1 = MED_NO_IT;
72 med_int p1numit2 = 3;
73 med_int p1numit3 = 2;
74 med_float p1dt1 = 0.0;
75 med_float p1dt2 = 0.1;
76 med_float p1dt3 = 5.5;
77 const med_int p1ncpst = 3;
78 med_int p2v1 = 5;
79 med_int p2v2 = 6;
80 med_int p2numit1 = MED_NO_IT;
81 med_int p2numdt1 = MED_NO_DT;
82 med_float p2dt1 = 0.0;
83 const med_int p2ncpst = 1;
84 med_int p3v1 = 77;
85 med_int p3v2 = 89;
86 med_int p3numdt1 = 1;
87 med_int p3numit1 = 1;
88 med_float p3dt1 = 18.9;
89 med_int p3numdt2 = MED_NO_DT;
90 med_int p3numit2 = MED_NO_IT;
91 med_float p3dt2 = 0.0;
92 const med_int p3ncpst = 2;
93 med_int numdtToRead;
94 med_int numitToRead;
95 med_float dtToRead;
96 med_float fvalueToRead;
97 med_int ivalueToRead;
98
99 /* file creation */
100 fid = MEDfileOpen(filename,MED_ACC_CREAT);
101 if (fid < 0) {
102 MESSAGE("ERROR : file creation ...");
103 SSCRUTE(filename);
104 return -1;
105 }
106
107 if (MEDfileCommentWr(fid,comment) < 0) {
108 MESSAGE("ERROR : write comment ...");
109 SSCRUTE(comment);
110 return -1;
111 }
112
113 /* create a MED_FLOAT64 parameter */
114 if (MEDparameterCr(fid, p1name, p1type, p1description, dtunit1) < 0) {
115 MESSAGE("ERROR : parameter p1 creation ...");
116 SSCRUTE(p1name);
117 return -1;
118 }
119
120 if (MEDparameterValueWr(fid, p1name, p1numdt1, p1numit1, p1dt1, (unsigned char*) &p1v1) < 0) {
121 MESSAGE("ERROR : write p1v1 ...");
122 SSCRUTE(p1name);
123 return -1;
124 }
125 if (MEDparameterValueWr(fid, p1name, p1numdt2, p1numit2, p1dt2, (unsigned char*) &p1v2) < 0) {
126 MESSAGE("ERROR : write p1v2 ...");
127 SSCRUTE(p1name);
128 return -1;
129 }
130 if (MEDparameterValueWr(fid, p1name, p1numdt3, p1numit3, p1dt3, (unsigned char*) &p1v3) < 0) {
131 MESSAGE("ERROR : write p1v3 ...");
132 SSCRUTE(p1name);
133 return -1;
134 }
135
136 /* create a MED_INT parameter with different values */
137 if (MEDparameterCr(fid, p2name, p2type, p2description, dtunit2) < 0) {
138 MESSAGE("ERROR : paramter p2 creation ...");
139 SSCRUTE(p2name);
140 return -1;
141 }
142 if (MEDparameterValueWr(fid, p2name, p2numdt1, p2numit1, p2dt1, (unsigned char*) &p2v1) < 0) {
143 MESSAGE("ERROR : write p2v1 ...");
144 SSCRUTE(p2name);
145 return -1;
146 }
147 if (MEDparameterValueWr(fid, p2name, p2numdt1, p2numit1, p2dt1, (unsigned char*) &p2v2) < 0) {
148 MESSAGE("ERROR : write p2v2 on same computation step ...");
149 SSCRUTE(p2name);
150 return -1;
151 }
152
153 /* create another MED_INT parameter */
154 if (MEDparameterCr(fid, p3name, p3type, p3description, dtunit3) < 0) {
155 MESSAGE("ERROR : paramter p3 creation ...");
156 SSCRUTE(p3name);
157 return -1;
158 }
159 if (MEDparameterValueWr(fid, p3name, p3numdt1, p3numit1, p3dt1, (unsigned char*) &p3v1) < 0) {
160 MESSAGE("ERROR : write p3v1 ...");
161 SSCRUTE(p3name);
162 return -1;
163 }
164 if (MEDparameterValueWr(fid, p3name, p3numdt2, p3numit2, p3dt2, (unsigned char*) &p3v2) < 0) {
165 MESSAGE("ERROR : write p3v2 ...");
166 SSCRUTE(p3name);
167 return -1;
168 }
169
170 /* close file */
171 if (MEDfileClose(fid) < 0) {
172 MESSAGE("ERROR : file closing ...");
173 return -1;
174 }
175
176 /* open file in READ ONLY access mode */
177 fid = MEDfileOpen(filename,MED_ACC_RDONLY);
178 if (fid < 0) {
179 MESSAGE("ERROR : open in READ ONLY ACCESS mode ...");
180 SSCRUTE(filename);
181 return -1;
182 }
183
184 /* direct access to parameters */
185 if (MEDparameterInfoByName(fid, p1name, &typeToRead, descriptionToRead,
186 dtunitToRead, &nstepToRead) < 0) {
187 MESSAGE("ERROR : read information for parameter p1 ...");
188 SSCRUTE(p1name);
189 ISCRUTE(typeToRead);
190 SSCRUTE(descriptionToRead);
191 SSCRUTE(dtunitToRead);
192 ISCRUTE(nstepToRead);
193 return -1;
194 }
195 if ((typeToRead != p1type) || strcmp(descriptionToRead, p1description) ||
196 strcmp(dtunitToRead,dtunit1) || (nstepToRead != p1ncpst)) {
197 MESSAGE("ERROR : read information for parameter p1 : attributes ...");
198 SSCRUTE(p1name);
199 ISCRUTE(typeToRead);
200 SSCRUTE(descriptionToRead);
201 SSCRUTE(dtunitToRead);
202 ISCRUTE(nstepToRead);
203 return -1;
204 }
205
206 if (MEDparameterInfoByName(fid, p2name, &typeToRead, descriptionToRead,
207 dtunitToRead, &nstepToRead) < 0) {
208 MESSAGE("ERROR : read information for parameter p2 ...");
209 SSCRUTE(p2name);
210 ISCRUTE(typeToRead);
211 SSCRUTE(descriptionToRead);
212 SSCRUTE(dtunitToRead);
213 ISCRUTE(nstepToRead);
214 return -1;
215 }
216 if ((typeToRead != p2type) || strcmp(descriptionToRead, p2description) ||
217 strcmp(dtunitToRead,dtunit2) || (nstepToRead != p2ncpst)) {
218 MESSAGE("ERROR : read information for parameter p2 : attributes ...");
219 SSCRUTE(p2name);
220 ISCRUTE(typeToRead); ISCRUTE(p2type);
221 SSCRUTE(descriptionToRead); SSCRUTE(p2description);
222 SSCRUTE(dtunitToRead); SSCRUTE(dtunit2);
223 ISCRUTE(nstepToRead); ISCRUTE(p2ncpst);
224 return -1;
225 }
226
227 if (MEDparameterInfoByName(fid, p3name, &typeToRead, descriptionToRead,
228 dtunitToRead, &nstepToRead) < 0) {
229 MESSAGE("ERROR : read information for parameter p3 ...");
230 SSCRUTE(p3name);
231 ISCRUTE(typeToRead);
232 SSCRUTE(descriptionToRead);
233 SSCRUTE(dtunitToRead);
234 ISCRUTE(nstepToRead);
235 return -1;
236 }
237 if ((typeToRead != p3type) || strcmp(descriptionToRead, p3description) ||
238 strcmp(dtunitToRead,dtunit3) || (nstepToRead != p3ncpst)) {
239 MESSAGE("ERROR : read information for parameter p2 : attributes ...");
240 SSCRUTE(p3name);
241 ISCRUTE(typeToRead);
242 SSCRUTE(descriptionToRead);
243 SSCRUTE(dtunitToRead);
244 ISCRUTE(nstepToRead);
245 return -1;
246 }
247
248 /* how many parameter(s) in the file ? */
249 if ((np = MEDnParameter(fid)) < 0) {
250 MESSAGE("ERROR : read number of paremeter ...");
251 ISCRUTE(np);
252 return -1;
253 }
254 if (np != 3) {
255 MESSAGE("The number of parameter is 3 !");
256 ISCRUTE(np);
257 return -1;
258 }
259 /* TODO : A SUPPRIMER */
260 np=0;
261
262 /* read informations for each parameter */
263 for (i=0;i<np;i++) {
264
265 if (MEDparameterInfo(fid, i+1, nameToRead, &typeToRead, descriptionToRead,
266 dtunitToRead, &nstepToRead) < 0) {
267 MESSAGE("ERROR : read information for parameter p3 ...");
268 SSCRUTE(nameToRead);
269 ISCRUTE(typeToRead);
270 SSCRUTE(descriptionToRead);
271 SSCRUTE(dtunitToRead);
272 ISCRUTE(nstepToRead);
273 return -1;
274 }
275
276 if (i == 0)
277 if (strcmp(nameToRead, p1name) || (typeToRead != p1type) ||
278 strcmp(descriptionToRead, p1description) || strcmp(dtunitToRead,dtunit1)
279 || (nstepToRead != p1ncpst)) {
280 MESSAGE("ERROR : read information for parameter p1 : attributes ...");
281 SSCRUTE(nameToRead);
282 ISCRUTE(typeToRead);
283 SSCRUTE(descriptionToRead);
284 SSCRUTE(dtunitToRead);
285 ISCRUTE(nstepToRead);
286 return -1;
287 }
288
289 if (i == 1)
290 if ( strcmp(nameToRead, p2name) || (typeToRead != p2type) ||
291 strcmp(descriptionToRead, p2description) || strcmp(dtunitToRead,dtunit2)
292 || (nstepToRead != p2ncpst)) {
293 MESSAGE("ERROR : read information for parameter p2 : attributes ...");
294 SSCRUTE(nameToRead);
295 ISCRUTE(typeToRead);
296 SSCRUTE(descriptionToRead);
297 SSCRUTE(dtunitToRead);
298 ISCRUTE(nstepToRead);
299 return -1;
300 }
301
302 if (i == 3)
303 if (strcmp(nameToRead,p3name) || (typeToRead != p3type) ||
304 strcmp(descriptionToRead, p3description) || strcmp(dtunitToRead,dtunit3) ||
305 (nstepToRead != p3ncpst)) {
306 MESSAGE("ERROR : read information for parameter p2 : attributes ...");
307 SSCRUTE(nameToRead);
308 ISCRUTE(typeToRead);
309 SSCRUTE(descriptionToRead);
310 SSCRUTE(dtunitToRead);
311 ISCRUTE(nstepToRead);
312 return -1;
313 }
314
315 /* read informations about each computation step
316 and then read value for each parameter */
317 for (j=0; j<nstepToRead; j++) {
318
319 if (MEDparameterComputationStepInfo(fid, nameToRead, j+1,
320 &numdtToRead, &numitToRead, &dtToRead) < 0) {
321 MESSAGE("ERROR : read information about computation step ...");
322 SSCRUTE(nameToRead);
323 ISCRUTE(j);
324 ISCRUTE(numdtToRead);
325 ISCRUTE(numitToRead);
326 return -1;
327 }
328
329 if (typeToRead == MED_FLOAT64)
330 if (MEDparameterValueRd(fid, nameToRead, numdtToRead, numitToRead,
331 (unsigned char *) &fvalueToRead) < 0) {
332 MESSAGE("ERROR : read parameter value ...");
333 SSCRUTE(nameToRead);
334 ISCRUTE(j);
335 ISCRUTE(numdtToRead);
336 ISCRUTE(numitToRead);
337 return -1;
338 }
339
340 if (typeToRead != MED_FLOAT64)
341 if (MEDparameterValueRd(fid, nameToRead, numdtToRead, numitToRead,
342 (unsigned char *) &ivalueToRead) < 0) {
343 MESSAGE("ERROR : read parameter value ...");
344 SSCRUTE(nameToRead);
345 ISCRUTE(j);
346 ISCRUTE(numdtToRead);
347 ISCRUTE(numitToRead);
348 ISCRUTE(ivalueToRead);
349 return -1;
350 }
351
352 /* data verifications */
353 if ((i==0) && (j==0))
354 if ((numdtToRead != p1numdt1) || (numitToRead != p1numit1) || (dtToRead != p1dt1) ||
355 (fvalueToRead != p1v1)) {
356 MESSAGE("ERROR : false informations for computation step : attributes ...");
357 SSCRUTE(nameToRead);
358 ISCRUTE(j);
359 ISCRUTE(numdtToRead); ISCRUTE(p1numdt1);
360 ISCRUTE(numitToRead); ISCRUTE(p1numit1);
361 return -1;
362 }
363
364 if ((i==0) && (j==1))
365 if ((numdtToRead != p1numdt3) || (numitToRead != p1numit3) || (dtToRead != p1dt3) ||
366 (fvalueToRead != p1v3)) {
367 MESSAGE("ERROR : false informations for computation step : attributes ...");
368 SSCRUTE(nameToRead);
369 ISCRUTE(j);
370 ISCRUTE(numdtToRead); ISCRUTE(p1numdt3);
371 ISCRUTE(numitToRead); ISCRUTE(p1numit3);
372 return -1;
373 }
374
375 if ((i==0) && (j==2))
376 if ((numdtToRead != p1numdt2) || (numitToRead != p1numit2) || (dtToRead != p1dt2) ||
377 (fvalueToRead != p1v2)) {
378 MESSAGE("ERROR : false informations for computation step : attributes ...");
379 SSCRUTE(nameToRead);
380 ISCRUTE(j);
381 ISCRUTE(numdtToRead); ISCRUTE(p1numdt2);
382 ISCRUTE(numitToRead); ISCRUTE(p1numit2);
383 return -1;
384 }
385
386 if (i==1)
387 if ((numdtToRead != p2numdt1) || (numitToRead != p2numit1) || (dtToRead != p2dt1) ||
388 (ivalueToRead != p2v2)) {
389 MESSAGE("ERROR : false informations for computation step : attributes ...");
390 SSCRUTE(nameToRead);
391 ISCRUTE(j);
392 ISCRUTE(numdtToRead); ISCRUTE(p2numdt1);
393 ISCRUTE(numitToRead); ISCRUTE(p2numit1);
394 return -1;
395 }
396
397 if ((i == 2) && (j == 0))
398 if ((numdtToRead != p3numdt2) || (numitToRead != p3numit2) || (dtToRead != p3dt2) ||
399 (ivalueToRead != p3v2)) {
400 MESSAGE("ERROR : false informations for computation step : attributes ...");
401 SSCRUTE(nameToRead);
402 ISCRUTE(j);
403 ISCRUTE(numdtToRead); ISCRUTE(p3numdt2);
404 ISCRUTE(numitToRead); ISCRUTE(p3numit2);
405 return -1;
406 }
407
408 if ((i == 2) && (j == 1))
409 if ((numdtToRead != p3numdt1) || (numitToRead != p3numit1) || (dtToRead != p3dt1) ||
410 (ivalueToRead != p3v1)) {
411 MESSAGE("ERROR : false informations for computation step : attributes ...");
412 SSCRUTE(nameToRead);
413 ISCRUTE(j);
414 ISCRUTE(numdtToRead); ISCRUTE(p3numdt1);
415 ISCRUTE(numitToRead); ISCRUTE(p3numit1);
416 return -1;
417 }
418
419 }
420
421 }
422
423 /* close file */
424 if (MEDfileClose(fid) < 0) {
425 MESSAGE("ERROR : close file ...");
426 return -1;
427 }
428
429 return 0;
430 }
431
432 EOF
433
434 mpicc -I/usr/include/hdf5/openmpi -I/usr/include/hdf5/mpich -I/usr/include/hdf5/serial -I/usr/include -Wl,--as-needed -o usescase usescase.c -lmedC
435 echo "build: OK"
436 [ -x usescase ]
437 ./usescase
438 echo "run: OK"