~ubuntu-branches/ubuntu/trusty/silo-llnl/trusty

« back to all changes in this revision

Viewing changes to tests/sami.c

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2011-01-02 00:03:01 UTC
  • Revision ID: james.westby@ubuntu.com-20110102000301-9s2hfsjrkguz6h4r
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
 
3
LLNL-CODE-425250.
 
4
All rights reserved.
 
5
 
 
6
This file is part of Silo. For details, see silo.llnl.gov.
 
7
 
 
8
Redistribution and use in source and binary forms, with or without
 
9
modification, are permitted provided that the following conditions
 
10
are met:
 
11
 
 
12
   * Redistributions of source code must retain the above copyright
 
13
     notice, this list of conditions and the disclaimer below.
 
14
   * Redistributions in binary form must reproduce the above copyright
 
15
     notice, this list of conditions and the disclaimer (as noted
 
16
     below) in the documentation and/or other materials provided with
 
17
     the distribution.
 
18
   * Neither the name of the LLNS/LLNL nor the names of its
 
19
     contributors may be used to endorse or promote products derived
 
20
     from this software without specific prior written permission.
 
21
 
 
22
THIS SOFTWARE  IS PROVIDED BY  THE COPYRIGHT HOLDERS  AND CONTRIBUTORS
 
23
"AS  IS" AND  ANY EXPRESS  OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT
 
24
LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
25
A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN  NO  EVENT SHALL  LAWRENCE
 
26
LIVERMORE  NATIONAL SECURITY, LLC,  THE U.S.  DEPARTMENT OF  ENERGY OR
 
27
CONTRIBUTORS BE LIABLE FOR  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
28
EXEMPLARY, OR  CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT  LIMITED TO,
 
29
PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS  OF USE,  DATA, OR
 
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
31
LIABILITY, WHETHER  IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING
 
32
NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT  OF THE USE  OF THIS
 
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
34
 
 
35
This work was produced at Lawrence Livermore National Laboratory under
 
36
Contract No.  DE-AC52-07NA27344 with the DOE.
 
37
 
 
38
Neither the  United States Government nor  Lawrence Livermore National
 
39
Security, LLC nor any of  their employees, makes any warranty, express
 
40
or  implied,  or  assumes  any  liability or  responsibility  for  the
 
41
accuracy, completeness,  or usefulness of  any information, apparatus,
 
42
product, or  process disclosed, or  represents that its use  would not
 
43
infringe privately-owned rights.
 
44
 
 
45
Any reference herein to  any specific commercial products, process, or
 
46
services by trade name,  trademark, manufacturer or otherwise does not
 
47
necessarily  constitute or imply  its endorsement,  recommendation, or
 
48
favoring  by  the  United  States  Government  or  Lawrence  Livermore
 
49
National Security,  LLC. The views  and opinions of  authors expressed
 
50
herein do not necessarily state  or reflect those of the United States
 
51
Government or Lawrence Livermore National Security, LLC, and shall not
 
52
be used for advertising or product endorsement purposes.
 
53
*/
 
54
/*
 
55
 * Programmer:  Robb Matzke <matzke@llnl.gov>
 
56
 *              Tuesday, February  9, 1999
 
57
 *
 
58
 * Purpose:     Tests reading and writing SAMI files using the HDF5 driver
 
59
 *              under silo.
 
60
 */
 
61
#include <silo.h>
 
62
#include <stdlib.h>
 
63
#include <std.c>
 
64
 
 
65
#include <config.h>
 
66
#ifdef HAVE_HDF5_H
 
67
#include <hdf5.h>
 
68
#endif
 
69
 
 
70
#ifdef WIN32
 
71
#include <string.h>
 
72
#endif
 
73
 
 
74
#define TEST_NELMTS     (1*720)         /*multiple of 6!                */
 
75
 
 
76
 
 
77
#define FALSE           0
 
78
#define TRUE            1
 
79
#define NELMTS(X)       (sizeof(X)/sizeof(*(X)))
 
80
 
 
81
static int      cntr_g;
 
82
static int      arch_g=DB_LOCAL;        /*target architecture           */
 
83
 
 
84
/* Memory versions of what appears in the file */
 
85
static char     cdata_g[TEST_NELMTS];
 
86
static short    sdata_g[TEST_NELMTS];
 
87
static int      idata_g[TEST_NELMTS];
 
88
static long     ldata_g[TEST_NELMTS];
 
89
static float    fdata_g[TEST_NELMTS];
 
90
static double   ddata_g[TEST_NELMTS];
 
91
 
 
92
 
 
93
/*-------------------------------------------------------------------------
 
94
 * Function:    test_write_all
 
95
 *
 
96
 * Purpose:     Write complete arrays from file to disk with DBWrite(). This
 
97
 *              only tests that DBWrite() returns success -- it doesn't
 
98
 *              attempt to read the data and compare it to what was written.
 
99
 *
 
100
 * Return:      Success:        0
 
101
 *
 
102
 *              Failure:        number of errors
 
103
 *
 
104
 * Programmer:  Robb Matzke
 
105
 *              Tuesday, February  9, 1999
 
106
 *
 
107
 * Modifications:
 
108
 *              Robb Matzke, 2000-01-12
 
109
 *              Changed hyphens to underscores in object names because silo
 
110
 *              now fails when underscores are present in the name.
 
111
 *-------------------------------------------------------------------------
 
112
 */
 
113
static int
 
114
test_write_all(DBfile *dbfile)
 
115
{
 
116
    int         i, dims[5], nerrors=0;
 
117
 
 
118
    puts("DBWrite():");
 
119
    
 
120
    /* Initialize output arrays */
 
121
    for (i=0; i<TEST_NELMTS; i++, cntr_g++) {
 
122
        cdata_g[i] = cntr_g%128; /*`char' has unknown sign so play it safe*/
 
123
        sdata_g[i] = cntr_g-TEST_NELMTS/2;
 
124
        idata_g[i] = cntr_g-TEST_NELMTS/2;
 
125
        ldata_g[i] = cntr_g-TEST_NELMTS/2;
 
126
        fdata_g[i] = (cntr_g-TEST_NELMTS/2)/10.0;
 
127
        ddata_g[i] = (cntr_g-TEST_NELMTS/2)/10.0;
 
128
    }
 
129
    
 
130
    /* 1d char */
 
131
    puts("    1d_char");
 
132
    dims[0] = TEST_NELMTS;
 
133
    if (DBWrite(dbfile, "1d_char", cdata_g, dims, 1, DB_CHAR)<0) {
 
134
        puts("        DBWrite() failed");
 
135
        nerrors++;
 
136
    }
 
137
 
 
138
    /* 2d short */
 
139
    puts("    2d_short");
 
140
    dims[0] = 2;
 
141
    dims[1] = TEST_NELMTS/dims[0];
 
142
    if (DBWrite(dbfile, "2d_short", sdata_g, dims, 2, DB_SHORT)<0) {
 
143
        puts("        DBWrite() failed");
 
144
        nerrors++;
 
145
    }
 
146
 
 
147
    /* 3d int */
 
148
    puts("    3d_int");
 
149
    dims[0] = 12;
 
150
    dims[1] = 30;
 
151
    dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
 
152
    if (DBWrite(dbfile, "3d_int", idata_g, dims, 3, DB_INT)<0) {
 
153
        puts("        DBWrite() failed");
 
154
        nerrors++;
 
155
    }
 
156
 
 
157
    /* 3d long */
 
158
    puts("    3d_long");
 
159
    dims[0] = 5;
 
160
    dims[1] = 6;
 
161
    dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
 
162
    if (DBWrite(dbfile, "3d_long", ldata_g, dims, 3, DB_LONG)<0) {
 
163
        puts("        DBWrite() failed");
 
164
        nerrors++;
 
165
    }
 
166
 
 
167
    /* 4d float */
 
168
    DBForceSingle(TRUE);
 
169
    puts("    4d_float");
 
170
    dims[0] = 6;
 
171
    dims[1] = 5;
 
172
    dims[2] = 4;
 
173
    dims[3] = TEST_NELMTS/(dims[0]*dims[1]*dims[2]);
 
174
    if (DBWrite(dbfile, "4d_float", fdata_g, dims, 4, DB_FLOAT)<0) {
 
175
        puts("        DBWrite() failed");
 
176
        nerrors++;
 
177
    }
 
178
    DBForceSingle(FALSE);
 
179
 
 
180
    /* 5d double */
 
181
    puts("    5d_double");
 
182
    dims[0] = 3;
 
183
    dims[1] = 2;
 
184
    dims[2] = 6;
 
185
    dims[3] = 5;
 
186
    dims[4] = TEST_NELMTS/(dims[0]*dims[1]*dims[2]*dims[3]);
 
187
    if (DBWrite(dbfile, "5d_double", ddata_g, dims, 5, DB_DOUBLE)<0) {
 
188
        puts("        DBWrite() failed");
 
189
        nerrors++;
 
190
    }
 
191
 
 
192
    return nerrors;
 
193
}
 
194
 
 
195
 
 
196
/*-------------------------------------------------------------------------
 
197
 * Function:    test_read_all
 
198
 *
 
199
 * Purpose:     Tests DBReadVar() by reading each of the variables that were
 
200
 *              written by test_write_all() and comparing the results to what
 
201
 *              is stored in memory.
 
202
 *
 
203
 *              This step is skipped if the architecture is not DB_LOCAL
 
204
 *              because the data might be read back as some other type than
 
205
 *              what was written. Unfortunately silo doesn't give the caller
 
206
 *              any control over how data is read.
 
207
 *
 
208
 * Return:      Success:        0
 
209
 *
 
210
 *              Failure:        number of errors
 
211
 *
 
212
 * Programmer:  Robb Matzke
 
213
 *              Tuesday, February  9, 1999
 
214
 *
 
215
 * Modifications:
 
216
 *              Robb Matzke, 2000-01-12
 
217
 *              Changed hyphens to underscores in object names because silo
 
218
 *              now fails when underscores are present in the name.
 
219
 *-------------------------------------------------------------------------
 
220
 */
 
221
static int
 
222
test_read_all(DBfile *dbfile)
 
223
{
 
224
    int         i, nerrors=0;
 
225
    char        cdata_in[TEST_NELMTS];
 
226
    short       sdata_in[TEST_NELMTS];
 
227
    int         idata_in[TEST_NELMTS];
 
228
    long        ldata_in[TEST_NELMTS];
 
229
    float       fdata_in[TEST_NELMTS];
 
230
    double      ddata_in[TEST_NELMTS];
 
231
 
 
232
    puts("DBReadVar():");
 
233
    if (DB_LOCAL!=arch_g) {
 
234
        puts("    Skipped because target is not DB_LOCAL"
 
235
             " -- use browser instead");
 
236
        return 0;
 
237
    }
 
238
    
 
239
    /* 1d char */
 
240
    puts("    1d_char");
 
241
    memset(cdata_in, 0xff, sizeof cdata_in);
 
242
    if (DBReadVar(dbfile, "1d_char", cdata_in)<0) {
 
243
        puts("        DBReadVar() failed");
 
244
        nerrors++;
 
245
    } else {
 
246
        for (i=0; i<TEST_NELMTS; i++) {
 
247
            if (cdata_g[i]!=cdata_in[i]) {
 
248
                printf("        failed at i=%d: out=%d, in=%d\n",
 
249
                       i, cdata_g[i], cdata_in[i]);
 
250
                nerrors++;
 
251
            }
 
252
        }
 
253
    }
 
254
 
 
255
    /* 2d short */
 
256
    puts("    2d_short");
 
257
    memset(sdata_in, 0xff, sizeof sdata_in);
 
258
    if (DBReadVar(dbfile, "2d_short", sdata_in)<0) {
 
259
        puts("        DBReadVar() failed");
 
260
        nerrors++;
 
261
    } else {
 
262
        for (i=0; i<TEST_NELMTS; i++) {
 
263
            if (sdata_g[i]!=sdata_in[i]) {
 
264
                printf("        failed at i=%d: out=%d, in=%d\n",
 
265
                       i, sdata_g[i], sdata_in[i]);
 
266
                nerrors++;
 
267
            }
 
268
        }
 
269
    }
 
270
 
 
271
 
 
272
    /* 3d int */
 
273
    puts("    3d_int");
 
274
    memset(idata_in, 0xff, sizeof idata_in);
 
275
    if (DBReadVar(dbfile, "3d_int", idata_in)<0) {
 
276
        puts("        DBReadVar() failed");
 
277
        nerrors++;
 
278
    } else {
 
279
        for (i=0; i<TEST_NELMTS; i++) {
 
280
            if (idata_g[i]!=idata_in[i]) {
 
281
                printf("        failed at i=%d: out=%d, in=%d\n",
 
282
                       i, idata_g[i], idata_in[i]);
 
283
            }
 
284
        }
 
285
    }
 
286
 
 
287
    /* 3d long */
 
288
    puts("    3d_long");
 
289
    memset(ldata_in, 0xff, sizeof ldata_in);
 
290
    if (DBReadVar(dbfile, "3d_long", ldata_in)<0) {
 
291
        puts("        DBReadVar() failed");
 
292
        nerrors++;
 
293
    } else {
 
294
        for (i=0; i<TEST_NELMTS; i++) {
 
295
            if (ldata_g[i]!=ldata_in[i]) {
 
296
                printf("        failed at i=%d: out=%ld, in=%ld\n",
 
297
                       i, ldata_g[i], ldata_in[i]);
 
298
            }
 
299
        }
 
300
    }
 
301
 
 
302
    /* 4d float */
 
303
    DBForceSingle(TRUE);
 
304
    puts("    4d_float");
 
305
    memset(fdata_in, 0xff, sizeof fdata_in);
 
306
    if (DBReadVar(dbfile, "4d_float", fdata_in)<0) {
 
307
        puts("        DBReadVar() failed");
 
308
        nerrors++;
 
309
    } else {
 
310
        printf("checking read of first 4d_float\n");
 
311
        for (i=0; i<TEST_NELMTS; i++) {
 
312
            if (fdata_g[i]!=fdata_in[i]) {
 
313
                printf("        failed at i=%d: out=%g, in=%g\n",
 
314
                       i, fdata_g[i], fdata_in[i]);
 
315
            }
 
316
        }
 
317
    }
 
318
    DBForceSingle(FALSE);
 
319
 
 
320
    /* 5d double */
 
321
    puts("    5d_double");
 
322
    memset(ddata_in, 0xff, sizeof ddata_in);
 
323
    if (DBReadVar(dbfile, "5d_double", ddata_in)<0) {
 
324
        puts("        DBReadVar() failed");
 
325
        nerrors++;
 
326
    } else {
 
327
        for (i=0; i<TEST_NELMTS; i++) {
 
328
            if (ddata_g[i]!=ddata_in[i]) {
 
329
                printf("        failed at i=%d: out=%g, in=%g\n",
 
330
                       i, ddata_g[i], ddata_in[i]);
 
331
            }
 
332
        }
 
333
    }
 
334
    return nerrors;
 
335
}
 
336
 
 
337
 
 
338
/*-------------------------------------------------------------------------
 
339
 * Function:    test_get_all
 
340
 *
 
341
 * Purpose:     Tests DBGetVar() by reading each of the variables that were
 
342
 *              written by test_write_all() and comparing the results to what
 
343
 *              is stored in memory.
 
344
 *
 
345
 *              This step is skipped if the architecture is not DB_LOCAL
 
346
 *              because the data might be read back as some other type than
 
347
 *              what was written. Unfortunately silo doesn't give the caller
 
348
 *              any control over how data is read.
 
349
 *
 
350
 * Return:      Success:        0
 
351
 *
 
352
 *              Failure:        number of errors
 
353
 *
 
354
 * Programmer:  Robb Matzke
 
355
 *              Tuesday, February  9, 1999
 
356
 *
 
357
 * Modifications:
 
358
 *              Robb Matzke, 2000-01-12
 
359
 *              Changed hyphens to underscores in object names because silo
 
360
 *              now fails when underscores are present in the name.
 
361
 *-------------------------------------------------------------------------
 
362
 */
 
363
static int
 
364
test_get_all(DBfile *dbfile)
 
365
{
 
366
    int         i, nerrors=0;
 
367
 
 
368
    char        *cdata_in=NULL;
 
369
    short       *sdata_in=NULL;
 
370
    int         *idata_in=NULL;
 
371
    long        *ldata_in=NULL;
 
372
    float       *fdata_in=NULL;
 
373
    double      *ddata_in=NULL;
 
374
 
 
375
    puts("DBGetVar():");
 
376
    if (DB_LOCAL!=arch_g) {
 
377
        puts("    Skipped because target is not DB_LOCAL"
 
378
             " -- use browser instead");
 
379
        return 0;
 
380
    }
 
381
    
 
382
    /* 1d char */
 
383
    puts("    1d_char");
 
384
    if (NULL==(cdata_in=DBGetVar(dbfile, "1d_char"))) {
 
385
        puts("        DBGetVar() failed");
 
386
        nerrors++;
 
387
    } else {
 
388
        for (i=0; i<TEST_NELMTS; i++) {
 
389
            if (cdata_g[i]!=cdata_in[i]) {
 
390
                printf("        failed at i=%d: out=%d, in=%d\n",
 
391
                       i, cdata_g[i], cdata_in[i]);
 
392
                nerrors++;
 
393
            }
 
394
        }
 
395
        free(cdata_in);
 
396
    }
 
397
 
 
398
    /* 2d short */
 
399
    puts("    2d_short");
 
400
    if (NULL==(sdata_in=DBGetVar(dbfile, "2d_short"))) {
 
401
        puts("        DBGetVar() failed");
 
402
        nerrors++;
 
403
    } else {
 
404
        for (i=0; i<TEST_NELMTS; i++) {
 
405
            if (sdata_g[i]!=sdata_in[i]) {
 
406
                printf("        failed at i=%d: out=%d, in=%d\n",
 
407
                       i, sdata_g[i], sdata_in[i]);
 
408
                nerrors++;
 
409
            }
 
410
        }
 
411
        free(sdata_in);
 
412
    }
 
413
 
 
414
 
 
415
    /* 3d int */
 
416
    puts("    3d_int");
 
417
    if (NULL==(idata_in=DBGetVar(dbfile, "3d_int"))) {
 
418
        puts("        DBGetVar() failed");
 
419
        nerrors++;
 
420
    } else {
 
421
        for (i=0; i<TEST_NELMTS; i++) {
 
422
            if (idata_g[i]!=idata_in[i]) {
 
423
                printf("        failed at i=%d: out=%d, in=%d\n",
 
424
                       i, idata_g[i], idata_in[i]);
 
425
            }
 
426
        }
 
427
        free(idata_in);
 
428
    }
 
429
 
 
430
    /* 3d long */
 
431
    puts("    3d_long");
 
432
    if (NULL==(ldata_in=DBGetVar(dbfile, "3d_long"))) {
 
433
        puts("        DBGetVar() failed");
 
434
        nerrors++;
 
435
    } else {
 
436
        for (i=0; i<TEST_NELMTS; i++) {
 
437
            if (ldata_g[i]!=ldata_in[i]) {
 
438
                printf("        failed at i=%d: out=%ld, in=%ld\n",
 
439
                       i, ldata_g[i], ldata_in[i]);
 
440
            }
 
441
        }
 
442
        free(ldata_in);
 
443
    }
 
444
 
 
445
    /* 4d float */
 
446
    DBForceSingle(TRUE);
 
447
    puts("    4d_float");
 
448
    if (NULL==(fdata_in=DBGetVar(dbfile, "4d_float"))) {
 
449
        puts("        DBGetVar() failed");
 
450
        nerrors++;
 
451
    } else {
 
452
        printf("testing DBGetVar of 4d_float\n");
 
453
        for (i=0; i<TEST_NELMTS; i++) {
 
454
            if (fdata_g[i]!=fdata_in[i]) {
 
455
                printf("        failed at i=%d: out=%g, in=%g\n",
 
456
                       i, fdata_g[i], fdata_in[i]);
 
457
            }
 
458
        }
 
459
        free(fdata_in);
 
460
    }
 
461
    DBForceSingle(FALSE);
 
462
 
 
463
    /* 5d double */
 
464
    puts("    5d_double");
 
465
    if (NULL==(ddata_in=DBGetVar(dbfile, "5d_double"))) {
 
466
        puts("        DBGetVar() failed");
 
467
        nerrors++;
 
468
    } else {
 
469
        for (i=0; i<TEST_NELMTS; i++) {
 
470
            if (ddata_g[i]!=ddata_in[i]) {
 
471
                printf("        failed at i=%d: out=%g, in=%g\n",
 
472
                       i, ddata_g[i], ddata_in[i]);
 
473
            }
 
474
        }
 
475
        free(ddata_in);
 
476
    }
 
477
    return nerrors;
 
478
}
 
479
 
 
480
 
 
481
/*-------------------------------------------------------------------------
 
482
 * Function:    test_inqvar
 
483
 *
 
484
 * Purpose:     Tests variable inquiry functions.
 
485
 *
 
486
 * Return:      Success:        0
 
487
 *
 
488
 *              Failure:        number of errors
 
489
 *
 
490
 * Programmer:  Robb Matzke
 
491
 *              Thursday, February 11, 1999
 
492
 *
 
493
 * Modifications:
 
494
 *              Robb Matzke, 2000-01-12
 
495
 *              Changed hyphens to underscores in object names because silo
 
496
 *              now fails when underscores are present in the name.
 
497
 *-------------------------------------------------------------------------
 
498
 */
 
499
static int
 
500
test_inqvar(DBfile *dbfile)
 
501
{
 
502
    int         nerrors=0;
 
503
    
 
504
    puts("DBGetVarLength()");
 
505
    
 
506
    puts("    1d_char");
 
507
    if (DBGetVarLength(dbfile, "1d_char")!=TEST_NELMTS) {
 
508
        puts("        failed");
 
509
        nerrors++;
 
510
    }
 
511
    
 
512
    
 
513
    puts("    2d_short");
 
514
    if (DBGetVarLength(dbfile, "2d_short")!=TEST_NELMTS) {
 
515
        puts("        failed");
 
516
        nerrors++;
 
517
    }
 
518
    
 
519
    
 
520
    puts("    3d_int");
 
521
    if (DBGetVarLength(dbfile, "3d_int")!=TEST_NELMTS) {
 
522
        puts("        failed");
 
523
        nerrors++;
 
524
    }
 
525
    
 
526
    
 
527
    puts("    3d_long");
 
528
    if (DBGetVarLength(dbfile, "3d_long")!=TEST_NELMTS) {
 
529
        puts("        failed");
 
530
        nerrors++;
 
531
    }
 
532
    
 
533
    
 
534
    puts("    4d_float");
 
535
    if (DBGetVarLength(dbfile, "4d_float")!=TEST_NELMTS) {
 
536
        puts("        failed");
 
537
        nerrors++;
 
538
    }
 
539
    
 
540
    
 
541
    puts("    5d_double");
 
542
    if (DBGetVarLength(dbfile, "5d_double")!=TEST_NELMTS) {
 
543
        puts("        failed");
 
544
        nerrors++;
 
545
    }
 
546
 
 
547
    return nerrors;
 
548
}
 
549
 
 
550
 
 
551
/*-------------------------------------------------------------------------
 
552
 * Function:    test_write_slice
 
553
 *
 
554
 * Purpose:     Writes to just certain parts of an array. We only test this
 
555
 *              for the 3d_int case.
 
556
 *
 
557
 * Return:      Success:        0
 
558
 *
 
559
 *              Failure:        number of errors
 
560
 *
 
561
 * Programmer:  Robb Matzke
 
562
 *              Tuesday, February  9, 1999
 
563
 *
 
564
 * Modifications:
 
565
 *              Robb Matzke, 2000-01-12
 
566
 *              Changed hyphens to underscores in object names because silo
 
567
 *              now fails when underscores are present in the name.
 
568
 *-------------------------------------------------------------------------
 
569
 */
 
570
static int
 
571
test_write_slice(DBfile *dbfile)
 
572
{
 
573
    int         dims[3], i, j, n, nerrors=0;
 
574
    int         idata_out[6*10];
 
575
    int         offset[3], length[3], stride[3];
 
576
 
 
577
    puts("DBWriteSlice()");
 
578
 
 
579
    dims[0] = 12;
 
580
    dims[1] = 30;
 
581
    dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
 
582
 
 
583
    /*
 
584
     * Write to elements (I,J,0) for all I=0 (mod 2) and J=1 (mod 3). That is,
 
585
     * all combinations of I and J such that I is from the set {0,2,4,6,8,10}
 
586
     * and J from {1,4,7,10,13,16,19,22,25,28}.
 
587
     */
 
588
    puts("   3d_int");
 
589
    for (i=n=0; i<12; i+=2) {
 
590
        for (j=1; j<30; j+=3) {
 
591
#if 0
 
592
            idata_g[i*dims[1]*dims[2]+j*dims[2]] = idata_out[n++] = cntr_g++;
 
593
#else
 
594
            idata_g[i*dims[1]*dims[2]+j*dims[2]] = idata_out[n++] = 0;
 
595
#endif
 
596
        }
 
597
    }
 
598
    offset[0] = 0;
 
599
    offset[1] = 1;
 
600
    offset[2] = 0;
 
601
    
 
602
    length[0] = dims[0]-offset[0];
 
603
    length[1] = dims[1]-offset[1];
 
604
    length[2] = 1;
 
605
    
 
606
    stride[0] = 2;
 
607
    stride[1] = 3;
 
608
    stride[2] = 1; /*don't care*/
 
609
    
 
610
    if (DBWriteSlice(dbfile, "3d_int", idata_out, DB_INT, offset, length,
 
611
                     stride, dims, 3)<0) {
 
612
        puts("        failed");
 
613
        nerrors++;
 
614
    }
 
615
 
 
616
    return nerrors;
 
617
}
 
618
 
 
619
 
 
620
/*-------------------------------------------------------------------------
 
621
 * Function:    test_read_slice
 
622
 *
 
623
 * Purpose:     Reads just certain parts of an array. We only test this for
 
624
 *              the 3d_int case.
 
625
 *
 
626
 * Return:      Success:        0
 
627
 *
 
628
 *              Failure:        number of errors
 
629
 *
 
630
 * Programmer:  Robb Matzke
 
631
 *              Wednesday, February 10, 1999
 
632
 *
 
633
 * Modifications:
 
634
 *              Robb Matzke, 2000-01-12
 
635
 *              Changed hyphens to underscores in object names because silo
 
636
 *              now fails when underscores are present in the name.
 
637
 *-------------------------------------------------------------------------
 
638
 */
 
639
static int
 
640
test_read_slice(DBfile *dbfile)
 
641
{
 
642
    int         dims[3], i, j, n, nerrors=0;
 
643
    int         idata_in[12*30];
 
644
    int         offset[3], length[3], stride[3];
 
645
 
 
646
    puts("DBReadSlice()");
 
647
    puts("    3d_int");
 
648
 
 
649
    dims[0] = 12;
 
650
    dims[1] = 30;
 
651
    dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
 
652
 
 
653
    /* Read elements (I,J,0) for I in {5,7,9}, J in {9,18,27} */
 
654
    offset[0] = 5;
 
655
    offset[1] = 9;
 
656
    offset[2] = 0;
 
657
 
 
658
    length[0] = (9-5)+1; /*one method*/
 
659
    length[1] = 9*3;    /*another method*/
 
660
    length[2] = 1;
 
661
 
 
662
    stride[0] = 2;
 
663
    stride[1] = 9;
 
664
    stride[2] = 1; /*don't care -- only one value being read */
 
665
 
 
666
    if (DBReadVarSlice(dbfile, "3d_int", offset, length, stride, 3,
 
667
                       idata_in)<0) {
 
668
        puts("        failed");
 
669
        nerrors++;
 
670
    }
 
671
 
 
672
    /* Check */
 
673
    for (i=n=0; i<3; i++) {
 
674
        for (j=0; j<3; j++, n++) {
 
675
            int v = idata_g[(offset[0]+stride[0]*i)*dims[1]*dims[2] +
 
676
                            (offset[1]+stride[1]*j)*dims[2]];
 
677
            if (v!=idata_in[n]) {
 
678
                printf("        failed at i=%d: out=%d, in=%d\n",
 
679
                       n, v, idata_in[n]);
 
680
                nerrors++;
 
681
            }
 
682
        }
 
683
    }
 
684
    return nerrors;
 
685
}
 
686
 
 
687
 
 
688
/*-------------------------------------------------------------------------
 
689
 * Function:    test_type_conv
 
690
 *
 
691
 * Purpose:     If we call DBWrite() for an existing variable but the memory
 
692
 *              data type is different than what was previously registered
 
693
 *              then a type conversion should occur.
 
694
 *
 
695
 * Return:      Success:        0
 
696
 *
 
697
 *              Failure:        number of errors.
 
698
 *
 
699
 * Programmer:  Robb Matzke
 
700
 *              Tuesday, February  9, 1999
 
701
 *
 
702
 * Modifications:
 
703
 *              Robb Matzke, 2000-01-12
 
704
 *              Changed hyphens to underscores in object names because silo
 
705
 *              now fails when underscores are present in the name.
 
706
 *-------------------------------------------------------------------------
 
707
 */
 
708
static int
 
709
test_type_conv(DBfile *dbfile)
 
710
{
 
711
    char        cdata_out[TEST_NELMTS];
 
712
    int         i, dims[3], nerrors=0, idata_in[TEST_NELMTS];
 
713
 
 
714
    puts("=== Type conversions ===");
 
715
    
 
716
    /* Initialize output arrays */
 
717
    for (i=0; i<TEST_NELMTS; i++, cntr_g++) {
 
718
        idata_g[i] = cdata_out[i] = cntr_g%128;
 
719
    }
 
720
 
 
721
    /* Write char data to the 3d_int array */
 
722
    puts("DBWrite()");
 
723
    puts("    3d_int");
 
724
    dims[0] = 12;
 
725
    dims[1] = 30;
 
726
    dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
 
727
    if (DBWrite(dbfile, "3d_int", cdata_out, dims, 3, DB_CHAR)<0) {
 
728
        puts("        failed");
 
729
        nerrors++;
 
730
    }
 
731
 
 
732
    /* Read integer data back out */
 
733
    puts("DBRead()");
 
734
    puts("    3d_int");
 
735
    memset(idata_in, 0xff, sizeof idata_in);
 
736
    if (DBReadVar(dbfile, "3d_int", idata_in)<0) {
 
737
        puts("        failed");
 
738
        nerrors++;
 
739
    } else {
 
740
        for (i=0; i<TEST_NELMTS; i++) {
 
741
            if (idata_g[i]!=idata_in[i]) {
 
742
                printf("        failed at i=%d: out=%d, in=%d\n",
 
743
                       i, idata_g[i], idata_in[i]);
 
744
            }
 
745
        }
 
746
    }
 
747
 
 
748
    return nerrors;
 
749
}
 
750
 
 
751
 
 
752
/*-------------------------------------------------------------------------
 
753
 * Function:    test_write_bad
 
754
 *
 
755
 * Purpose:     Try writing to an existing data but using an incompatible
 
756
 *              size or data type.
 
757
 *
 
758
 * Return:      Success:        0
 
759
 *
 
760
 *              Failure:        number of errors.
 
761
 *
 
762
 * Programmer:  Robb Matzke
 
763
 *              Tuesday, February  9, 1999
 
764
 *
 
765
 * Modifications:
 
766
 *              Robb Matzke, 2000-01-12
 
767
 *              Changed hyphens to underscores in object names because silo
 
768
 *              now fails when underscores are present in the name.
 
769
 *-------------------------------------------------------------------------
 
770
 */
 
771
static int
 
772
test_write_bad(DBfile *dbfile)
 
773
{
 
774
    int         i, data[TEST_NELMTS], dims[4], nerrors=0;
 
775
 
 
776
#ifdef HAVE_HDF5_H
 
777
    H5E_BEGIN_TRY {
 
778
#endif
 
779
 
 
780
        puts("=== Error conditions ===");
 
781
 
 
782
        for (i=0; i<TEST_NELMTS; i++) data[i] = 911;
 
783
 
 
784
        /* Write to "3d_int" but supply only 1 dimension */
 
785
        dims[0] = TEST_NELMTS;
 
786
        if (DBWrite(dbfile, "3d_int", data, dims, 1, DB_INT)>=0) {
 
787
            puts("DBWrite() to 3d_int with 1d data should have failed");
 
788
            nerrors++;
 
789
        }
 
790
 
 
791
        /* Write to "3d_int" but with the wrong sizes */
 
792
        dims[0] = 3;
 
793
        dims[2] = 4;
 
794
        dims[1] = TEST_NELMTS/(dims[0]*dims[2]);
 
795
        if (DBWrite(dbfile, "3d_int", data, dims, 3, DB_INT)>=0) {
 
796
            puts("DBWrite() to 3d_int with wrong dims should have faild");
 
797
            nerrors++;
 
798
        }
 
799
 
 
800
        /* Write to "4d_float" but with integer data */
 
801
        DBForceSingle(TRUE);
 
802
        dims[0] = 6;
 
803
        dims[1] = 5;
 
804
        dims[2] = 4;
 
805
        dims[3] = TEST_NELMTS/(dims[0]*dims[1]*dims[2]);
 
806
        if (DBWrite(dbfile, "4d_float", data, dims, 4, DB_INT)>=0) {
 
807
            puts("DBWrite() to 4d_float with integer data should have failed");
 
808
            nerrors++;
 
809
        }
 
810
        DBForceSingle(FALSE);
 
811
 
 
812
#ifdef HAVE_HDF5_H
 
813
    } H5E_END_TRY;
 
814
#endif
 
815
 
 
816
    return nerrors;
 
817
}
 
818
 
 
819
 
 
820
/*-------------------------------------------------------------------------
 
821
 * Function:    test_dirs
 
822
 *
 
823
 * Purpose:     Test directory operations
 
824
 *
 
825
 * Return:      Success:        0
 
826
 *
 
827
 *              Failure:        number of errors
 
828
 *
 
829
 * Programmer:  Robb Matzke
 
830
 *              Wednesday, February 10, 1999
 
831
 *
 
832
 * Modifications:
 
833
 *              Robb Matzke, 2000-01-12
 
834
 *              Changed hyphens to underscores in object names because silo
 
835
 *              now fails when underscores are present in the name.
 
836
 *-------------------------------------------------------------------------
 
837
 */
 
838
static int
 
839
test_dirs(DBfile *dbfile)
 
840
{
 
841
    int         nerrors=0;
 
842
    char        curdir[1024];
 
843
    static int  in[1]={911}, value[1]={0};
 
844
    static int  dims[1]={1};
 
845
 
 
846
    puts("=== Directories ===");
 
847
 
 
848
    /* Make some directories */
 
849
    if (DBMkDir(dbfile, "dir1")<0) {
 
850
        puts("DBMkDir(dir1) failed");
 
851
        nerrors++;
 
852
    }
 
853
    if (DBMkDir(dbfile, "dir1/d1a")<0) {
 
854
        puts("DBMkDir(dir1/d1a) failed");
 
855
        nerrors++;
 
856
    }
 
857
    if (DBMkDir(dbfile, "/dir1/d1b")<0) {
 
858
        puts("DBMkDir(dir1/d1b) failed");
 
859
        nerrors++;
 
860
    }
 
861
    if (DBMkDir(dbfile, "/dir1/d1c/")<0) {
 
862
        puts("DBMkDir(dir1/d1c) failed");
 
863
        nerrors++;
 
864
    }
 
865
    if (DBMkdir(dbfile, "//dir2//")<0) {
 
866
        puts("DBMkDir(dir2) failed");
 
867
        nerrors++;
 
868
    }
 
869
 
 
870
    /* Set the CWD to /dir1/d1c and write a variable */
 
871
    if (DBSetDir(dbfile, "//dir1//d1c//")<0) {
 
872
        puts("DBSetDir(/dir1/d1c) failed");
 
873
        nerrors++;
 
874
    }
 
875
    if (DBWrite(dbfile, "d1c_A", value, dims, 1, DB_INT)<0) {
 
876
        puts("DBWrite(d1c_A) failed");
 
877
        nerrors++;
 
878
    }
 
879
    if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/dir1/d1c")) {
 
880
        puts("DBGetDir() failed");
 
881
        nerrors++;
 
882
    }
 
883
    if (DBReadVar(dbfile, "../d1c/..//..////dir1/d1c//d1c_A", in)<0 ||
 
884
        in[0]!=value[0]) {
 
885
        puts("DBReadVar(d1c_A) failed");
 
886
        nerrors++;
 
887
    }
 
888
 
 
889
    /* Test table of contents */
 
890
    if (NULL==DBGetToc(dbfile)) {
 
891
        puts("DBGetToc() failed");
 
892
        nerrors++;
 
893
    }
 
894
    
 
895
    /* Set CWD to top */
 
896
    if (DBSetDir(dbfile, "/")<0) {
 
897
        puts("DBSetDir(/) failed");
 
898
        nerrors++;
 
899
    }
 
900
    if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/")) {
 
901
        puts("DBetDir() failed");
 
902
        nerrors++;
 
903
    }
 
904
 
 
905
    return nerrors;
 
906
}
 
907
 
 
908
 
 
909
/*-------------------------------------------------------------------------
 
910
 * Function:    test_curve
 
911
 *
 
912
 * Purpose:     Tests reading and writing DBcurve objects.
 
913
 *
 
914
 * Return:      Success:        0
 
915
 *
 
916
 *              Failure:        number of errors
 
917
 *
 
918
 * Programmer:  Robb Matzke
 
919
 *              Tuesday, March 23, 1999
 
920
 *
 
921
 * Modifications:
 
922
 *
 
923
 *-------------------------------------------------------------------------
 
924
 */
 
925
static int
 
926
test_curve(DBfile *dbfile)
 
927
{
 
928
    int                 nerrors = 0;
 
929
    static double       xvals_d[] = { 1.1,   2.2,   3.3,   4.4,   5.5 };
 
930
    static double       yvals_d[] = {10.01, 20.02, 30.03, 40.04, 50.05};
 
931
    
 
932
    puts("=== Curves ===");
 
933
 
 
934
    DBMkDir(dbfile, "/curves");
 
935
    DBSetDir(dbfile, "/curves");
 
936
 
 
937
    /* Write an initial curve along with its X and Y arrays */
 
938
    if (DBPutCurve(dbfile, "curve1", xvals_d, yvals_d, DB_DOUBLE,
 
939
                   NELMTS(xvals_d), NULL)<0) {
 
940
        puts("DBPutCurve(curve1) failed");
 
941
        nerrors++;
 
942
    }
 
943
 
 
944
    return nerrors;
 
945
}
 
946
 
 
947
 
 
948
/*-------------------------------------------------------------------------
 
949
 * Function:    test_quadmesh
 
950
 *
 
951
 * Purpose:     Tests reading and writing DBquadmesh objects.
 
952
 *
 
953
 * Return:      Success:        
 
954
 *
 
955
 *              Failure:        
 
956
 *
 
957
 * Programmer:  Robb Matzke
 
958
 *              Tuesday, March 30, 1999
 
959
 *
 
960
 * Modifications:
 
961
 *
 
962
 *-------------------------------------------------------------------------
 
963
 */
 
964
static int
 
965
test_quadmesh(DBfile *dbfile)
 
966
{
 
967
    int                 nerrors=0;
 
968
    static int          dims[] = {5, 5};
 
969
    static float        coords0[] = {0.11, 0.12, 0.13, 0.14, 0.15};
 
970
    static float        coords1[] = {0.21, 0.22, 0.23, 0.24, 0.25};
 
971
    static float        *coords[] = {coords0, coords1};
 
972
    static double       varA[] = {10, 11, 12, 13, 14,
 
973
                                  15, 16, 17, 18, 19,
 
974
                                  20, 21, 22, 23, 24,
 
975
                                  25, 26, 27, 28, 29,
 
976
                                  30, 31, 32, 33, 34};
 
977
    static double       varB[] = {35, 36, 37, 38, 39,
 
978
                                  40, 41, 42, 43, 44,
 
979
                                  45, 46, 47, 48, 49,
 
980
                                  50, 51, 52, 53, 54,
 
981
                                  55, 56, 57, 58, 59};
 
982
    static double       varC[] = {60, 61, 62, 63, 64,
 
983
                                  65, 66, 67, 68, 69,
 
984
                                  70, 71, 72, 73, 74,
 
985
                                  75, 76, 77, 78, 79,
 
986
                                  80, 81, 82, 83, 84};
 
987
    static double       *vars[] = {varA, varB, varC};
 
988
    static char         *varnames[] = {"varA", "varB", "varC"};
 
989
        
 
990
    puts("=== Quadmesh ===");
 
991
 
 
992
    DBMkDir(dbfile, "/quad");
 
993
    DBSetDir(dbfile, "/quad");
 
994
 
 
995
    if (DBPutQuadmesh(dbfile, "qm1", NULL, coords, dims, 2, DB_FLOAT,
 
996
                      DB_COLLINEAR, NULL)<0) {
 
997
        puts("DBPutQuadmesh(qm1) failed");
 
998
        nerrors++;
 
999
    }
 
1000
 
 
1001
    if (DBPutQuadvar(dbfile, "qv1", "qm1", 3, varnames, (float**)vars, dims, 2,
 
1002
                     NULL, 0, DB_DOUBLE, DB_NODECENT, NULL)<0) {
 
1003
        puts("DBPutQuadmesh(qv1) failed");
 
1004
        nerrors++;
 
1005
    }
 
1006
    
 
1007
 
 
1008
    return nerrors;
 
1009
}
 
1010
 
 
1011
 
 
1012
/*-------------------------------------------------------------------------
 
1013
 * Function:    test_ucdmesh
 
1014
 *
 
1015
 * Purpose:     Test unstructured mesh functions.
 
1016
 *
 
1017
 * Return:      Success:        0
 
1018
 *
 
1019
 *              Failure:        number of errors
 
1020
 *
 
1021
 * Programmer:  Robb Matzke
 
1022
 *              Thursday, April  1, 1999
 
1023
 *
 
1024
 * Modifications:
 
1025
 *
 
1026
 *-------------------------------------------------------------------------
 
1027
 */
 
1028
static int
 
1029
test_ucdmesh(DBfile *dbfile)
 
1030
{
 
1031
    int                 nerrors = 0;
 
1032
    static double       coordA[] = {101, 102, 103, 104, 105};
 
1033
    static double       coordB[] = {201, 202, 203, 204, 205};
 
1034
    static double       coordC[] = {301, 302, 303, 304, 305};
 
1035
    static double       *coords[] = {coordA, coordB, coordC};
 
1036
    static char         *coordnames[] = {"coordA", "coordB", "coordC"};
 
1037
    static int          nnodes = NELMTS(coordA);
 
1038
    static int          ndims = NELMTS(coords);
 
1039
    static int          nzones = 3;
 
1040
    static float        varA[] = {1,  2,  3,  4,  5, 6, 7, 8};
 
1041
    static float        *vars[] = {varA};
 
1042
    static char         *varnames[] = {"varA"};
 
1043
    static int          nels = NELMTS(varA);
 
1044
    static int          nvars = NELMTS(vars);
 
1045
    static float        mixA[] = {0.1, 0.2, 0.3};
 
1046
    static float        *mixvars[] = {mixA};
 
1047
    static int          mixlen = NELMTS(mixA);
 
1048
    static int          nodelist[] = {500, 501, 502, 503, 504, 505, 506, 507};
 
1049
    static int          lnodelist = NELMTS(nodelist);
 
1050
    static int          shapecnt[] = {1,  1,  2,  2,  3,  3,  4,  4,  5,  5};
 
1051
    static int          shapesize[]= {5,  5,  4,  4,  3,  3,  2,  2,  1,  1};
 
1052
    static int          nshapes = NELMTS(shapecnt);
 
1053
    static int          typelist[] = {99, 98, 97, 96, 95, 94};
 
1054
    static int          ntypes = NELMTS(typelist);
 
1055
    static int          types[]    = {193, 192, 191, 190, 189, 187, 186};
 
1056
    static int          zoneno[]   = {185, 184, 183, 182, 181, 180, 179};
 
1057
    static int          nfaces = NELMTS(types);
 
1058
    static int          origin = 1;
 
1059
 
 
1060
    puts("=== Ucdmesh ===");
 
1061
 
 
1062
    DBMkDir(dbfile, "/ucd");
 
1063
    DBSetDir(dbfile, "/ucd");
 
1064
 
 
1065
    /* Mesh */
 
1066
    if (DBPutUcdmesh(dbfile, "um1", ndims, coordnames, (float**)coords, nnodes,
 
1067
                     nzones, "zl1", "fl1", DB_DOUBLE,
 
1068
                     NULL)<0) {
 
1069
        puts("DBPutUcdmesh(um1) failed");
 
1070
        nerrors++;
 
1071
    }
 
1072
    if (DBPutUcdsubmesh(dbfile, "um2", "um1", nzones, "zl1", "fl1", NULL)<0) {
 
1073
        puts("DBPutUcdsubmesh(um2) failed");
 
1074
        nerrors++;
 
1075
    }
 
1076
    
 
1077
    /* Variable */
 
1078
    if (DBPutUcdvar(dbfile, "uv1", "um1", nvars, varnames, vars, nels, mixvars,
 
1079
                    mixlen, DB_FLOAT, DB_NODECENT, NULL)<0) {
 
1080
        puts("DBPutUcdvar(uv1) failed");
 
1081
        nerrors++;
 
1082
    }
 
1083
 
 
1084
    /* Facelist */
 
1085
    if (DBPutFacelist(dbfile, "fl1", nfaces, ndims, nodelist, lnodelist,
 
1086
                      origin, zoneno, shapesize, shapecnt, nshapes, types,
 
1087
                      typelist, ntypes)<0) {
 
1088
        puts("DBPutFacelist(fl1) failed");
 
1089
        nerrors++;
 
1090
    }
 
1091
 
 
1092
    /* Zonelist */
 
1093
    if (DBPutZonelist(dbfile, "zl1", nzones, ndims, nodelist, lnodelist,
 
1094
                      origin, shapesize, shapecnt, nshapes)<0) {
 
1095
        puts("DBPutZonelist(zl1) failed");
 
1096
        nerrors++;
 
1097
    }
 
1098
 
 
1099
    
 
1100
    return nerrors;
 
1101
}
 
1102
 
 
1103
 
 
1104
 
 
1105
/*-------------------------------------------------------------------------
 
1106
 * Function:    main
 
1107
 *
 
1108
 * Purpose:     
 
1109
 *
 
1110
 * Return:      Success:        
 
1111
 *
 
1112
 *              Failure:        
 
1113
 *
 
1114
 * Programmer:  Robb Matzke
 
1115
 *              Tuesday, February  9, 1999
 
1116
 *
 
1117
 * Modifications:
 
1118
 *    Eric Brugger, Fri Apr 14 09:30:47 PDT 2000
 
1119
 *    I modified the routine to not perform some tests that are not valid
 
1120
 *    when using the PDB driver.  There was already code to not do those
 
1121
 *    tests when using the pdb driver but it wasn't quite correct.
 
1122
 *
 
1123
 *-------------------------------------------------------------------------
 
1124
 */
 
1125
int
 
1126
main(int argc, char *argv[])
 
1127
{
 
1128
    DBfile              *dbfile;
 
1129
    int                 i, nerrors=0,  driver=DB_PDB;
 
1130
    char                *filename="sami.silo";
 
1131
    int                 show_all_errors = FALSE;
 
1132
    
 
1133
    for (i=1; i<argc; i++) {
 
1134
        if (!strcmp(argv[i], "DB_LOCAL")) {
 
1135
            arch_g = DB_LOCAL;
 
1136
        } else if (!strcmp(argv[i], "DB_SUN3")) {
 
1137
            arch_g = DB_SUN3;
 
1138
        } else if (!strcmp(argv[i], "DB_SUN4")) {
 
1139
            arch_g = DB_SUN4;
 
1140
        } else if (!strcmp(argv[i], "DB_SGI")) {
 
1141
            arch_g = DB_SGI;
 
1142
        } else if (!strcmp(argv[i], "DB_RS6000")) {
 
1143
            arch_g = DB_RS6000;
 
1144
        } else if (!strcmp(argv[i], "DB_CRAY")) {
 
1145
            arch_g = DB_CRAY;
 
1146
        } else if (!strncmp(argv[i], "DB_",3)) {
 
1147
            driver = StringToDriver(argv[i]);
 
1148
        } else if (!strcmp(argv[i], "show-all-errors")) {
 
1149
            show_all_errors = 1;
 
1150
        } else if (argv[i][0] != '\0') {
 
1151
            fprintf(stderr, "%s: ignored argument `%s'\n", argv[0], argv[i]);
 
1152
        }
 
1153
    }
 
1154
    
 
1155
    if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);
 
1156
 
 
1157
    /* turn of deprecate warnings */
 
1158
    DBSetDeprecateWarnings(0);
 
1159
 
 
1160
    /*
 
1161
     * Create a new file (clobbering any old file), write some variables to
 
1162
     * the file, then read them and compare with what was written.
 
1163
     */
 
1164
    puts("=== Creating file ===");
 
1165
    if (NULL==(dbfile=DBCreate(filename, DB_CLOBBER, arch_g,
 
1166
                               "testing SAMI HDF5 silo driver", driver))) {
 
1167
        puts("DBCreate() failed");
 
1168
        nerrors++;
 
1169
    }
 
1170
 
 
1171
    /* Write the first time, creating variables */
 
1172
    nerrors += test_write_all(dbfile);
 
1173
    nerrors += test_read_all(dbfile);
 
1174
    
 
1175
    nerrors += test_get_all(dbfile);
 
1176
    nerrors += test_inqvar(dbfile);
 
1177
 
 
1178
    /* Write a second time, writing new values to existing variables */
 
1179
    nerrors += test_write_all(dbfile);
 
1180
    nerrors += test_read_all(dbfile);
 
1181
 
 
1182
    /* Rewrite with different memory data type and verify results */
 
1183
    if (DB_PDB != (driver&0xF) && DB_PDBP != (driver&0xF))
 
1184
    {
 
1185
        nerrors += test_type_conv(dbfile);
 
1186
    }
 
1187
 
 
1188
    /*
 
1189
     * Do some illegal things to make sure they fail. Make sure we can still
 
1190
     * read data.
 
1191
     */
 
1192
    if (DB_PDB != (driver&0xF) && DB_PDBP != (driver&0xF))
 
1193
    {
 
1194
        nerrors += test_write_bad(dbfile);
 
1195
        nerrors += test_read_all(dbfile);
 
1196
    }
 
1197
    
 
1198
    if (DBClose(dbfile)<0) {
 
1199
        puts("DBClose() failed");
 
1200
        nerrors++;
 
1201
    }
 
1202
 
 
1203
    /* Open the file for read only and read all variables */
 
1204
    puts("=== Opening for read-only ===");
 
1205
    if (NULL==(dbfile=DBOpen(filename, DB_UNKNOWN, DB_READ))) {
 
1206
        puts("DBOpen() failed for read-only access");
 
1207
        nerrors++;
 
1208
    }
 
1209
    nerrors += test_read_all(dbfile);
 
1210
    if (DBClose(dbfile)<0) {
 
1211
        puts("DBClose() failed");
 
1212
        nerrors++;
 
1213
    }
 
1214
    
 
1215
    /* Open the file for read-write and test slicing */
 
1216
    puts("=== Opening for read-write ===");
 
1217
    if (NULL==(dbfile=DBOpen(filename, driver, DB_APPEND))) {
 
1218
        puts("DBOpen() failed for read-write access");
 
1219
        nerrors++;
 
1220
    }
 
1221
    
 
1222
    nerrors += test_read_all(dbfile);
 
1223
    nerrors += test_write_slice(dbfile);
 
1224
    nerrors += test_read_all(dbfile);
 
1225
    nerrors += test_read_slice(dbfile);
 
1226
    nerrors += test_dirs(dbfile);
 
1227
    nerrors += test_curve(dbfile);
 
1228
    nerrors += test_quadmesh(dbfile);
 
1229
    nerrors += test_ucdmesh(dbfile);
 
1230
 
 
1231
    if (DBClose(dbfile)<0) {
 
1232
        puts("DBClose() failed");
 
1233
        nerrors++;
 
1234
    }
 
1235
 
 
1236
    if (nerrors) {
 
1237
        printf("*** %d error%s detected ***\n", nerrors, 1==nerrors?"":"s");
 
1238
    } else {
 
1239
        puts("All sami tests passed.");
 
1240
    }
 
1241
    CleanupDriverStuff();
 
1242
    return nerrors?1:0;
 
1243
}