2
Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
6
This file is part of Silo. For details, see silo.llnl.gov.
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions
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
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.
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.
35
This work was produced at Lawrence Livermore National Laboratory under
36
Contract No. DE-AC52-07NA27344 with the DOE.
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.
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.
55
* Programmer: Robb Matzke <matzke@llnl.gov>
56
* Tuesday, February 9, 1999
58
* Purpose: Tests reading and writing SAMI files using the HDF5 driver
74
#define TEST_NELMTS (1*720) /*multiple of 6! */
79
#define NELMTS(X) (sizeof(X)/sizeof(*(X)))
82
static int arch_g=DB_LOCAL; /*target architecture */
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];
93
/*-------------------------------------------------------------------------
94
* Function: test_write_all
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.
102
* Failure: number of errors
104
* Programmer: Robb Matzke
105
* Tuesday, February 9, 1999
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
*-------------------------------------------------------------------------
114
test_write_all(DBfile *dbfile)
116
int i, dims[5], nerrors=0;
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;
132
dims[0] = TEST_NELMTS;
133
if (DBWrite(dbfile, "1d_char", cdata_g, dims, 1, DB_CHAR)<0) {
134
puts(" DBWrite() failed");
141
dims[1] = TEST_NELMTS/dims[0];
142
if (DBWrite(dbfile, "2d_short", sdata_g, dims, 2, DB_SHORT)<0) {
143
puts(" DBWrite() failed");
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");
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");
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");
178
DBForceSingle(FALSE);
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");
196
/*-------------------------------------------------------------------------
197
* Function: test_read_all
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.
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.
210
* Failure: number of errors
212
* Programmer: Robb Matzke
213
* Tuesday, February 9, 1999
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
*-------------------------------------------------------------------------
222
test_read_all(DBfile *dbfile)
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];
232
puts("DBReadVar():");
233
if (DB_LOCAL!=arch_g) {
234
puts(" Skipped because target is not DB_LOCAL"
235
" -- use browser instead");
241
memset(cdata_in, 0xff, sizeof cdata_in);
242
if (DBReadVar(dbfile, "1d_char", cdata_in)<0) {
243
puts(" DBReadVar() failed");
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]);
257
memset(sdata_in, 0xff, sizeof sdata_in);
258
if (DBReadVar(dbfile, "2d_short", sdata_in)<0) {
259
puts(" DBReadVar() failed");
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]);
274
memset(idata_in, 0xff, sizeof idata_in);
275
if (DBReadVar(dbfile, "3d_int", idata_in)<0) {
276
puts(" DBReadVar() failed");
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]);
289
memset(ldata_in, 0xff, sizeof ldata_in);
290
if (DBReadVar(dbfile, "3d_long", ldata_in)<0) {
291
puts(" DBReadVar() failed");
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]);
305
memset(fdata_in, 0xff, sizeof fdata_in);
306
if (DBReadVar(dbfile, "4d_float", fdata_in)<0) {
307
puts(" DBReadVar() failed");
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]);
318
DBForceSingle(FALSE);
322
memset(ddata_in, 0xff, sizeof ddata_in);
323
if (DBReadVar(dbfile, "5d_double", ddata_in)<0) {
324
puts(" DBReadVar() failed");
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]);
338
/*-------------------------------------------------------------------------
339
* Function: test_get_all
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.
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.
352
* Failure: number of errors
354
* Programmer: Robb Matzke
355
* Tuesday, February 9, 1999
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
*-------------------------------------------------------------------------
364
test_get_all(DBfile *dbfile)
369
short *sdata_in=NULL;
372
float *fdata_in=NULL;
373
double *ddata_in=NULL;
376
if (DB_LOCAL!=arch_g) {
377
puts(" Skipped because target is not DB_LOCAL"
378
" -- use browser instead");
384
if (NULL==(cdata_in=DBGetVar(dbfile, "1d_char"))) {
385
puts(" DBGetVar() failed");
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]);
400
if (NULL==(sdata_in=DBGetVar(dbfile, "2d_short"))) {
401
puts(" DBGetVar() failed");
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]);
417
if (NULL==(idata_in=DBGetVar(dbfile, "3d_int"))) {
418
puts(" DBGetVar() failed");
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]);
432
if (NULL==(ldata_in=DBGetVar(dbfile, "3d_long"))) {
433
puts(" DBGetVar() failed");
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]);
448
if (NULL==(fdata_in=DBGetVar(dbfile, "4d_float"))) {
449
puts(" DBGetVar() failed");
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]);
461
DBForceSingle(FALSE);
465
if (NULL==(ddata_in=DBGetVar(dbfile, "5d_double"))) {
466
puts(" DBGetVar() failed");
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]);
481
/*-------------------------------------------------------------------------
482
* Function: test_inqvar
484
* Purpose: Tests variable inquiry functions.
488
* Failure: number of errors
490
* Programmer: Robb Matzke
491
* Thursday, February 11, 1999
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
*-------------------------------------------------------------------------
500
test_inqvar(DBfile *dbfile)
504
puts("DBGetVarLength()");
507
if (DBGetVarLength(dbfile, "1d_char")!=TEST_NELMTS) {
514
if (DBGetVarLength(dbfile, "2d_short")!=TEST_NELMTS) {
521
if (DBGetVarLength(dbfile, "3d_int")!=TEST_NELMTS) {
528
if (DBGetVarLength(dbfile, "3d_long")!=TEST_NELMTS) {
535
if (DBGetVarLength(dbfile, "4d_float")!=TEST_NELMTS) {
542
if (DBGetVarLength(dbfile, "5d_double")!=TEST_NELMTS) {
551
/*-------------------------------------------------------------------------
552
* Function: test_write_slice
554
* Purpose: Writes to just certain parts of an array. We only test this
555
* for the 3d_int case.
559
* Failure: number of errors
561
* Programmer: Robb Matzke
562
* Tuesday, February 9, 1999
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
*-------------------------------------------------------------------------
571
test_write_slice(DBfile *dbfile)
573
int dims[3], i, j, n, nerrors=0;
575
int offset[3], length[3], stride[3];
577
puts("DBWriteSlice()");
581
dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
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}.
589
for (i=n=0; i<12; i+=2) {
590
for (j=1; j<30; j+=3) {
592
idata_g[i*dims[1]*dims[2]+j*dims[2]] = idata_out[n++] = cntr_g++;
594
idata_g[i*dims[1]*dims[2]+j*dims[2]] = idata_out[n++] = 0;
602
length[0] = dims[0]-offset[0];
603
length[1] = dims[1]-offset[1];
608
stride[2] = 1; /*don't care*/
610
if (DBWriteSlice(dbfile, "3d_int", idata_out, DB_INT, offset, length,
611
stride, dims, 3)<0) {
620
/*-------------------------------------------------------------------------
621
* Function: test_read_slice
623
* Purpose: Reads just certain parts of an array. We only test this for
628
* Failure: number of errors
630
* Programmer: Robb Matzke
631
* Wednesday, February 10, 1999
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
*-------------------------------------------------------------------------
640
test_read_slice(DBfile *dbfile)
642
int dims[3], i, j, n, nerrors=0;
644
int offset[3], length[3], stride[3];
646
puts("DBReadSlice()");
651
dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
653
/* Read elements (I,J,0) for I in {5,7,9}, J in {9,18,27} */
658
length[0] = (9-5)+1; /*one method*/
659
length[1] = 9*3; /*another method*/
664
stride[2] = 1; /*don't care -- only one value being read */
666
if (DBReadVarSlice(dbfile, "3d_int", offset, length, stride, 3,
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",
688
/*-------------------------------------------------------------------------
689
* Function: test_type_conv
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.
697
* Failure: number of errors.
699
* Programmer: Robb Matzke
700
* Tuesday, February 9, 1999
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
*-------------------------------------------------------------------------
709
test_type_conv(DBfile *dbfile)
711
char cdata_out[TEST_NELMTS];
712
int i, dims[3], nerrors=0, idata_in[TEST_NELMTS];
714
puts("=== Type conversions ===");
716
/* Initialize output arrays */
717
for (i=0; i<TEST_NELMTS; i++, cntr_g++) {
718
idata_g[i] = cdata_out[i] = cntr_g%128;
721
/* Write char data to the 3d_int array */
726
dims[2] = TEST_NELMTS/(dims[0]*dims[1]);
727
if (DBWrite(dbfile, "3d_int", cdata_out, dims, 3, DB_CHAR)<0) {
732
/* Read integer data back out */
735
memset(idata_in, 0xff, sizeof idata_in);
736
if (DBReadVar(dbfile, "3d_int", idata_in)<0) {
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]);
752
/*-------------------------------------------------------------------------
753
* Function: test_write_bad
755
* Purpose: Try writing to an existing data but using an incompatible
760
* Failure: number of errors.
762
* Programmer: Robb Matzke
763
* Tuesday, February 9, 1999
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
*-------------------------------------------------------------------------
772
test_write_bad(DBfile *dbfile)
774
int i, data[TEST_NELMTS], dims[4], nerrors=0;
780
puts("=== Error conditions ===");
782
for (i=0; i<TEST_NELMTS; i++) data[i] = 911;
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");
791
/* Write to "3d_int" but with the wrong sizes */
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");
800
/* Write to "4d_float" but with integer data */
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");
810
DBForceSingle(FALSE);
820
/*-------------------------------------------------------------------------
821
* Function: test_dirs
823
* Purpose: Test directory operations
827
* Failure: number of errors
829
* Programmer: Robb Matzke
830
* Wednesday, February 10, 1999
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
*-------------------------------------------------------------------------
839
test_dirs(DBfile *dbfile)
843
static int in[1]={911}, value[1]={0};
844
static int dims[1]={1};
846
puts("=== Directories ===");
848
/* Make some directories */
849
if (DBMkDir(dbfile, "dir1")<0) {
850
puts("DBMkDir(dir1) failed");
853
if (DBMkDir(dbfile, "dir1/d1a")<0) {
854
puts("DBMkDir(dir1/d1a) failed");
857
if (DBMkDir(dbfile, "/dir1/d1b")<0) {
858
puts("DBMkDir(dir1/d1b) failed");
861
if (DBMkDir(dbfile, "/dir1/d1c/")<0) {
862
puts("DBMkDir(dir1/d1c) failed");
865
if (DBMkdir(dbfile, "//dir2//")<0) {
866
puts("DBMkDir(dir2) failed");
870
/* Set the CWD to /dir1/d1c and write a variable */
871
if (DBSetDir(dbfile, "//dir1//d1c//")<0) {
872
puts("DBSetDir(/dir1/d1c) failed");
875
if (DBWrite(dbfile, "d1c_A", value, dims, 1, DB_INT)<0) {
876
puts("DBWrite(d1c_A) failed");
879
if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/dir1/d1c")) {
880
puts("DBGetDir() failed");
883
if (DBReadVar(dbfile, "../d1c/..//..////dir1/d1c//d1c_A", in)<0 ||
885
puts("DBReadVar(d1c_A) failed");
889
/* Test table of contents */
890
if (NULL==DBGetToc(dbfile)) {
891
puts("DBGetToc() failed");
896
if (DBSetDir(dbfile, "/")<0) {
897
puts("DBSetDir(/) failed");
900
if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/")) {
901
puts("DBetDir() failed");
909
/*-------------------------------------------------------------------------
910
* Function: test_curve
912
* Purpose: Tests reading and writing DBcurve objects.
916
* Failure: number of errors
918
* Programmer: Robb Matzke
919
* Tuesday, March 23, 1999
923
*-------------------------------------------------------------------------
926
test_curve(DBfile *dbfile)
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};
932
puts("=== Curves ===");
934
DBMkDir(dbfile, "/curves");
935
DBSetDir(dbfile, "/curves");
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");
948
/*-------------------------------------------------------------------------
949
* Function: test_quadmesh
951
* Purpose: Tests reading and writing DBquadmesh objects.
957
* Programmer: Robb Matzke
958
* Tuesday, March 30, 1999
962
*-------------------------------------------------------------------------
965
test_quadmesh(DBfile *dbfile)
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,
977
static double varB[] = {35, 36, 37, 38, 39,
982
static double varC[] = {60, 61, 62, 63, 64,
987
static double *vars[] = {varA, varB, varC};
988
static char *varnames[] = {"varA", "varB", "varC"};
990
puts("=== Quadmesh ===");
992
DBMkDir(dbfile, "/quad");
993
DBSetDir(dbfile, "/quad");
995
if (DBPutQuadmesh(dbfile, "qm1", NULL, coords, dims, 2, DB_FLOAT,
996
DB_COLLINEAR, NULL)<0) {
997
puts("DBPutQuadmesh(qm1) failed");
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");
1012
/*-------------------------------------------------------------------------
1013
* Function: test_ucdmesh
1015
* Purpose: Test unstructured mesh functions.
1017
* Return: Success: 0
1019
* Failure: number of errors
1021
* Programmer: Robb Matzke
1022
* Thursday, April 1, 1999
1026
*-------------------------------------------------------------------------
1029
test_ucdmesh(DBfile *dbfile)
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;
1060
puts("=== Ucdmesh ===");
1062
DBMkDir(dbfile, "/ucd");
1063
DBSetDir(dbfile, "/ucd");
1066
if (DBPutUcdmesh(dbfile, "um1", ndims, coordnames, (float**)coords, nnodes,
1067
nzones, "zl1", "fl1", DB_DOUBLE,
1069
puts("DBPutUcdmesh(um1) failed");
1072
if (DBPutUcdsubmesh(dbfile, "um2", "um1", nzones, "zl1", "fl1", NULL)<0) {
1073
puts("DBPutUcdsubmesh(um2) failed");
1078
if (DBPutUcdvar(dbfile, "uv1", "um1", nvars, varnames, vars, nels, mixvars,
1079
mixlen, DB_FLOAT, DB_NODECENT, NULL)<0) {
1080
puts("DBPutUcdvar(uv1) failed");
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");
1093
if (DBPutZonelist(dbfile, "zl1", nzones, ndims, nodelist, lnodelist,
1094
origin, shapesize, shapecnt, nshapes)<0) {
1095
puts("DBPutZonelist(zl1) failed");
1105
/*-------------------------------------------------------------------------
1114
* Programmer: Robb Matzke
1115
* Tuesday, February 9, 1999
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.
1123
*-------------------------------------------------------------------------
1126
main(int argc, char *argv[])
1129
int i, nerrors=0, driver=DB_PDB;
1130
char *filename="sami.silo";
1131
int show_all_errors = FALSE;
1133
for (i=1; i<argc; i++) {
1134
if (!strcmp(argv[i], "DB_LOCAL")) {
1136
} else if (!strcmp(argv[i], "DB_SUN3")) {
1138
} else if (!strcmp(argv[i], "DB_SUN4")) {
1140
} else if (!strcmp(argv[i], "DB_SGI")) {
1142
} else if (!strcmp(argv[i], "DB_RS6000")) {
1144
} else if (!strcmp(argv[i], "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]);
1155
if (show_all_errors) DBShowErrors(DB_ALL_AND_DRVR, 0);
1157
/* turn of deprecate warnings */
1158
DBSetDeprecateWarnings(0);
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.
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");
1171
/* Write the first time, creating variables */
1172
nerrors += test_write_all(dbfile);
1173
nerrors += test_read_all(dbfile);
1175
nerrors += test_get_all(dbfile);
1176
nerrors += test_inqvar(dbfile);
1178
/* Write a second time, writing new values to existing variables */
1179
nerrors += test_write_all(dbfile);
1180
nerrors += test_read_all(dbfile);
1182
/* Rewrite with different memory data type and verify results */
1183
if (DB_PDB != (driver&0xF) && DB_PDBP != (driver&0xF))
1185
nerrors += test_type_conv(dbfile);
1189
* Do some illegal things to make sure they fail. Make sure we can still
1192
if (DB_PDB != (driver&0xF) && DB_PDBP != (driver&0xF))
1194
nerrors += test_write_bad(dbfile);
1195
nerrors += test_read_all(dbfile);
1198
if (DBClose(dbfile)<0) {
1199
puts("DBClose() failed");
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");
1209
nerrors += test_read_all(dbfile);
1210
if (DBClose(dbfile)<0) {
1211
puts("DBClose() failed");
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");
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);
1231
if (DBClose(dbfile)<0) {
1232
puts("DBClose() failed");
1237
printf("*** %d error%s detected ***\n", nerrors, 1==nerrors?"":"s");
1239
puts("All sami tests passed.");
1241
CleanupDriverStuff();