1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/***********************************************************
*
* Test program: tarray
*
* Test the Array Datatype functionality
*
*************************************************************/
#include "testhdf5.h"
#include "H5srcdir.h"
#include "hdf5.h"
#define FILENAME "tarray1.h5"
#define TESTFILE "tarrold.h5"
/* 1-D array datatype */
#define ARRAY1_RANK 1
#define ARRAY1_DIM1 4
/* 3-D array datatype */
#define ARRAY2_RANK 3
#define ARRAY2_DIM1 3
#define ARRAY2_DIM2 4
#define ARRAY2_DIM3 5
/* 2-D array datatype */
#define ARRAY3_RANK 2
#define ARRAY3_DIM1 6
#define ARRAY3_DIM2 3
/* 1-D dataset with fixed dimensions */
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
/****************************************************************
**
** test_array_atomic_1d(): Test basic array datatype code.
** Tests 1-D array of atomic datatypes
**
****************************************************************/
static void
test_array_atomic_1d(void)
{
int wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
int rdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information read in */
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Datatype ID */
hsize_t sdims1[] = {SPACE1_DIM1};
hsize_t tdims1[] = {ARRAY1_DIM1};
int ndims; /* Array rank for reading */
hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */
int i,j; /* counting variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing 1-D Array of Atomic Datatypes Functionality\n"));
/* Allocate and initialize array data to write */
for(i = 0; i < SPACE1_DIM1; i++)
for(j = 0; j < ARRAY1_DIM1; j++)
wdata[i][j] = i * 10 + j;
/* Create file */
fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fcreate");
/* Create dataspace for datasets */
sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
CHECK(sid1, FAIL, "H5Screate_simple");
/* Create a datatype to refer to */
tid1 = H5Tarray_create2(H5T_NATIVE_INT, ARRAY1_RANK, tdims1);
CHECK(tid1, FAIL, "H5Tarray_create2");
/* Create a dataset */
dataset = H5Dcreate2(fid1, "Dataset1", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dcreate2");
/* Write dataset to disk */
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
CHECK(ret, FAIL, "H5Dwrite");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close disk dataspace */
ret = H5Sclose(sid1);
CHECK(ret, FAIL, "H5Sclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Re-open file */
fid1 = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* Open the dataset */
dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
/* Get the datatype */
tid1 = H5Dget_type (dataset);
CHECK(tid1, FAIL, "H5Dget_type");
/* Check the array rank */
ndims = H5Tget_array_ndims(tid1);
VERIFY(ndims, ARRAY1_RANK, "H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(tid1, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i = 0; i < ndims; i++)
if(rdims1[i] != tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n", (int)i, (int)rdims1[i], (int)i, (int)tdims1[i]);
continue;
} /* end if */
/* Read dataset from disk */
ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
CHECK(ret, FAIL, "H5Dread");
/* Compare data read in */
for(i = 0; i < SPACE1_DIM1; i++)
for(j = 0; j < ARRAY1_DIM1; j++)
if(wdata[i][j] != rdata[i][j]) {
TestErrPrintf("Array data information doesn't match!, wdata[%d][%d]=%d, rdata[%d][%d]=%d\n", (int)i, (int)j, (int)wdata[i][j], (int)i, (int)j, (int)rdata[i][j]);
continue;
} /* end if */
/* Close Datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
} /* end test_array_atomic_1d() */
/****************************************************************
**
** test_array_funcs(): Test some type functions that are and
** aren't supposed to work with array type.
**
****************************************************************/
static void
test_array_funcs(void)
{
hid_t type; /* Datatype ID */
hsize_t tdims1[] = {ARRAY1_DIM1};
int size;
H5T_pad_t inpad;
H5T_norm_t norm;
H5T_cset_t cset;
H5T_str_t strpad;
herr_t ret; /* Generic return value */
/* Create a datatype to refer to */
type = H5Tarray_create2(H5T_IEEE_F32BE, ARRAY1_RANK, tdims1);
CHECK(type, FAIL, "H5Tarray_create2");
size=H5Tget_precision(type);
CHECK(size, FAIL, "H5Tget_precision");
size=H5Tget_size(type);
CHECK(size, FAIL, "H5Tget_size");
size=H5Tget_ebias(type);
CHECK(size, FAIL, "H5Tget_ebias");
ret=H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE);
CHECK(ret, FAIL, "H5Tset_pad");
inpad=H5Tget_inpad(type);
CHECK(inpad, FAIL, "H5Tget_inpad");
norm=H5Tget_norm(type);
CHECK(norm, FAIL, "H5Tget_norm");
ret=H5Tset_offset(type, (size_t)16);
CHECK(ret, FAIL, "H5Tset_offset");
H5E_BEGIN_TRY {
cset=H5Tget_cset(type);
} H5E_END_TRY;
VERIFY(cset, FAIL, "H5Tget_cset");
H5E_BEGIN_TRY {
strpad=H5Tget_strpad(type);
} H5E_END_TRY;
VERIFY(strpad, FAIL, "H5Tget_strpad");
/* Close datatype */
ret = H5Tclose(type);
CHECK(ret, FAIL, "H5Tclose");
} /* end test_array_funcs */
/****************************************************************
**
** test_array_atomic_3d(): Test basic array datatype code.
** Tests 3-D array of atomic datatypes
**
****************************************************************/
static void
test_array_atomic_3d(void)
{
int wdata[SPACE1_DIM1][ARRAY2_DIM1][ARRAY2_DIM2][ARRAY2_DIM3]; /* Information to write */
int rdata[SPACE1_DIM1][ARRAY2_DIM1][ARRAY2_DIM2][ARRAY2_DIM3]; /* Information read in */
hid_t fid; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid; /* Dataspace ID */
hid_t tid; /* Datatype ID */
hsize_t sdims1[] = {SPACE1_DIM1};
hsize_t tdims2[] = {ARRAY2_DIM1,ARRAY2_DIM2,ARRAY2_DIM3};
int ndims; /* Array rank for reading */
hsize_t rdims2[H5S_MAX_RANK]; /* Array dimensions for reading */
int i,j,k,l; /* counting variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing 3-D Array of Atomic Datatypes Functionality\n"));
/* Allocate and initialize array data to write */
for(i = 0; i < SPACE1_DIM1; i++)
for(j = 0; j < ARRAY2_DIM1; j++)
for(k = 0; k < ARRAY2_DIM2; k++)
for(l = 0; l < ARRAY2_DIM3; l++)
wdata[i][j][k][l] = i * 1000 + j * 100 + k * 10 + l;
/* Create file */
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fcreate");
/* Create dataspace for datasets */
sid = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
CHECK(sid, FAIL, "H5Screate_simple");
/* Create a datatype to refer to */
tid = H5Tarray_create2(H5T_NATIVE_INT, ARRAY2_RANK, tdims2);
CHECK(tid, FAIL, "H5Tarray_create2");
/* Create a dataset */
dataset = H5Dcreate2(fid, "Dataset1", tid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dcreate2");
/* Write dataset to disk */
ret = H5Dwrite(dataset, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
CHECK(ret, FAIL, "H5Dwrite");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close datatype */
ret = H5Tclose(tid);
CHECK(ret, FAIL, "H5Tclose");
/* Close disk dataspace */
ret = H5Sclose(sid);
CHECK(ret, FAIL, "H5Sclose");
/* Close file */
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
/* Re-open file */
fid = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");
/* Open the dataset */
dataset = H5Dopen2(fid, "Dataset1", H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
/* Get the datatype */
tid = H5Dget_type (dataset);
CHECK(tid, FAIL, "H5Dget_type");
/* Check the array rank */
ndims = H5Tget_array_ndims(tid);
VERIFY(ndims, ARRAY2_RANK, "H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(tid, rdims2);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i = 0; i < ndims; i++)
if(rdims2[i] != tdims2[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims2[%d]=%d, tdims2[%d]=%d\n", (int)i, (int)rdims2[i], (int)i, (int)tdims2[i]);
continue;
} /* end if */
/* Read dataset from disk */
ret = H5Dread(dataset, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
CHECK(ret, FAIL, "H5Dread");
/* Compare data read in */
for(i = 0; i < SPACE1_DIM1; i++)
for(j = 0; j < ARRAY2_DIM1; j++)
for(k = 0; k < ARRAY2_DIM2; k++)
for(l = 0; l < ARRAY2_DIM3; l++)
if(wdata[i][j][k][l] != rdata[i][j][k][l]) {
TestErrPrintf("Array data information doesn't match!, wdata[%d][%d][%d][%d]=%d, rdata[%d][%d][%d][%d]=%d\n", (int)i, (int)j, (int)k, (int)l, (int)wdata[i][j][k][l], (int)i, (int)j, (int)k, (int)l, (int)rdata[i][j][k][l]);
continue;
} /* end if */
/* Close Datatype */
ret = H5Tclose(tid);
CHECK(ret, FAIL, "H5Tclose");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close file */
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
} /* end test_array_atomic_3d() */
/****************************************************************
**
** test_array_array_atomic(): Test basic array datatype code.
** Tests 1-D array 2-D arrays of atomic datatypes
**
****************************************************************/
static void
test_array_array_atomic(void)
{
int wdata[SPACE1_DIM1][ARRAY1_DIM1][ARRAY3_DIM1][ARRAY3_DIM2]; /* Information to write */
int rdata[SPACE1_DIM1][ARRAY1_DIM1][ARRAY3_DIM1][ARRAY3_DIM2]; /* Information read in */
hid_t fid; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid; /* Dataspace ID */
hid_t tid1; /* 1-D array Datatype ID */
hid_t tid2; /* 2-D array Datatype ID */
hsize_t sdims1[] = {SPACE1_DIM1};
hsize_t tdims1[] = {ARRAY1_DIM1};
hsize_t tdims2[] = {ARRAY3_DIM1,ARRAY3_DIM2};
int ndims1; /* Array rank for reading */
int ndims2; /* Array rank for reading */
hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */
hsize_t rdims2[H5S_MAX_RANK]; /* Array dimensions for reading */
int i,j,k,l; /* counting variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing 1-D Array 2-D Arrays of Atomic Datatypes Functionality\n"));
/* Allocate and initialize array data to write */
for(i = 0; i < SPACE1_DIM1; i++)
for(j = 0; j < ARRAY1_DIM1; j++)
for(k = 0; k < ARRAY3_DIM1; k++)
for(l = 0; l < ARRAY3_DIM2; l++)
wdata[i][j][k][l] = i * 1000 + j * 100 + k * 10 + l;
/* Create file */
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fcreate");
/* Create dataspace for datasets */
sid = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
CHECK(sid, FAIL, "H5Screate_simple");
/* Create a 2-D datatype to refer to */
tid2 = H5Tarray_create2(H5T_NATIVE_INT, ARRAY3_RANK, tdims2);
CHECK(tid2, FAIL, "H5Tarray_create2");
/* Create a 1-D datatype to refer to */
tid1 = H5Tarray_create2(tid2, ARRAY1_RANK, tdims1);
CHECK(tid1, FAIL, "H5Tarray_create2");
/* Create a dataset */
dataset = H5Dcreate2(fid, "Dataset1", tid1, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dcreate2");
/* Write dataset to disk */
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
CHECK(ret, FAIL, "H5Dwrite");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close datatypes */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Close disk dataspace */
ret = H5Sclose(sid);
CHECK(ret, FAIL, "H5Sclose");
/* Close file */
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
/* Re-open file */
fid = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");
/* Open the dataset */
dataset = H5Dopen2(fid, "Dataset1", H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
/* Get the 1-D datatype */
tid1 = H5Dget_type(dataset);
CHECK(tid1, FAIL, "H5Dget_type");
/* Check the 1-D array rank */
ndims1 = H5Tget_array_ndims(tid1);
VERIFY(ndims1, ARRAY1_RANK, "H5Tget_array_ndims");
/* Get the 1-D array dimensions */
ret = H5Tget_array_dims2(tid1, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i = 0; i < ndims1; i++)
if(rdims1[i] != tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n", (int)i, (int)rdims1[i], (int)i, (int)tdims1[i]);
continue;
} /* end if */
/* Get the 2-D datatype */
tid2 = H5Tget_super(tid1);
CHECK(tid2, FAIL, "H5Tget_super");
/* Check the 2-D array rank */
ndims2 = H5Tget_array_ndims(tid2);
VERIFY(ndims2, ARRAY3_RANK, "H5Tget_array_ndims");
/* Get the 2-D array dimensions */
ret = H5Tget_array_dims2(tid2, rdims2);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i = 0; i < ndims2; i++)
if(rdims2[i] != tdims2[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims2[%d]=%d, tdims2[%d]=%d\n", (int)i, (int)rdims2[i], (int)i, (int)tdims2[i]);
continue;
} /* end if */
/* Read dataset from disk */
ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
CHECK(ret, FAIL, "H5Dread");
/* Compare data read in */
for(i = 0; i < SPACE1_DIM1; i++)
for(j = 0; j < ARRAY1_DIM1; j++)
for(k = 0; k < ARRAY3_DIM1; k++)
for(l = 0; l < ARRAY3_DIM2; l++)
if(wdata[i][j][k][l] != rdata[i][j][k][l]) {
TestErrPrintf("Array data information doesn't match!, wdata[%d][%d][%d][%d]=%d, rdata[%d][%d][%d][%d]=%d\n", (int)i, (int)j, (int)k, (int)l, (int)wdata[i][j][k][l], (int)i, (int)j, (int)k, (int)l, (int)rdata[i][j][k][l]);
continue;
} /* end if */
/* Close Datatypes */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close file */
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
} /* end test_array_array_atomic() */
/****************************************************************
**
** test_array_compound_atomic(): Test basic array datatype code.
** Tests 1-D array of compound datatypes (with no array fields)
**
****************************************************************/
static void
test_array_compound_atomic(void)
{
typedef struct { /* Typedef for compound datatype */
int i;
float f;
} s1_t;
s1_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
s1_t rdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information read in */
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Array Datatype ID */
hid_t tid2; /* Compound Datatype ID */
hsize_t sdims1[] = {SPACE1_DIM1};
hsize_t tdims1[] = {ARRAY1_DIM1};
int ndims; /* Array rank for reading */
hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */
int nmemb; /* Number of compound members */
char *mname; /* Name of compound field */
size_t off; /* Offset of compound field */
hid_t mtid; /* Datatype ID for field */
int i,j; /* counting variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing 1-D Array of Compound Atomic Datatypes Functionality\n"));
/* Initialize array data to write */
for(i = 0; i < SPACE1_DIM1; i++)
for(j = 0; j < ARRAY1_DIM1; j++) {
wdata[i][j].i = i * 10 + j;
wdata[i][j].f = (float)(i * 2.5 + j);
} /* end for */
/* Create file */
fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fcreate");
/* Create dataspace for datasets */
sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
CHECK(sid1, FAIL, "H5Screate_simple");
/* Create a compound datatype to refer to */
tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
CHECK(tid2, FAIL, "H5Tcreate");
/* Insert integer field */
ret = H5Tinsert(tid2, "i", HOFFSET(s1_t, i), H5T_NATIVE_INT);
CHECK(ret, FAIL, "H5Tinsert");
/* Insert float field */
ret = H5Tinsert(tid2, "f", HOFFSET(s1_t, f), H5T_NATIVE_FLOAT);
CHECK(ret, FAIL, "H5Tinsert");
/* Create an array datatype to refer to */
tid1 = H5Tarray_create2(tid2, ARRAY1_RANK, tdims1);
CHECK(tid1, FAIL, "H5Tarray_create2");
/* Close compound datatype */
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Create a dataset */
dataset = H5Dcreate2(fid1, "Dataset1", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dcreate2");
/* Write dataset to disk */
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
CHECK(ret, FAIL, "H5Dwrite");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close disk dataspace */
ret = H5Sclose(sid1);
CHECK(ret, FAIL, "H5Sclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Re-open file */
fid1 = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* Open the dataset */
dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
/* Get the datatype */
tid1 = H5Dget_type(dataset);
CHECK(tid1, FAIL, "H5Dget_type");
/* Check the array rank */
ndims = H5Tget_array_ndims(tid1);
VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(tid1, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i = 0; i < ndims; i++)
if(rdims1[i] != tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n", (int)i, (int)rdims1[i], (int)i, (int)tdims1[i]);
continue;
} /* end if */
/* Get the compound datatype */
tid2 = H5Tget_super (tid1);
CHECK(tid2, FAIL, "H5Tget_super");
/* Check the number of members */
nmemb = H5Tget_nmembers(tid2);
VERIFY(nmemb,2,"H5Tget_nmembers");
/* Check the 1st field's name */
mname = H5Tget_member_name(tid2, 0);
CHECK(mname, NULL, "H5Tget_member_name");
if(HDstrcmp(mname, "i") != 0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n", mname);
free(mname);
/* Check the 1st field's offset */
off = H5Tget_member_offset(tid2, 0);
VERIFY(off, HOFFSET(s1_t, i), "H5Tget_member_offset");
/* Check the 1st field's datatype */
mtid = H5Tget_member_type(tid2, 0);
CHECK(mtid, FAIL, "H5Tget_member_type");
if((ret = H5Tequal(mtid,H5T_NATIVE_INT)) <= 0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n", (int)ret);
ret = H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Check the 2nd field's name */
mname = H5Tget_member_name(tid2, 1);
CHECK(mname, NULL, "H5Tget_member_name");
if(HDstrcmp(mname, "f") != 0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n", mname);
free(mname);
/* Check the 2nd field's offset */
off = H5Tget_member_offset(tid2, 1);
VERIFY(off, HOFFSET(s1_t, f), "H5Tget_member_offset");
/* Check the 2nd field's datatype */
mtid = H5Tget_member_type(tid2, 1);
CHECK(mtid, FAIL, "H5Tget_member_type");
if((ret = H5Tequal(mtid, H5T_NATIVE_FLOAT)) <= 0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n", (int)ret);
ret = H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Close Compound Datatype */
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Read dataset from disk */
ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
CHECK(ret, FAIL, "H5Dread");
/* Compare data read in */
for(i = 0; i < SPACE1_DIM1; i++)
for(j = 0; j < ARRAY1_DIM1; j++) {
if(wdata[i][j].i != rdata[i][j].i) {
TestErrPrintf("Array data information doesn't match!, wdata[%d][%d].i=%d, rdata[%d][%d].i=%d\n", (int)i, (int)j, (int)wdata[i][j].i, (int)i, (int)j, (int)rdata[i][j].i);
continue;
} /* end if */
if(!FLT_ABS_EQUAL(wdata[i][j].f, rdata[i][j].f)) {
TestErrPrintf("Array data information doesn't match!, wdata[%d][%d].f=%f, rdata[%d][%d].f=%f\n", (int)i, (int)j, wdata[i][j].f, (int)i, (int)j, rdata[i][j].f);
continue;
} /* end if */
} /* end for */
/* Close Datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
} /* end test_array_compound_atomic() */
/****************************************************************
**
** test_array_compound_array(): Test basic array datatype code.
** Tests 1-D array of compound datatypes (with array fields)
**
****************************************************************/
static void
test_array_compound_array(void)
{
typedef struct { /* Typedef for compound datatype */
int i;
float f[ARRAY1_DIM1];
} s1_t;
s1_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
s1_t rdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information read in */
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Array Datatype ID */
hid_t tid2; /* Compound Datatype ID */
hid_t tid3; /* Nested Array Datatype ID */
hsize_t sdims1[] = {SPACE1_DIM1};
hsize_t tdims1[] = {ARRAY1_DIM1};
int ndims; /* Array rank for reading */
hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */
int nmemb; /* Number of compound members */
char *mname; /* Name of compound field */
size_t off; /* Offset of compound field */
hid_t mtid; /* Datatype ID for field */
H5T_class_t mclass; /* Datatype class for field */
int i,j,k; /* counting variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing 1-D Array of Compound Array Datatypes Functionality\n"));
/* Initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
for(j=0; j<ARRAY1_DIM1; j++) {
wdata[i][j].i=i*10+j;
for(k=0; k<ARRAY1_DIM1; k++)
wdata[i][j].f[k]=(float)(i*10+j*2.5+k);
} /* end for */
/* Create file */
fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fcreate");
/* Create dataspace for datasets */
sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
CHECK(sid1, FAIL, "H5Screate_simple");
/* Create a compound datatype to refer to */
tid2 = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
CHECK(tid2, FAIL, "H5Tcreate");
/* Insert integer field */
ret = H5Tinsert (tid2, "i", HOFFSET(s1_t,i), H5T_NATIVE_INT);
CHECK(ret, FAIL, "H5Tinsert");
/* Create an array of floats datatype */
tid3 = H5Tarray_create2(H5T_NATIVE_FLOAT, ARRAY1_RANK, tdims1);
CHECK(tid3, FAIL, "H5Tarray_create2");
/* Insert float array field */
ret = H5Tinsert(tid2, "f", HOFFSET(s1_t, f), tid3);
CHECK(ret, FAIL, "H5Tinsert");
/* Close array of floats field datatype */
ret = H5Tclose(tid3);
CHECK(ret, FAIL, "H5Tclose");
/* Create an array datatype to refer to */
tid1 = H5Tarray_create2(tid2, ARRAY1_RANK, tdims1);
CHECK(tid1, FAIL, "H5Tarray_create2");
/* Close compound datatype */
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Create a dataset */
dataset = H5Dcreate2(fid1, "Dataset1", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dcreate2");
/* Write dataset to disk */
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
CHECK(ret, FAIL, "H5Dwrite");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close disk dataspace */
ret = H5Sclose(sid1);
CHECK(ret, FAIL, "H5Sclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Re-open file */
fid1 = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* Open the dataset */
dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
/* Get the datatype */
tid1 = H5Dget_type (dataset);
CHECK(tid1, FAIL, "H5Dget_type");
/* Check the array rank */
ndims=H5Tget_array_ndims(tid1);
VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(tid1, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i=0; i<ndims; i++)
if(rdims1[i]!=tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n",(int)i,(int)rdims1[i],(int)i,(int)tdims1[i]);
continue;
} /* end if */
/* Get the compound datatype */
tid2 = H5Tget_super (tid1);
CHECK(tid2, FAIL, "H5Tget_super");
/* Check the number of members */
nmemb=H5Tget_nmembers(tid2);
VERIFY(nmemb,2,"H5Tget_nmembers");
/* Check the 1st field's name */
mname=H5Tget_member_name(tid2,0);
CHECK(mname, NULL, "H5Tget_member_name");
if(HDstrcmp(mname,"i")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
free(mname);
/* Check the 1st field's offset */
off=H5Tget_member_offset(tid2,0);
VERIFY(off, HOFFSET(s1_t,i), "H5Tget_member_offset");
/* Check the 1st field's datatype */
mtid=H5Tget_member_type(tid2,0);
CHECK(mtid, FAIL, "H5Tget_member_type");
if((ret=H5Tequal(mtid,H5T_NATIVE_INT))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
ret=H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Check the 2nd field's name */
mname=H5Tget_member_name(tid2,1);
CHECK(mname, NULL, "H5Tget_member_name");
if(HDstrcmp(mname,"f")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
free(mname);
/* Check the 2nd field's offset */
off=H5Tget_member_offset(tid2,1);
VERIFY(off, HOFFSET(s1_t,f), "H5Tget_member_offset");
/* Check the 2nd field's datatype */
mtid=H5Tget_member_type(tid2,1);
CHECK(mtid, FAIL, "H5Tget_member_type");
/* Get the 2nd field's class */
mclass=H5Tget_class(mtid);
VERIFY(mclass, H5T_ARRAY, "H5Tget_class");
/* Check the array rank */
ndims=H5Tget_array_ndims(mtid);
VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(mtid, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i=0; i<ndims; i++)
if(rdims1[i]!=tdims1[i]) {
TestErrPrintf("Nested array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n",(int)i,(int)rdims1[i],(int)i,(int)tdims1[i]);
continue;
} /* end if */
/* Check the nested array's datatype */
tid3=H5Tget_super(mtid);
CHECK(tid3, FAIL, "H5Tget_super");
if((ret=H5Tequal(tid3,H5T_NATIVE_FLOAT))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
/* Close the array's base type datatype */
ret=H5Tclose(tid3);
CHECK(mtid, FAIL, "H5Tclose");
/* Close the member datatype */
ret=H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Close Compound Datatype */
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Read dataset from disk */
ret=H5Dread(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,rdata);
CHECK(ret, FAIL, "H5Dread");
/* Compare data read in */
for(i=0; i<SPACE1_DIM1; i++) {
for(j=0; j<ARRAY1_DIM1; j++) {
if(wdata[i][j].i!=rdata[i][j].i) {
TestErrPrintf("Array data information doesn't match!, wdata[%d][%d].i=%d, rdata[%d][%d].i=%d\n",(int)i,(int)j,(int)wdata[i][j].i,(int)i,(int)j,(int)rdata[i][j].i);
continue;
} /* end if */
for(k=0; k<ARRAY1_DIM1; k++)
if(!FLT_ABS_EQUAL(wdata[i][j].f[k],rdata[i][j].f[k])) {
TestErrPrintf("Array data information doesn't match!, wdata[%d][%d].f[%d]=%f, rdata[%d][%d].f[%d]=%f\n",(int)i,(int)j,(int)k,wdata[i][j].f[k],(int)i,(int)j,(int)k,rdata[i][j].f[k]);
continue;
} /* end if */
} /* end for */
} /* end for */
/* Close Datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
} /* end test_array_compound_array() */
void *test_array_alloc_custom(size_t size, void *info);
void test_array_free_custom(void *mem, void *info);
/****************************************************************
**
** test_array_alloc_custom(): Test VL datatype custom memory
** allocation routines. This routine just uses malloc to
** allocate the memory and increments the amount of memory
** allocated.
**
****************************************************************/
void *test_array_alloc_custom(size_t size, void *info)
{
void *ret_value=NULL; /* Pointer to return */
int *mem_used=(int *)info; /* Get the pointer to the memory used */
size_t extra; /* Extra space needed */
/*
* This weird contortion is required on the DEC Alpha to keep the
* alignment correct - QAK
*/
extra=MAX(sizeof(void *),sizeof(size_t));
if((ret_value=HDmalloc(extra+size))!=NULL) {
*(size_t *)ret_value=size;
*mem_used+=size;
} /* end if */
ret_value=((unsigned char *)ret_value)+extra;
return(ret_value);
}
/****************************************************************
**
** test_array_free_custom(): Test VL datatype custom memory
** allocation routines. This routine just uses free to
** release the memory and decrements the amount of memory
** allocated.
**
****************************************************************/
void test_array_free_custom(void *_mem, void *info)
{
unsigned char *mem;
int *mem_used=(int *)info; /* Get the pointer to the memory used */
size_t extra; /* Extra space needed */
/*
* This weird contortion is required on the DEC Alpha to keep the
* alignment correct - QAK
*/
extra=MAX(sizeof(void *),sizeof(size_t));
if(_mem!=NULL) {
mem=((unsigned char *)_mem)-extra;
*mem_used-=*(size_t *)mem;
HDfree(mem);
} /* end if */
}
/****************************************************************
**
** test_array_vlen_atomic(): Test basic array datatype code.
** Tests 1-D array of atomic VL datatypes
**
****************************************************************/
static void
test_array_vlen_atomic(void)
{
hvl_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
hvl_t rdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information read in */
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Array Datatype ID */
hid_t tid2; /* VL Datatype ID */
hid_t tid3; /* Atomic Datatype ID */
hsize_t sdims1[] = {SPACE1_DIM1};
hsize_t tdims1[] = {ARRAY1_DIM1};
int ndims; /* Array rank for reading */
hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */
H5T_class_t mclass; /* Datatype class for VL */
hid_t xfer_pid; /* Dataset transfer property list ID */
hsize_t size; /* Number of bytes which will be used */
int mem_used=0; /* Memory used during allocation */
int i,j,k; /* counting variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing 1-D Array of Atomic Variable-Length Datatypes Functionality\n"));
/* Initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
for(j=0; j<ARRAY1_DIM1; j++) {
wdata[i][j].p=malloc((i+j+1)*sizeof(unsigned int));
wdata[i][j].len=i+j+1;
for(k=0; k<(i+j+1); k++)
((unsigned int *)wdata[i][j].p)[k]=i*100+j*10+k;
} /* end for */
/* Create file */
fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fcreate");
/* Create dataspace for datasets */
sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
CHECK(sid1, FAIL, "H5Screate_simple");
/* Create a compound datatype to refer to */
tid2 = H5Tvlen_create(H5T_NATIVE_UINT);
CHECK(tid2, FAIL, "H5Tcreate");
/* Create an array datatype to refer to */
tid1 = H5Tarray_create2(tid2, ARRAY1_RANK, tdims1);
CHECK(tid1, FAIL, "H5Tarray_create2");
/* Close VL datatype */
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Create a dataset */
dataset = H5Dcreate2(fid1, "Dataset1", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dcreate2");
/* Write dataset to disk */
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
CHECK(ret, FAIL, "H5Dwrite");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close disk dataspace */
ret = H5Sclose(sid1);
CHECK(ret, FAIL, "H5Sclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Re-open file */
fid1 = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* Open the dataset */
dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
/* Get the dataspace */
sid1 = H5Dget_space (dataset);
CHECK(sid1, FAIL, "H5Dget_space");
/* Get the datatype */
tid1 = H5Dget_type (dataset);
CHECK(tid1, FAIL, "H5Dget_type");
/* Check the array rank */
ndims=H5Tget_array_ndims(tid1);
VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(tid1, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i=0; i<ndims; i++)
if(rdims1[i]!=tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n",(int)i,(int)rdims1[i],(int)i,(int)tdims1[i]);
continue;
} /* end if */
/* Get the VL datatype */
tid2 = H5Tget_super (tid1);
CHECK(tid2, FAIL, "H5Tget_super");
/* Get the 2nd field's class */
mclass=H5Tget_class(tid2);
VERIFY(mclass, H5T_VLEN, "H5Tget_class");
/* Check the VL datatype's base type */
tid3=H5Tget_super(tid2);
CHECK(tid3, FAIL, "H5Tget_super");
if((ret=H5Tequal(tid3,H5T_NATIVE_UINT))<=0)
TestErrPrintf("VL base datatype is incorrect!, ret=%d\n",(int)ret);
/* Close the array's base type datatype */
ret=H5Tclose(tid3);
CHECK(ret, FAIL, "H5Tclose");
/* Close VL Datatype */
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Change to the custom memory allocation routines for reading VL data */
xfer_pid=H5Pcreate(H5P_DATASET_XFER);
CHECK(xfer_pid, FAIL, "H5Pcreate");
ret=H5Pset_vlen_mem_manager(xfer_pid,test_array_alloc_custom,&mem_used,test_array_free_custom,&mem_used);
CHECK(ret, FAIL, "H5Pset_vlen_mem_manager");
/* Make certain the correct amount of memory will be used */
ret=H5Dvlen_get_buf_size(dataset,tid1,sid1,&size);
CHECK(ret, FAIL, "H5Dvlen_get_buf_size");
/* # elements allocated = (1 + 2 + 3 + 4) + (2 + 3 + 4 + 5) +
* (3 + 4 + 5 + 6) + (4 + 5 + 6 + 7) = 64 elements
*/
VERIFY(size,64*sizeof(unsigned int),"H5Dvlen_get_buf_size");
/* Read dataset from disk */
ret=H5Dread(dataset,tid1,H5S_ALL,H5S_ALL,xfer_pid,rdata);
CHECK(ret, FAIL, "H5Dread");
/* Make certain the correct amount of memory has been used */
/* # elements allocated = (1 + 2 + 3 + 4) + (2 + 3 + 4 + 5) +
* (3 + 4 + 5 + 6) + (4 + 5 + 6 + 7) = 64 elements
*/
VERIFY(mem_used,64*sizeof(unsigned int),"H5Dread");
/* Compare data read in */
for(i=0; i<SPACE1_DIM1; i++) {
for(j=0; j<ARRAY1_DIM1; j++) {
if(wdata[i][j].len!=rdata[i][j].len) {
TestErrPrintf("VL data length don't match!, wdata[%d][%d].len=%d, rdata[%d][%d].len=%d\n",(int)i,(int)j,(int)wdata[i][j].len,(int)i,(int)j,(int)rdata[i][j].len);
continue;
} /* end if */
for(k=0; k<(int)rdata[i][j].len; k++) {
if( ((unsigned int *)wdata[i][j].p)[k] != ((unsigned int *)rdata[i][j].p)[k] ) {
TestErrPrintf("VL data values don't match!, wdata[%d][%d].p[%d]=%d, rdata[%d][%d].p[%d]=%d\n",(int)i,(int)j,(int)k, (int)((unsigned int *)wdata[i][j].p)[k], (int)i,(int)j,(int)k, (int)((unsigned int *)rdata[i][j].p)[k]);
continue;
} /* end if */
} /* end for */
} /* end for */
} /* end for */
/* Reclaim the read VL data */
ret=H5Dvlen_reclaim(tid1,sid1,xfer_pid,rdata);
CHECK(ret, FAIL, "H5Dvlen_reclaim");
/* Make certain the VL memory has been freed */
VERIFY(mem_used,0,"H5Dvlen_reclaim");
/* Reclaim the write VL data */
ret=H5Dvlen_reclaim(tid1,sid1,H5P_DEFAULT,wdata);
CHECK(ret, FAIL, "H5Dvlen_reclaim");
/* Close dataset transfer property list */
ret = H5Pclose(xfer_pid);
CHECK(ret, FAIL, "H5Pclose");
/* Close Datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
} /* end test_array_vlen_atomic() */
/****************************************************************
**
** test_array_vlen_array(): Test basic array datatype code.
** Tests 1-D array of 1-D array VL datatypes
**
****************************************************************/
static void
test_array_vlen_array(void)
{
hvl_t wdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information to write */
hvl_t rdata[SPACE1_DIM1][ARRAY1_DIM1]; /* Information read in */
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Array Datatype ID */
hid_t tid2; /* VL Datatype ID */
hid_t tid3; /* Nested Array Datatype ID */
hid_t tid4; /* Atomic Datatype ID */
hsize_t sdims1[] = {SPACE1_DIM1};
hsize_t tdims1[] = {ARRAY1_DIM1};
int ndims; /* Array rank for reading */
hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */
H5T_class_t mclass; /* Datatype class for VL */
hid_t xfer_pid; /* Dataset transfer property list ID */
hsize_t size; /* Number of bytes which will be used */
int mem_used=0; /* Memory used during allocation */
int i,j,k,l; /* Index variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing 1-D Array of 1-D Array Variable-Length Datatypes Functionality\n"));
/* Initialize array data to write */
for(i=0; i<SPACE1_DIM1; i++)
for(j=0; j<ARRAY1_DIM1; j++) {
wdata[i][j].p=malloc((i+j+1)*(sizeof(unsigned int)*ARRAY1_DIM1));
wdata[i][j].len=i+j+1;
for(k=0; k<(i+j+1); k++)
for(l=0; l<ARRAY1_DIM1; l++)
((unsigned int *)wdata[i][j].p)[k*ARRAY1_DIM1+l]=i*1000+j*100+k*10+l;
} /* end for */
/* Create file */
fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fcreate");
/* Create dataspace for datasets */
sid1 = H5Screate_simple(SPACE1_RANK, sdims1, NULL);
CHECK(sid1, FAIL, "H5Screate_simple");
/* Create the nested array datatype to refer to */
tid3 = H5Tarray_create2(H5T_NATIVE_UINT, ARRAY1_RANK, tdims1);
CHECK(tid3, FAIL, "H5Tarray_create2");
/* Create a VL datatype of 1-D arrays to refer to */
tid2 = H5Tvlen_create(tid3);
CHECK(tid2, FAIL, "H5Tcreate");
/* Close nested array datatype */
ret = H5Tclose(tid3);
CHECK(ret, FAIL, "H5Tclose");
/* Create an array datatype to refer to */
tid1 = H5Tarray_create2(tid2, ARRAY1_RANK, tdims1);
CHECK(tid1, FAIL, "H5Tarray_create2");
/* Close VL datatype */
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Create a dataset */
dataset = H5Dcreate2(fid1, "Dataset1", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dcreate2");
/* Write dataset to disk */
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
CHECK(ret, FAIL, "H5Dwrite");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close disk dataspace */
ret = H5Sclose(sid1);
CHECK(ret, FAIL, "H5Sclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Re-open file */
fid1 = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* Open the dataset */
dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
/* Get the dataspace */
sid1 = H5Dget_space (dataset);
CHECK(sid1, FAIL, "H5Dget_space");
/* Get the datatype */
tid1 = H5Dget_type (dataset);
CHECK(tid1, FAIL, "H5Dget_type");
/* Check the array rank */
ndims=H5Tget_array_ndims(tid1);
VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(tid1, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i=0; i<ndims; i++)
if(rdims1[i]!=tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n",(int)i,(int)rdims1[i],(int)i,(int)tdims1[i]);
continue;
} /* end if */
/* Get the VL datatype */
tid2 = H5Tget_super (tid1);
CHECK(tid2, FAIL, "H5Tget_super");
/* Get the VL datatype's class */
mclass=H5Tget_class(tid2);
VERIFY(mclass, H5T_VLEN, "H5Tget_class");
/* Check the VL datatype's base type */
tid3=H5Tget_super(tid2);
CHECK(tid3, FAIL, "H5Tget_super");
/* Get the nested array datatype's class */
mclass=H5Tget_class(tid3);
VERIFY(mclass, H5T_ARRAY, "H5Tget_class");
/* Check the array rank */
ndims=H5Tget_array_ndims(tid3);
VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(tid3, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i=0; i<ndims; i++)
if(rdims1[i]!=tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n",(int)i,(int)rdims1[i],(int)i,(int)tdims1[i]);
continue;
} /* end if */
/* Check the array's base type */
tid4=H5Tget_super(tid3);
CHECK(tid4, FAIL, "H5Tget_super");
if((ret=H5Tequal(tid4,H5T_NATIVE_UINT))<=0)
TestErrPrintf("VL base datatype is incorrect!, ret=%d\n",(int)ret);
/* Close the array's base type datatype */
ret=H5Tclose(tid4);
CHECK(ret, FAIL, "H5Tclose");
/* Close the nested array datatype */
ret=H5Tclose(tid3);
CHECK(ret, FAIL, "H5Tclose");
/* Close VL Datatype */
ret = H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
/* Change to the custom memory allocation routines for reading VL data */
xfer_pid=H5Pcreate(H5P_DATASET_XFER);
CHECK(xfer_pid, FAIL, "H5Pcreate");
ret=H5Pset_vlen_mem_manager(xfer_pid,test_array_alloc_custom,&mem_used,test_array_free_custom,&mem_used);
CHECK(ret, FAIL, "H5Pset_vlen_mem_manager");
/* Make certain the correct amount of memory will be used */
ret=H5Dvlen_get_buf_size(dataset,tid1,sid1,&size);
CHECK(ret, FAIL, "H5Dvlen_get_buf_size");
/* # elements allocated = (1 + 2 + 3 + 4) + (2 + 3 + 4 + 5) +
* (3 + 4 + 5 + 6) + (4 + 5 + 6 + 7) = 64*ARRAY1_DIM1 elements
*/
VERIFY(size,64*(sizeof(unsigned int)*ARRAY1_DIM1),"H5Dvlen_get_buf_size");
/* Read dataset from disk */
ret=H5Dread(dataset,tid1,H5S_ALL,H5S_ALL,xfer_pid,rdata);
CHECK(ret, FAIL, "H5Dread");
/* Make certain the correct amount of memory has been used */
/* # elements allocated = (1 + 2 + 3 + 4) + (2 + 3 + 4 + 5) +
* (3 + 4 + 5 + 6) + (4 + 5 + 6 + 7) = 64*ARRAY1_DIM1 elements
*/
VERIFY(mem_used,64*(sizeof(unsigned int)*ARRAY1_DIM1),"H5Dread");
/* Compare data read in */
for(i=0; i<SPACE1_DIM1; i++) {
for(j=0; j<ARRAY1_DIM1; j++) {
if(wdata[i][j].len!=rdata[i][j].len) {
TestErrPrintf("VL data length don't match!, wdata[%d][%d].len=%d, rdata[%d][%d].len=%d\n",(int)i,(int)j,(int)wdata[i][j].len,(int)i,(int)j,(int)rdata[i][j].len);
continue;
} /* end if */
for(k=0; k<(int)rdata[i][j].len; k++) {
for(l=0; l<ARRAY1_DIM1; l++) {
if( ((unsigned int *)wdata[i][j].p)[k*ARRAY1_DIM1+l] != ((unsigned int *)rdata[i][j].p)[k*ARRAY1_DIM1+l] ) {
TestErrPrintf("VL data values don't match!, wdata[%d][%d].p[%d][%d]=%d, rdata[%d][%d].p[%d][%d]=%d\n",(int)i,(int)j,(int)k,(int)l, (int)((unsigned int *)wdata[i][j].p)[k*ARRAY1_DIM1+l], (int)i,(int)j,(int)k,(int)l, (int)((unsigned int *)rdata[i][j].p)[k*ARRAY1_DIM1+l]);
continue;
} /* end if */
} /* end for */
} /* end for */
} /* end for */
} /* end for */
/* Reclaim the read VL data */
ret=H5Dvlen_reclaim(tid1,sid1,xfer_pid,rdata);
CHECK(ret, FAIL, "H5Dvlen_reclaim");
/* Make certain the VL memory has been freed */
VERIFY(mem_used,0,"H5Dvlen_reclaim");
/* Reclaim the write VL data */
ret=H5Dvlen_reclaim(tid1,sid1,H5P_DEFAULT,wdata);
CHECK(ret, FAIL, "H5Dvlen_reclaim");
/* Close dataset transfer property list */
ret = H5Pclose(xfer_pid);
CHECK(ret, FAIL, "H5Pclose");
/* Close Datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
} /* end test_array_vlen_array() */
#define FIELDNAME "ArrayofStructures"
#define LENGTH 5
#define ALEN 10
#define RANK 1
#define NMAX 100
typedef struct
{
int nsubfields;
char *name[NMAX];
size_t offset[NMAX];
hid_t datatype[NMAX];
} CmpDTSinfo;
/****************************************************************
**
** test_array_bkg(): Test basic array datatype code.
** Tests reading compound datatype with array fields and
** writing partial fields.
**
****************************************************************/
static void
test_array_bkg(void)
{
herr_t status = -1;
hid_t fid, array_dt;
hid_t space;
hid_t type;
hid_t dataset;
hsize_t dim[] = {LENGTH};
hsize_t dima[] = {ALEN};
int i, j;
unsigned ndims[3] = {1,1,1};
typedef struct
{
int a[ALEN];
float b[ALEN];
double c[ALEN];
} CmpField;
CmpField cf[LENGTH];
CmpField cfr[LENGTH];
CmpDTSinfo dtsinfo;
typedef struct
{
float b[ALEN];
} fld_t;
fld_t fld[LENGTH];
fld_t fldr[LENGTH];
/* Output message about test being performed */
MESSAGE(5, ("Testing Partial I/O of Array Fields in Compound Datatype Functionality\n"));
/* Initialize the data */
/* ------------------- */
for (i = 0; i < LENGTH; i++)
{
for (j = 0; j < ALEN; j++)
{
cf[i].a[j] = 100*(i+1) + j;
cf[i].b[j] = (float)(100.*(i+1) + 0.01*j);
cf[i].c[j] = 100.*(i+1) + 0.02*j;
}
}
/* Set the number of data members */
/* ------------------------------ */
dtsinfo.nsubfields = 3;
/* Initialize the offsets */
/* ----------------------- */
dtsinfo.offset[0] = HOFFSET(CmpField, a);
dtsinfo.offset[1] = HOFFSET(CmpField, b);
dtsinfo.offset[2] = HOFFSET(CmpField, c);
/* Initialize the data type IDs */
/* ---------------------------- */
dtsinfo.datatype[0] = H5T_NATIVE_INT;
dtsinfo.datatype[1] = H5T_NATIVE_FLOAT;
dtsinfo.datatype[2] = H5T_NATIVE_DOUBLE;
/* Initialize the names of data members */
/* ------------------------------------ */
for (i = 0; i < dtsinfo.nsubfields; i++)
dtsinfo.name[i] = (char *)HDcalloc((size_t)20, sizeof(char));
strcpy(dtsinfo.name[0], "One");
strcpy(dtsinfo.name[1], "Two");
strcpy(dtsinfo.name[2], "Three");
/* Create file */
/* ----------- */
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fcreate");
/* Create data space */
/* ----------------- */
space = H5Screate_simple(RANK, dim, NULL);
CHECK(space, FAIL, "H5Screate_simple");
/* Create the memory data type */
/* --------------------------- */
type = H5Tcreate(H5T_COMPOUND, sizeof(CmpField));
CHECK(type, FAIL, "H5Tcreate");
/* Add members to the compound data type */
/* -------------------------------------- */
for ( i = 0; i < dtsinfo.nsubfields; i++)
{
array_dt = H5Tarray_create2(dtsinfo.datatype[i], ndims[i], dima);
CHECK(array_dt, FAIL, "H5Tarray_create2");
status = H5Tinsert (type, dtsinfo.name[i], dtsinfo.offset[i], array_dt);
CHECK(status, FAIL, "H5Tinsert");
status = H5Tclose(array_dt);
CHECK(status, FAIL, "H5Tclose");
}
/* Create the dataset */
/* ------------------ */
dataset = H5Dcreate2(fid, FIELDNAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dcreate2");
/* Write data to the dataset */
/* ------------------------- */
status = H5Dwrite(dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, cf);
CHECK(status, FAIL, "H5Dwrite");
status = H5Dread(dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, cfr);
CHECK(status, FAIL, "H5Dread");
/* Verify correct data */
/* ------------------- */
for (i = 0; i < LENGTH; i++) {
for (j = 0; j < ALEN; j++) {
if(cf[i].a[j]!=cfr[i].a[j]) {
TestErrPrintf("Field a data doesn't match, cf[%d].a[%d]=%d, cfr[%d].a[%d]=%d\n",(int)i,(int)j,(int)cf[i].a[j],(int)i,(int)j,(int)cfr[i].a[j]);
continue;
}
if(!FLT_ABS_EQUAL(cf[i].b[j],cfr[i].b[j])) {
TestErrPrintf("Field b data doesn't match, cf[%d].b[%d]=%f, cfr[%d].b[%d]=%f\n",(int)i,(int)j,(float)cf[i].b[j],(int)i,(int)j,(float)cfr[i].b[j]);
continue;
}
if(!DBL_ABS_EQUAL(cf[i].c[j],cfr[i].c[j])) {
TestErrPrintf("Field c data doesn't match, cf[%d].b[%d]=%f, cfr[%d].b[%d]=%f\n",(int)i,(int)j,(float)cf[i].c[j],(int)i,(int)j,(float)cfr[i].c[j]);
continue;
}
}
}
/* Release memory resources */
/* ------------------------ */
for (i = 0; i < dtsinfo.nsubfields; i++)
free(dtsinfo.name[i]);
/* Release IDs */
/* ----------- */
status = H5Tclose(type);
CHECK(status, FAIL, "H5Tclose");
status = H5Sclose(space);
CHECK(status, FAIL, "H5Sclose");
status = H5Dclose(dataset);
CHECK(status, FAIL, "H5Dclose");
status = H5Fclose(fid);
CHECK(status, FAIL, "H5Fclose");
/******************************/
/* Reopen the file and update */
/******************************/
fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");
dataset = H5Dopen2(fid, FIELDNAME, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
type = H5Tcreate(H5T_COMPOUND, sizeof(fld_t));
CHECK(type, FAIL, "H5Tcreate");
array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, dima);
CHECK(array_dt, FAIL, "H5Tarray_create2");
status = H5Tinsert (type, "Two", HOFFSET(fld_t, b), array_dt);
CHECK(status, FAIL, "H5Tinsert");
/* Initialize the data to overwrite */
/* -------------------------------- */
for (i=0; i< LENGTH; i++)
for (j = 0; j < ALEN; j++)
cf[i].b[j]=fld[i].b[j] = (float)1.313;
status = H5Dwrite (dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, fld);
CHECK(status, FAIL, "H5Dwrite");
/* Read just the field changed */
status = H5Dread (dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, fldr);
CHECK(status, FAIL, "H5Dread");
for (i=0; i< LENGTH; i++)
for (j = 0; j < ALEN; j++)
if(!FLT_ABS_EQUAL(fld[i].b[j],fldr[i].b[j])) {
TestErrPrintf("Field data doesn't match, fld[%d].b[%d]=%f, fldr[%d].b[%d]=%f\n",(int)i,(int)j,(float)fld[i].b[j],(int)i,(int)j,(float)fldr[i].b[j]);
continue;
}
status = H5Tclose (type);
CHECK(status, FAIL, "H5Tclose");
status = H5Tclose (array_dt);
CHECK(status, FAIL, "H5Tclose");
type = H5Dget_type(dataset);
CHECK(type, FAIL, "H5Dget_type");
/* Read the entire dataset again */
status = H5Dread(dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, cfr);
CHECK(status, FAIL, "H5Dread");
/* Verify correct data */
/* ------------------- */
for (i = 0; i < LENGTH; i++) {
for (j = 0; j < ALEN; j++) {
if(cf[i].a[j]!=cfr[i].a[j]) {
TestErrPrintf("Field a data doesn't match, cf[%d].a[%d]=%d, cfr[%d].a[%d]=%d\n",(int)i,(int)j,(int)cf[i].a[j],(int)i,(int)j,(int)cfr[i].a[j]);
continue;
}
if(!FLT_ABS_EQUAL(cf[i].b[j],cfr[i].b[j])) {
TestErrPrintf("Field b data doesn't match, cf[%d].b[%d]=%f, cfr[%d].b[%d]=%f\n",(int)i,(int)j,(float)cf[i].b[j],(int)i,(int)j,(float)cfr[i].b[j]);
continue;
}
if(!DBL_ABS_EQUAL(cf[i].c[j],cfr[i].c[j])) {
TestErrPrintf("Field c data doesn't match, cf[%d].b[%d]=%f, cfr[%d].b[%d]=%f\n",(int)i,(int)j,(float)cf[i].c[j],(int)i,(int)j,(float)cfr[i].c[j]);
continue;
}
}
}
status = H5Dclose(dataset);
CHECK(status, FAIL, "H5Dclose");
status = H5Tclose (type);
CHECK(status, FAIL, "H5Tclose");
status = H5Fclose(fid);
CHECK(status, FAIL, "H5Fclose");
/****************************************************/
/* Reopen the file and print out all the data again */
/****************************************************/
fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid, FAIL, "H5Fopen");
dataset = H5Dopen2(fid, FIELDNAME, H5P_DEFAULT);
CHECK(dataset, FAIL, "H5Dopen2");
type = H5Dget_type(dataset);
CHECK(type, FAIL, "H5Dget_type");
/* Reset the data to read in */
/* ------------------------- */
memset(cfr, 0, sizeof(CmpField)*LENGTH);
status = H5Dread(dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, cfr);
CHECK(status, FAIL, "H5Dread");
/* Verify correct data */
/* ------------------- */
for (i = 0; i < LENGTH; i++) {
for (j = 0; j < ALEN; j++) {
if(cf[i].a[j]!=cfr[i].a[j]) {
TestErrPrintf("Field a data doesn't match, cf[%d].a[%d]=%d, cfr[%d].a[%d]=%d\n",(int)i,(int)j,(int)cf[i].a[j],(int)i,(int)j,(int)cfr[i].a[j]);
continue;
}
if(!FLT_ABS_EQUAL(cf[i].b[j],cfr[i].b[j])) {
TestErrPrintf("Field b data doesn't match, cf[%d].b[%d]=%f, cfr[%d].b[%d]=%f\n",(int)i,(int)j,(float)cf[i].b[j],(int)i,(int)j,(float)cfr[i].b[j]);
continue;
}
if(!DBL_ABS_EQUAL(cf[i].c[j],cfr[i].c[j])) {
TestErrPrintf("Field c data doesn't match, cf[%d].b[%d]=%f, cfr[%d].b[%d]=%f\n",(int)i,(int)j,(float)cf[i].c[j],(int)i,(int)j,(float)cfr[i].c[j]);
continue;
}
}
}
status = H5Dclose(dataset);
CHECK(status, FAIL, "H5Dclose");
status = H5Tclose (type);
CHECK(status, FAIL, "H5Tclose");
status = H5Fclose(fid);
CHECK(status, FAIL, "H5Fclose");
} /* end test_array_bkg() */
/****************************************************************
**
** test_compat(): Test array datatype compatibility code.
** Reads file containing old version of datatype object header
** messages for compound datatypes and verifies reading the older
** version of the is working correctly.
**
****************************************************************/
static void
test_compat(void)
{
char testfile[512]=""; /* Character buffer for corrected test file name */
char *srcdir = getenv("srcdir"); /* Pointer to the directory the source code is located within */
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t tid1; /* Array Datatype ID */
hid_t tid2; /* Datatype ID */
hsize_t tdims1[] = {ARRAY1_DIM1};
int ndims; /* Array rank for reading */
hsize_t rdims1[H5S_MAX_RANK]; /* Array dimensions for reading */
H5T_class_t mclass; /* Datatype class for VL */
int nmemb; /* Number of compound members */
char *mname; /* Name of compound field */
size_t off; /* Offset of compound field */
hid_t mtid; /* Datatype ID for field */
int i; /* Index variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing Array Datatypes Compatibility Functionality\n"));
/*
* Try reading a file that has been prepared that has datasets with
* compound datatypes which use an older version (version 1) of the
* datatype object header message for describing the datatype.
*
* If this test fails and the datatype object header message version has
* changed, follow the instructions in gen_old_array.c for regenerating
* the tarrold.h5 file.
*/
/* Generate the correct name for the test file, by prepending the source path */
if (srcdir && ((strlen(srcdir) + strlen(TESTFILE) + 1) < sizeof(testfile))) {
strcpy(testfile, srcdir);
strcat(testfile, "/");
}
strcat(testfile, TESTFILE);
/* Open the testfile */
fid1 = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK_I(fid1, "H5Fopen");
/* Only try to proceed if the file is around */
if (fid1 >= 0){
/* Open the first dataset (with no array fields) */
dataset = H5Dopen2(fid1, "Dataset1", H5P_DEFAULT);
CHECK_I(dataset, "H5Dopen2");
/* Get the datatype */
tid1=H5Dget_type(dataset);
CHECK_I(tid1, "H5Dget_type");
/* Verify datatype class */
mclass=H5Tget_class(tid1);
VERIFY(mclass, H5T_COMPOUND, "H5Tget_class");
/* Get the number of compound datatype fields */
nmemb=H5Tget_nmembers(tid1);
VERIFY(nmemb,3,"H5Tget_nmembers");
/* Check the 1st field's name */
mname=H5Tget_member_name(tid1,0);
CHECK(mname, NULL, "H5Tget_member_name");
if(HDstrcmp(mname,"i")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
free(mname);
/* Check the 1st field's offset */
off=H5Tget_member_offset(tid1,0);
VERIFY(off, 0, "H5Tget_member_offset");
/* Check the 1st field's datatype */
mtid=H5Tget_member_type(tid1,0);
CHECK(mtid, FAIL, "H5Tget_member_type");
if((ret=H5Tequal(mtid,H5T_STD_I16LE))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
ret=H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Check the 2nd field's name */
mname=H5Tget_member_name(tid1,1);
CHECK(mname, NULL, "H5Tget_member_name");
if(HDstrcmp(mname,"f")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
free(mname);
/* Check the 2nd field's offset */
off=H5Tget_member_offset(tid1,1);
VERIFY(off, 4, "H5Tget_member_offset");
/* Check the 2nd field's datatype */
mtid=H5Tget_member_type(tid1,1);
CHECK(mtid, FAIL, "H5Tget_member_type");
if((ret=H5Tequal(mtid,H5T_IEEE_F32LE))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
ret=H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Check the 3rd field's name */
mname=H5Tget_member_name(tid1,2);
CHECK(mname, NULL, "H5Tget_member_name");
if(HDstrcmp(mname,"l")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
free(mname);
/* Check the 3rd field's offset */
off=H5Tget_member_offset(tid1,2);
VERIFY(off, 8, "H5Tget_member_offset");
/* Check the 3rd field's datatype */
mtid=H5Tget_member_type(tid1,2);
CHECK(mtid, FAIL, "H5Tget_member_type");
if((ret=H5Tequal(mtid,H5T_STD_I32LE))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
ret=H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Close the datatype */
ret = H5Tclose(tid1);
CHECK_I(ret, "H5Tclose");
/* Close the dataset */
ret = H5Dclose(dataset);
CHECK_I(ret, "H5Dclose");
/* Open the second dataset (with array fields) */
dataset = H5Dopen2(fid1, "Dataset2", H5P_DEFAULT);
CHECK_I(dataset, "H5Dopen2");
/* Get the datatype */
tid1=H5Dget_type(dataset);
CHECK_I(tid1, "H5Dget_type");
/* Verify datatype class */
mclass=H5Tget_class(tid1);
VERIFY(mclass, H5T_COMPOUND, "H5Tget_class");
/* Get the number of compound datatype fields */
nmemb=H5Tget_nmembers(tid1);
VERIFY(nmemb,4,"H5Tget_nmembers");
/* Check the 1st field's name */
mname=H5Tget_member_name(tid1,0);
CHECK(mname, NULL, "H5Tget_member_name");
if(mname && HDstrcmp(mname,"i")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
if(mname) free(mname);
/* Check the 1st field's offset */
off=H5Tget_member_offset(tid1,0);
VERIFY(off, 0, "H5Tget_member_offset");
/* Check the 1st field's datatype */
mtid=H5Tget_member_type(tid1,0);
CHECK(mtid, FAIL, "H5Tget_member_type");
if((ret=H5Tequal(mtid,H5T_STD_I16LE))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
ret=H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Check the 2nd field's name */
mname=H5Tget_member_name(tid1,1);
CHECK(mname, NULL, "H5Tget_member_name");
if(mname && HDstrcmp(mname,"f")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
if(mname) free(mname);
/* Check the 2nd field's offset */
off=H5Tget_member_offset(tid1,1);
VERIFY(off, 4, "H5Tget_member_offset");
/* Check the 2nd field's datatype */
mtid=H5Tget_member_type(tid1,1);
CHECK(mtid, FAIL, "H5Tget_member_type");
/* Verify datatype class */
mclass=H5Tget_class(mtid);
VERIFY(mclass, H5T_ARRAY, "H5Tget_class");
/* Check the array rank */
ndims=H5Tget_array_ndims(mtid);
VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(mtid, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i=0; i<ndims; i++)
if(rdims1[i]!=tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n",(int)i,(int)rdims1[i],(int)i,(int)tdims1[i]);
continue;
} /* end if */
/* Check the array's base datatype */
tid2=H5Tget_super(mtid);
CHECK(tid2, FAIL, "H5Tget_super");
if((ret=H5Tequal(tid2,H5T_IEEE_F32LE))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
ret=H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
ret=H5Tclose(mtid);
CHECK(ret, FAIL, "H5Tclose");
/* Check the 3rd field's name */
mname=H5Tget_member_name(tid1,2);
CHECK(mname, NULL, "H5Tget_member_name");
if(mname && HDstrcmp(mname,"l")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
if(mname) free(mname);
/* Check the 3rd field's offset */
off=H5Tget_member_offset(tid1,2);
VERIFY(off, 20, "H5Tget_member_offset");
/* Check the 3rd field's datatype */
mtid=H5Tget_member_type(tid1,2);
CHECK(mtid, FAIL, "H5Tget_member_type");
/* Verify datatype class */
mclass=H5Tget_class(mtid);
VERIFY(mclass, H5T_ARRAY, "H5Tget_class");
/* Check the array rank */
ndims=H5Tget_array_ndims(mtid);
VERIFY(ndims,ARRAY1_RANK,"H5Tget_array_ndims");
/* Get the array dimensions */
ret = H5Tget_array_dims2(mtid, rdims1);
CHECK(ret, FAIL, "H5Tget_array_dims2");
/* Check the array dimensions */
for(i=0; i<ndims; i++)
if(rdims1[i]!=tdims1[i]) {
TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%d, tdims1[%d]=%d\n",(int)i,(int)rdims1[i],(int)i,(int)tdims1[i]);
continue;
} /* end if */
/* Check the array's base datatype */
tid2=H5Tget_super(mtid);
CHECK(tid2, FAIL, "H5Tget_super");
if((ret=H5Tequal(tid2,H5T_STD_I32LE))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
ret=H5Tclose(tid2);
CHECK(ret, FAIL, "H5Tclose");
ret=H5Tclose(mtid);
CHECK(ret, FAIL, "H5Tclose");
/* Check the 4th field's name */
mname=H5Tget_member_name(tid1,3);
CHECK(mname, NULL, "H5Tget_member_name");
if(mname && HDstrcmp(mname,"d")!=0)
TestErrPrintf("Compound field name doesn't match!, mname=%s\n",mname);
if(mname) free(mname);
/* Check the 4th field's offset */
off=H5Tget_member_offset(tid1,3);
VERIFY(off, 36, "H5Tget_member_offset");
/* Check the 4th field's datatype */
mtid=H5Tget_member_type(tid1,3);
CHECK(mtid, FAIL, "H5Tget_member_type");
if((ret=H5Tequal(mtid,H5T_IEEE_F64LE))<=0)
TestErrPrintf("Compound data type is incorrect!, ret=%d\n",(int)ret);
ret=H5Tclose(mtid);
CHECK(mtid, FAIL, "H5Tclose");
/* Close the datatype */
ret = H5Tclose(tid1);
CHECK_I(ret, "H5Tclose");
/* Close the dataset */
ret = H5Dclose(dataset);
CHECK_I(ret, "H5Dclose");
/* Close the file */
ret = H5Fclose(fid1);
CHECK_I(ret, "H5Fclose");
}
else
printf("***cannot open the pre-created compound datatype test file (%s)\n",testfile);
} /* end test_compat() */
/****************************************************************
**
** test_array(): Main array datatype testing routine.
**
****************************************************************/
void
test_array(void)
{
/* Output message about test being performed */
MESSAGE(5, ("Testing Array Datatypes\n"));
/* These tests use the same file... */
test_array_atomic_1d(); /* Test 1-D array of atomic datatypes */
test_array_atomic_3d(); /* Test 3-D array of atomic datatypes */
test_array_array_atomic(); /* Test 1-D array of 2-D arrays of atomic datatypes */
test_array_compound_atomic(); /* Test 1-D array of compound datatypes (with no array fields) */
test_array_compound_array(); /* Test 1-D array of compound datatypes (with array fields) */
test_array_vlen_atomic(); /* Test 1-D array of atomic VL datatypes */
test_array_vlen_array(); /* Test 1-D array of 1-D array VL datatypes */
test_array_funcs(); /* Test type functions with array types */
test_array_bkg(); /* Read compound datatype with array fields and background fields read */
/* This test uses a custom file */
test_compat(); /* Test compatibility changes for compound datatype fields */
} /* test_array() */
/*-------------------------------------------------------------------------
* Function: cleanup_array
*
* Purpose: Cleanup temporary test files
*
* Return: none
*
* Programmer: Quincey Koziol
* June 8, 1999
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
cleanup_array(void)
{
remove(FILENAME);
}
|