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
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define H5S_PACKAGE /*suppress error about including H5Spkg */
#define H5F_PACKAGE /*suppress error about including H5Fpkg */
/* Interface initialization */
#define H5_INTERFACE_INIT_FUNC H5S_init_interface
/* Pablo information */
/* (Put before include files to avoid problems with inline functions) */
#define PABLO_MASK H5S_mask
#define _H5S_IN_H5S_C
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Fpkg.h" /* File access */
#include "H5FLprivate.h" /* Free lists */
#include "H5Iprivate.h" /* IDs */
#include "H5MMprivate.h" /* Memory management */
#include "H5Oprivate.h" /* Object headers */
#include "H5Spkg.h" /* Dataspaces */
/* Local macro definitions */
#define H5S_ENCODE_VERSION 0
/* Local static function prototypes */
static H5S_t * H5S_create(H5S_class_t type);
static herr_t H5S_set_extent_simple (H5S_t *space, unsigned rank,
const hsize_t *dims, const hsize_t *max);
static htri_t H5S_is_simple(const H5S_t *sdim);
static herr_t H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc);
static H5S_t *H5S_decode(const unsigned char *buf);
#ifdef H5S_DEBUG
/* Names of the selection names, for debugging */
static const char *H5S_sel_names[]={
"none", "point", "hyperslab", "all"
};
#endif /* H5S_DEBUG */
/* The path table, variable length */
static H5S_conv_t **H5S_conv_g = NULL;
static size_t H5S_aconv_g = 0; /*entries allocated*/
static size_t H5S_nconv_g = 0; /*entries used*/
#ifdef H5_HAVE_PARALLEL
/* Global vars whose value can be set from environment variable also */
hbool_t H5S_mpi_opt_types_g = TRUE;
#endif /* H5_HAVE_PARALLEL */
/* Declare a free list to manage the H5S_extent_t struct */
H5FL_DEFINE(H5S_extent_t);
/* Declare a free list to manage the H5S_t struct */
H5FL_DEFINE(H5S_t);
/* Declare a free list to manage the array's of hsize_t's */
H5FL_ARR_DEFINE(hsize_t,H5S_MAX_RANK);
/* Declare a free list to manage the array's of hssize_t's */
H5FL_ARR_DEFINE(hssize_t,H5S_MAX_RANK);
/*--------------------------------------------------------------------------
NAME
H5S_init_interface -- Initialize interface-specific information
USAGE
herr_t H5S_init_interface()
RETURNS
Non-negative on success/Negative on failure
DESCRIPTION
Initializes any interface-specific data or routines.
--------------------------------------------------------------------------*/
static herr_t
H5S_init_interface(void)
{
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5S_init_interface);
/* Initialize the atom group for the file IDs */
if (H5I_register_type(H5I_DATASPACE, H5I_DATASPACEID_HASHSIZE,
H5S_RESERVED_ATOMS, (H5I_free_t)H5S_close)<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize interface");
#ifdef H5_HAVE_PARALLEL
{
/* Allow MPI buf-and-file-type optimizations? */
const char *s = HDgetenv ("HDF5_MPI_OPT_TYPES");
if (s && HDisdigit(*s))
H5S_mpi_opt_types_g = (int)HDstrtol (s, NULL, 0);
}
#endif /* H5_HAVE_PARALLEL */
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*--------------------------------------------------------------------------
NAME
H5S_term_interface
PURPOSE
Terminate various H5S objects
USAGE
void H5S_term_interface()
RETURNS
Non-negative on success/Negative on failure
DESCRIPTION
Release the atom group and any other resources allocated.
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
Can't report errors...
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
int
H5S_term_interface(void)
{
size_t i;
int n=0;
#ifdef H5S_DEBUG
int j, nprints=0;
H5S_conv_t *path=NULL;
char buf[256];
#endif
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_term_interface);
if (H5_interface_initialize_g) {
if ((n=H5I_nmembers(H5I_DATASPACE))) {
H5I_clear_type(H5I_DATASPACE, FALSE);
} else {
#ifdef H5S_DEBUG
/*
* Print statistics about each conversion path.
*/
if (H5DEBUG(S)) {
for (i=0; i<H5S_nconv_g; i++) {
path = H5S_conv_g[i];
for (j=0; j<2; j++) {
if (0==path->stats[j].gath_ncalls &&
0==path->stats[j].scat_ncalls &&
0==path->stats[j].bkg_ncalls &&
0==path->stats[j].read_ncalls &&
0==path->stats[j].write_ncalls) {
continue;
}
if (0==nprints++) {
fprintf(H5DEBUG(S), "H5S: data space conversion "
"statistics:\n");
fprintf(H5DEBUG(S),
" %-16s %10s %10s %8s %8s %8s %10s\n",
"Memory <> File", "Bytes", "Calls",
"User", "System", "Elapsed", "Bandwidth");
fprintf(H5DEBUG(S),
" %-16s %10s %10s %8s %8s %8s %10s\n",
"--------------", "-----", "-----",
"----", "------", "-------", "---------");
}
/* Summary */
sprintf(buf, "%s %c %s",
H5S_sel_names[path->mtype], 0==j?'>':'<', H5S_sel_names[path->ftype]);
fprintf(H5DEBUG(S), " %-16s\n", buf);
/* Gather */
if (path->stats[j].gath_ncalls) {
H5_bandwidth(buf,
(double)(path->stats[j].gath_nbytes),
path->stats[j].gath_timer.etime);
HDfprintf(H5DEBUG(S),
" %16s %10Hu %10Hu %8.2f %8.2f %8.2f "
"%10s\n", "gather",
path->stats[j].gath_nbytes,
path->stats[j].gath_ncalls,
path->stats[j].gath_timer.utime,
path->stats[j].gath_timer.stime,
path->stats[j].gath_timer.etime,
buf);
}
/* Scatter */
if (path->stats[j].scat_ncalls) {
H5_bandwidth(buf,
(double)(path->stats[j].scat_nbytes),
path->stats[j].scat_timer.etime);
HDfprintf(H5DEBUG(S),
" %16s %10Hu %10Hu %8.2f %8.2f %8.2f "
"%10s\n", "scatter",
path->stats[j].scat_nbytes,
path->stats[j].scat_ncalls,
path->stats[j].scat_timer.utime,
path->stats[j].scat_timer.stime,
path->stats[j].scat_timer.etime,
buf);
}
/* Background */
if (path->stats[j].bkg_ncalls) {
H5_bandwidth(buf,
(double)(path->stats[j].bkg_nbytes),
path->stats[j].bkg_timer.etime);
HDfprintf(H5DEBUG(S),
" %16s %10Hu %10Hu %8.2f %8.2f %8.2f "
"%10s\n", "background",
path->stats[j].bkg_nbytes,
path->stats[j].bkg_ncalls,
path->stats[j].bkg_timer.utime,
path->stats[j].bkg_timer.stime,
path->stats[j].bkg_timer.etime,
buf);
}
/* Read */
if (path->stats[j].read_ncalls) {
H5_bandwidth(buf,
(double)(path->stats[j].read_nbytes),
path->stats[j].read_timer.etime);
HDfprintf(H5DEBUG(S),
" %16s %10Hu %10Hu %8.2f %8.2f %8.2f "
"%10s\n", "read",
path->stats[j].read_nbytes,
path->stats[j].read_ncalls,
path->stats[j].read_timer.utime,
path->stats[j].read_timer.stime,
path->stats[j].read_timer.etime,
buf);
}
/* Write */
if (path->stats[j].write_ncalls) {
H5_bandwidth(buf,
(double)(path->stats[j].write_nbytes),
path->stats[j].write_timer.etime);
HDfprintf(H5DEBUG(S),
" %16s %10Hu %10Hu %8.2f %8.2f %8.2f "
"%10s\n", "write",
path->stats[j].write_nbytes,
path->stats[j].write_ncalls,
path->stats[j].write_timer.utime,
path->stats[j].write_timer.stime,
path->stats[j].write_timer.etime,
buf);
}
}
}
}
#endif
/* Free data types */
H5I_dec_type_ref(H5I_DATASPACE);
/* Clear/free conversion table */
for (i=0; i<H5S_nconv_g; i++)
H5MM_xfree(H5S_conv_g[i]);
H5S_conv_g = H5MM_xfree(H5S_conv_g);
H5S_nconv_g = H5S_aconv_g = 0;
/* Shut down interface */
H5_interface_initialize_g = 0;
n = 1; /*H5I*/
}
}
FUNC_LEAVE_NOAPI(n);
}
/*--------------------------------------------------------------------------
NAME
H5S_create
PURPOSE
Create empty, typed dataspace
USAGE
H5S_t *H5S_create(type)
H5S_type_t type; IN: Dataspace type to create
RETURNS
Pointer to dataspace on success, NULL on failure
DESCRIPTION
Creates a new dataspace of a given type. The extent is undefined and the
selection is set to the "all" selection.
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
static H5S_t *
H5S_create(H5S_class_t type)
{
H5S_t *ret_value;
FUNC_ENTER_NOAPI(H5S_create, NULL);
/* Create a new data space */
if((ret_value = H5FL_MALLOC(H5S_t))!=NULL) {
ret_value->extent.type = type;
ret_value->extent.rank = 0;
ret_value->extent.size = ret_value->extent.max = NULL;
switch(type) {
case H5S_SCALAR:
ret_value->extent.nelem = 1;
break;
case H5S_SIMPLE:
case H5S_NULL:
ret_value->extent.nelem = 0;
break;
default:
assert("unknown dataspace (extent) type" && 0);
break;
} /* end switch */
/* Start with "all" selection */
if(H5S_select_all(ret_value,0)<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection");
/* Reset common selection info pointer */
ret_value->select.sel_info.hslab=NULL;
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5S_create() */
/*--------------------------------------------------------------------------
NAME
H5Screate
PURPOSE
Create empty, typed dataspace
USAGE
hid_t H5Screate(type)
H5S_type_t type; IN: Dataspace type to create
RETURNS
Valid dataspace ID on success, negative on failure
DESCRIPTION
Creates a new dataspace of a given type. The extent & selection are
undefined
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
hid_t
H5Screate(H5S_class_t type)
{
H5S_t *new_ds=NULL; /* New dataspace structure */
hid_t ret_value; /* Return value */
FUNC_ENTER_API(H5Screate, FAIL);
H5TRACE1("i","Sc",type);
/* Check args */
if(type<=H5S_NO_CLASS || type> H5S_NULL) /* don't allow complex dataspace yet */
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid dataspace type");
if (NULL==(new_ds=H5S_create(type)))
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCREATE, FAIL, "unable to create dataspace");
/* Atomize */
if ((ret_value=H5I_register (H5I_DATASPACE, new_ds))<0)
HGOTO_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register data space atom");
done:
if (ret_value < 0) {
if(new_ds!=NULL)
H5S_close(new_ds);
} /* end if */
FUNC_LEAVE_API(ret_value);
} /* end H5Screate() */
/*-------------------------------------------------------------------------
* Function: H5S_extent_release
*
* Purpose: Releases all memory associated with a dataspace extent.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Thursday, July 23, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5S_extent_release(H5S_extent_t *extent)
{
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_extent_release, FAIL);
assert(extent);
/* Release extent */
if(extent->type==H5S_SIMPLE) {
if(extent->size)
H5FL_ARR_FREE(hsize_t,extent->size);
if(extent->max)
H5FL_ARR_FREE(hsize_t,extent->max);
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5S_extent_release() */
/*-------------------------------------------------------------------------
* Function: H5S_close
*
* Purpose: Releases all memory associated with a data space.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5S_close(H5S_t *ds)
{
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_close, FAIL);
assert(ds);
/* Release selection (this should come before the extent release) */
H5S_SELECT_RELEASE(ds);
/* Release extent */
H5S_extent_release(&ds->extent);
/* Release the main structure */
H5FL_FREE(H5S_t,ds);
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Sclose
*
* Purpose: Release access to a data space object.
*
* Return: Non-negative on success/Negative on failure
*
* Errors:
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5Sclose(hid_t space_id)
{
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(H5Sclose, FAIL);
H5TRACE1("e","i",space_id);
/* Check args */
if (NULL == H5I_object_verify(space_id,H5I_DATASPACE))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
/* When the reference count reaches zero the resources are freed */
if (H5I_dec_ref(space_id) < 0)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "problem freeing id");
done:
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Scopy
*
* Purpose: Copies a dataspace.
*
* Return: Success: ID of the new dataspace
*
* Failure: Negative
*
* Programmer: Robb Matzke
* Friday, January 30, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
hid_t
H5Scopy(hid_t space_id)
{
H5S_t *src = NULL;
H5S_t *dst = NULL;
hid_t ret_value;
FUNC_ENTER_API(H5Scopy, FAIL);
H5TRACE1("i","i",space_id);
/* Check args */
if (NULL==(src=H5I_object_verify(space_id, H5I_DATASPACE)))
HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
/* Copy */
if (NULL==(dst=H5S_copy (src, FALSE)))
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to copy data space");
/* Atomize */
if ((ret_value=H5I_register (H5I_DATASPACE, dst))<0)
HGOTO_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register data space atom");
done:
if(ret_value<0) {
if(dst!=NULL)
H5S_close(dst);
} /* end if */
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Sextent_copy
*
* Purpose: Copies a dataspace extent.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Thursday, July 23, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5Sextent_copy(hid_t dst_id,hid_t src_id)
{
H5S_t *src = NULL;
H5S_t *dst = NULL;
hid_t ret_value = SUCCEED;
FUNC_ENTER_API(H5Sextent_copy, FAIL);
H5TRACE2("e","ii",dst_id,src_id);
/* Check args */
if (NULL==(src=H5I_object_verify(src_id, H5I_DATASPACE)))
HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
if (NULL==(dst=H5I_object_verify(dst_id, H5I_DATASPACE)))
HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
/* Copy */
if (H5S_extent_copy(&(dst->extent),&(src->extent))<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy extent");
done:
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_extent_copy
*
* Purpose: Copies a dataspace extent
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Wednesday, June 3, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5S_extent_copy(H5S_extent_t *dst, const H5S_extent_t *src)
{
unsigned u;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_extent_copy, FAIL);
/* Copy the regular fields */
dst->type=src->type;
dst->nelem=src->nelem;
dst->rank=src->rank;
switch (src->type) {
case H5S_NULL:
case H5S_SCALAR:
dst->size=NULL;
dst->max=NULL;
break;
case H5S_SIMPLE:
if (src->size) {
dst->size = H5FL_ARR_MALLOC(hsize_t,src->rank);
for (u = 0; u < src->rank; u++)
dst->size[u] = src->size[u];
}
else
dst->size=NULL;
if (src->max) {
dst->max = H5FL_ARR_MALLOC(hsize_t,src->rank);
for (u = 0; u < src->rank; u++)
dst->max[u] = src->max[u];
}
else
dst->max=NULL;
break;
case H5S_COMPLEX:
/*void */
break;
default:
assert("unknown data space type" && 0);
break;
}
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_copy
*
* Purpose: Copies a data space, by copying the extent and selection through
* H5S_extent_copy and H5S_select_copy. If the SHARE_SELECTION flag
* is set, then the selection can be shared between the source and
* destination dataspaces. (This should only occur in situations
* where the destination dataspace will immediately change to a new
* selection)
*
* Return: Success: A pointer to a new copy of SRC
*
* Failure: NULL
*
* Programmer: Robb Matzke
* Thursday, December 4, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
H5S_t *
H5S_copy(const H5S_t *src, hbool_t share_selection)
{
H5S_t *dst = NULL;
H5S_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5S_copy, NULL);
if (NULL==(dst = H5FL_MALLOC(H5S_t)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
/* Copy the source dataspace's extent */
if (H5S_extent_copy(&(dst->extent),&(src->extent))<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy extent");
/* Copy the source dataspace's selection */
if (H5S_select_copy(dst,src,share_selection)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy select");
/* Set the return value */
ret_value=dst;
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_get_simple_extent_npoints
*
* Purpose: Determines how many data points a dataset extent has.
*
* Return: Success: Number of data points in the dataset extent.
*
* Failure: negative
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Note: This routine participates in the "Inlining C function pointers"
* pattern, don't call it directly, use the appropriate macro
* defined in H5Sprivate.h.
*
* Modifications:
* Changed Name - QAK 7/7/98
*
*-------------------------------------------------------------------------
*/
hssize_t
H5S_get_simple_extent_npoints(const H5S_t *ds)
{
hssize_t ret_value;
FUNC_ENTER_NOAPI(H5S_get_simple_extent_npoints, -1);
/* check args */
assert(ds);
/* Get the number of elements in extent */
ret_value = ds->extent.nelem;
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Sget_simple_extent_npoints
*
* Purpose: Determines how many data points a dataset extent has.
*
* Return: Success: Number of data points in the dataset.
*
* Failure: negative
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
* Changed Name - QAK 7/7/98
*
*-------------------------------------------------------------------------
*/
hssize_t
H5Sget_simple_extent_npoints(hid_t space_id)
{
H5S_t *ds = NULL;
hssize_t ret_value;
FUNC_ENTER_API(H5Sget_simple_extent_npoints, FAIL);
H5TRACE1("Hs","i",space_id);
/* Check args */
if (NULL == (ds = H5I_object_verify(space_id, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
ret_value = H5S_GET_EXTENT_NPOINTS(ds);
done:
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_get_npoints_max
*
* Purpose: Determines the maximum number of data points a data space may
* have. If the `max' array is null then the maximum number of
* data points is the same as the current number of data points
* without regard to the hyperslab. If any element of the `max'
* array is zero then the maximum possible size is returned.
*
* Return: Success: Maximum number of data points the data space
* may have.
*
* Failure: 0
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
hsize_t
H5S_get_npoints_max(const H5S_t *ds)
{
hsize_t ret_value;
unsigned u;
FUNC_ENTER_NOAPI(H5S_get_npoints_max, 0);
/* check args */
assert(ds);
switch (H5S_GET_EXTENT_TYPE(ds)) {
case H5S_NULL:
ret_value = 0;
break;
case H5S_SCALAR:
ret_value = 1;
break;
case H5S_SIMPLE:
if (ds->extent.max) {
for (ret_value=1, u=0; u<ds->extent.rank; u++) {
if (H5S_UNLIMITED==ds->extent.max[u]) {
ret_value = HSIZET_MAX;
break;
}
else
ret_value *= ds->extent.max[u];
}
}
else {
for (ret_value=1, u=0; u<ds->extent.rank; u++)
ret_value *= ds->extent.size[u];
}
break;
case H5S_COMPLEX:
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0, "complex data spaces are not supported yet");
default:
assert("unknown data space class" && 0);
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0, "internal error (unknown data space class)");
}
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Sget_simple_extent_ndims
*
* Purpose: Determines the dimensionality of a data space.
*
* Return: Success: The number of dimensions in a data space.
*
* Failure: Negative
*
* Programmer: Robb Matzke
* Thursday, December 11, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
H5Sget_simple_extent_ndims(hid_t space_id)
{
H5S_t *ds = NULL;
int ret_value;
FUNC_ENTER_API(H5Sget_simple_extent_ndims, FAIL);
H5TRACE1("Is","i",space_id);
/* Check args */
if (NULL == (ds = H5I_object_verify(space_id, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
ret_value = H5S_GET_EXTENT_NDIMS(ds);
done:
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_get_simple_extent_ndims
*
* Purpose: Returns the number of dimensions in a data space.
*
* Return: Success: Non-negative number of dimensions. Zero
* implies a scalar.
*
* Failure: Negative
*
* Programmer: Robb Matzke
* Thursday, December 11, 1997
*
* Note: This routine participates in the "Inlining C function pointers"
* pattern, don't call it directly, use the appropriate macro
* defined in H5Sprivate.h.
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
H5S_get_simple_extent_ndims(const H5S_t *ds)
{
int ret_value;
FUNC_ENTER_NOAPI(H5S_get_simple_extent_ndims, FAIL);
/* check args */
assert(ds);
switch (H5S_GET_EXTENT_TYPE(ds)) {
case H5S_NULL:
case H5S_SCALAR:
case H5S_SIMPLE:
ret_value = ds->extent.rank;
break;
case H5S_COMPLEX:
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "complex data spaces are not supported yet");
default:
assert("unknown data space class" && 0);
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "internal error (unknown data space class)");
}
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Sget_simple_extent_dims
*
* Purpose: Returns the size and maximum sizes in each dimension of
* a data space DS through the DIMS and MAXDIMS arguments.
*
* Return: Success: Number of dimensions, the same value as
* returned by H5Sget_simple_extent_ndims().
*
* Failure: Negative
*
* Programmer: Robb Matzke
* Thursday, December 11, 1997
*
* Modifications:
* June 18, 1998 Albert Cheng
* Added maxdims argument. Removed dims argument check
* since it can still return ndims even if both dims and
* maxdims are NULLs.
*
*-------------------------------------------------------------------------
*/
int
H5Sget_simple_extent_dims(hid_t space_id, hsize_t dims[]/*out*/,
hsize_t maxdims[]/*out*/)
{
H5S_t *ds = NULL;
int ret_value;
FUNC_ENTER_API(H5Sget_simple_extent_dims, FAIL);
H5TRACE3("Is","ixx",space_id,dims,maxdims);
/* Check args */
if (NULL == (ds = H5I_object_verify(space_id, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace");
ret_value = H5S_get_simple_extent_dims(ds, dims, maxdims);
done:
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_get_simple_extent_dims
*
* Purpose: Returns the size in each dimension of a data space. This
* function may not be meaningful for all types of data spaces.
*
* Return: Success: Number of dimensions. Zero implies scalar.
*
* Failure: Negative
*
* Programmer: Robb Matzke
* Thursday, December 11, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
H5S_get_simple_extent_dims(const H5S_t *ds, hsize_t dims[], hsize_t max_dims[])
{
int ret_value;
int i;
FUNC_ENTER_NOAPI(H5S_get_simple_extent_dims, FAIL);
/* check args */
assert(ds);
switch (H5S_GET_EXTENT_TYPE(ds)) {
case H5S_NULL:
case H5S_SCALAR:
ret_value = 0;
break;
case H5S_SIMPLE:
ret_value = ds->extent.rank;
for (i=0; i<ret_value; i++) {
if (dims)
dims[i] = ds->extent.size[i];
if (max_dims) {
if (ds->extent.max)
max_dims[i] = ds->extent.max[i];
else
max_dims[i] = ds->extent.size[i];
}
}
break;
case H5S_COMPLEX:
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "complex data spaces are not supported yet");
default:
assert("unknown data space class" && 0);
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "internal error (unknown data space class)");
}
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_modify
*
* Purpose: Updates a data space by writing a message to an object
* header.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5S_modify(H5G_entry_t *ent, const H5S_t *ds, hbool_t update_time, hid_t dxpl_id)
{
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_modify, FAIL);
assert(ent);
assert(ds);
switch (H5S_GET_EXTENT_TYPE(ds)) {
case H5S_NULL:
case H5S_SCALAR:
case H5S_SIMPLE:
if (H5O_modify(ent, H5O_SDSPACE_ID, 0, 0, update_time, &(ds->extent), dxpl_id)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "can't update simple data space message");
break;
case H5S_COMPLEX:
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "complex data spaces are not implemented yet");
default:
assert("unknown data space class" && 0);
break;
}
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_append
*
* Purpose: Updates a data space by adding a message to an object
* header.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Tuesday, December 31, 2002
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5S_append(H5F_t *f, hid_t dxpl_id, struct H5O_t *oh, const H5S_t *ds)
{
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_append, FAIL);
assert(f);
assert(oh);
assert(ds);
switch (H5S_GET_EXTENT_TYPE(ds)) {
case H5S_NULL:
case H5S_SCALAR:
case H5S_SIMPLE:
if (H5O_append(f, dxpl_id, oh, H5O_SDSPACE_ID, 0, &(ds->extent))<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "can't update simple data space message");
break;
case H5S_COMPLEX:
HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "complex data spaces are not implemented yet");
default:
assert("unknown data space class" && 0);
break;
}
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5S_append() */
/*-------------------------------------------------------------------------
* Function: H5S_read
*
* Purpose: Reads the data space from an object header.
*
* Return: Success: Pointer to a new data space.
*
* Failure: NULL
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
* Robb Matzke, 9 Jun 1998
* Removed the unused file argument since the file is now part of the
* ENT argument.
*-------------------------------------------------------------------------
*/
H5S_t *
H5S_read(H5G_entry_t *ent, hid_t dxpl_id)
{
H5S_t *ds = NULL; /* Dataspace to return */
H5S_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5S_read, NULL);
/* check args */
assert(ent);
if (NULL==(ds = H5FL_CALLOC(H5S_t)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
if (H5O_read(ent, H5O_SDSPACE_ID, 0, &(ds->extent), dxpl_id) == NULL)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, NULL, "unable to load dataspace info from dataset header");
/* Default to entire dataspace being selected */
if(H5S_select_all(ds,0)<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection");
/* Set the value for successful return */
ret_value=ds;
done:
if(ret_value==NULL) {
if(ds!=NULL)
H5FL_FREE(H5S_t,ds);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value);
}
/*--------------------------------------------------------------------------
NAME
H5S_is_simple
PURPOSE
Check if a dataspace is simple (internal)
USAGE
htri_t H5S_is_simple(sdim)
H5S_t *sdim; IN: Pointer to dataspace object to query
RETURNS
TRUE/FALSE/FAIL
DESCRIPTION
This function determines the if a dataspace is "simple". ie. if it
has orthogonal, evenly spaced dimensions.
--------------------------------------------------------------------------*/
static htri_t
H5S_is_simple(const H5S_t *sdim)
{
htri_t ret_value;
FUNC_ENTER_NOAPI(H5S_is_simple, FAIL);
/* Check args and all the boring stuff. */
assert(sdim);
/* H5S_NULL shouldn't be simple dataspace */
ret_value = (H5S_GET_EXTENT_TYPE(sdim) == H5S_SIMPLE ||
H5S_GET_EXTENT_TYPE(sdim) == H5S_SCALAR) ? TRUE : FALSE;
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*--------------------------------------------------------------------------
NAME
H5Sis_simple
PURPOSE
Check if a dataspace is simple
USAGE
htri_t H5Sis_simple(space_id)
hid_t space_id; IN: ID of dataspace object to query
RETURNS
TRUE/FALSE/FAIL
DESCRIPTION
This function determines the if a dataspace is "simple". ie. if it
has orthogonal, evenly spaced dimensions.
--------------------------------------------------------------------------*/
htri_t
H5Sis_simple(hid_t space_id)
{
H5S_t *space = NULL; /* dataspace to modify */
htri_t ret_value;
FUNC_ENTER_API(H5Sis_simple, FAIL);
H5TRACE1("t","i",space_id);
/* Check args and all the boring stuff. */
if ((space = H5I_object_verify(space_id,H5I_DATASPACE)) == NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "not a data space");
ret_value = H5S_is_simple(space);
done:
FUNC_LEAVE_API(ret_value);
}
/*--------------------------------------------------------------------------
NAME
H5Sset_extent_simple
PURPOSE
Sets the size of a simple dataspace
USAGE
herr_t H5Sset_extent_simple(space_id, rank, dims, max)
hid_t space_id; IN: Dataspace object to query
int rank; IN: # of dimensions for the dataspace
const size_t *dims; IN: Size of each dimension for the dataspace
const size_t *max; IN: Maximum size of each dimension for the
dataspace
RETURNS
Non-negative on success/Negative on failure
DESCRIPTION
This function sets the number and size of each dimension in the
dataspace. Setting RANK to a value of zero converts the dataspace to a
scalar dataspace. Dimensions are specified from slowest to fastest
changing in the DIMS array (i.e. 'C' order). Setting the size of a
dimension in the MAX array to zero indicates that the dimension is of
unlimited size and should be allowed to expand. If MAX is NULL, the
dimensions in the DIMS array are used as the maximum dimensions.
Currently, only the first dimension in the array (the slowest) may be
unlimited in size.
MODIFICATION
A null dataspace cannot be created from simple space with this function.
--------------------------------------------------------------------------*/
herr_t
H5Sset_extent_simple(hid_t space_id, int rank, const hsize_t dims[/*rank*/],
const hsize_t max[/*rank*/])
{
H5S_t *space = NULL; /* dataspace to modify */
int u; /* local counting variable */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(H5Sset_extent_simple, FAIL);
H5TRACE4("e","iIs*[a1]h*[a1]h",space_id,rank,dims,max);
/* Check args */
if ((space = H5I_object_verify(space_id,H5I_DATASPACE)) == NULL)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "not a data space");
if (rank > 0 && dims == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no dimensions specified");
if (rank<0 || rank>H5S_MAX_RANK)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid rank");
if (dims) {
for (u=0; u<rank; u++) {
if (((max!=NULL && max[u]!=H5S_UNLIMITED) || max==NULL) && dims[u]==0)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid dimension size");
}
}
if (max!=NULL) {
if(dims==NULL)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "maximum dimension specified, but no current dimensions specified");
for (u=0; u<rank; u++) {
if (max[u]!=H5S_UNLIMITED && max[u]<dims[u])
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid maximum dimension size");
}
}
/* Do it */
if (H5S_set_extent_simple(space, (unsigned)rank, dims, max)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to set simple extent");
done:
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_set_extent_simple
*
* Purpose: This is where the real work happens for
* H5Sset_extent_simple().
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke (copied from H5Sset_extent_simple)
* Wednesday, July 8, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5S_set_extent_simple (H5S_t *space, unsigned rank, const hsize_t *dims,
const hsize_t *max)
{
unsigned u; /* Local index variable */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_set_extent_simple, FAIL);
/* Check args */
assert(rank<=H5S_MAX_RANK);
assert(0==rank || dims);
/* shift out of the previous state to a "simple" dataspace. */
if(H5S_extent_release(&space->extent)<0)
HGOTO_ERROR (H5E_RESOURCE, H5E_CANTFREE, FAIL, "failed to release previous dataspace extent");
if (rank == 0) { /* scalar variable */
space->extent.type = H5S_SCALAR;
space->extent.nelem = 1;
space->extent.rank = 0; /* set to scalar rank */
} else {
hsize_t nelem; /* Number of elements in extent */
space->extent.type = H5S_SIMPLE;
/* Set the rank and allocate space for the dims */
space->extent.rank = rank;
space->extent.size = H5FL_ARR_MALLOC(hsize_t,rank);
/* Copy the dimensions & compute the number of elements in the extent */
for(u=0, nelem=1; u<space->extent.rank; u++) {
space->extent.size[u]=dims[u];
nelem*=dims[u];
} /* end for */
space->extent.nelem = nelem;
/* Copy the maximum dimensions if specified */
if(max!=NULL) {
space->extent.max = H5FL_ARR_MALLOC(hsize_t,rank);
HDmemcpy(space->extent.max, max, sizeof(hsize_t) * rank);
} /* end if */
else {
space->extent.max = NULL;
}
}
/* Selection related cleanup */
/* Set offset to zeros */
for(u=0; u<space->extent.rank; u++)
space->select.offset[u]=0;
/* If the selection is 'all', update the number of elements selected */
if(H5S_GET_SELECT_TYPE(space)==H5S_SEL_ALL)
if(H5S_select_all(space, FALSE)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection");
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_find
*
* Purpose: Given two data spaces (MEM_SPACE and FILE_SPACE) this
* function returns a pointer to the conversion path information,
* creating a new conversion path entry if necessary.
*
* Return: Success: Ptr to a conversion path entry
*
* Failure: NULL
*
* Programmer: Robb Matzke
* Wednesday, January 21, 1998
*
* Modifications:
*
* Quincey Koziol
* Instead of returning a point into the data space conversion table we
* copy all the information into a user-supplied CONV buffer and return
* non-negative on success or negative on failure.
*
* Robb Matzke, 11 Aug 1998
* Returns a pointer into the conversion path table. A path entry
* contains pointers to the memory and file half of the conversion (the
* pointers registered in the H5S_fconv_g[] and H5S_mconv_g[] tables)
* along with other data whose scope is the conversion path (like path
* statistics).
*
*-------------------------------------------------------------------------
*/
H5S_conv_t *
H5S_find (const H5F_t
#ifndef H5_HAVE_PARALLEL
UNUSED
#endif/* H5_HAVE_PARALLEL*/
*file,
const H5S_t *mem_space, const H5S_t *file_space, unsigned
#ifndef H5_HAVE_PARALLEL
UNUSED
#endif /* H5_HAVE_PARALLEL */
flags, hbool_t
#ifndef H5_HAVE_PARALLEL
UNUSED
#endif /* H5_HAVE_PARALLEL */
*use_par_opt_io,
#ifndef H5_HAVE_PARALLEL
UNUSED
#endif
const H5O_layout_t *layout
)
{
H5S_conv_t *path=NULL; /* Space conversion path */
#ifdef H5_HAVE_PARALLEL
htri_t opt; /* Flag whether a selection is optimizable */
#endif /* H5_HAVE_PARALLEL */
size_t i; /* Index variable */
H5S_conv_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5S_find, NULL);
/* Check args */
assert (mem_space && (H5S_SIMPLE==H5S_GET_EXTENT_TYPE(mem_space) ||
H5S_NULL==H5S_GET_EXTENT_TYPE(mem_space) ||
H5S_SCALAR==H5S_GET_EXTENT_TYPE(mem_space)));
assert (file_space && (H5S_SIMPLE==H5S_GET_EXTENT_TYPE(file_space) ||
H5S_NULL==H5S_GET_EXTENT_TYPE(file_space) ||
H5S_SCALAR==H5S_GET_EXTENT_TYPE(file_space)));
/*
* Is this path already present in the data space conversion path table?
* If so then return a pointer to that entry.
*/
for (i=0; i<H5S_nconv_g; i++) {
if (H5S_conv_g[i]->ftype==H5S_GET_SELECT_TYPE(file_space) &&
H5S_conv_g[i]->mtype==H5S_GET_SELECT_TYPE(mem_space)) {
#ifdef H5_HAVE_PARALLEL
/*
* Check if we can set direct MPI-IO read/write functions
*/
opt=H5S_mpio_opt_possible(file,mem_space,file_space,flags,layout);
if(opt==FAIL)
HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, NULL, "invalid check for direct IO dataspace ");
/* Check if we can use the optimized parallel I/O routines */
if(opt==TRUE) {
/* Set the pointers to the MPI-specific routines */
H5S_conv_g[i]->read = H5D_mpio_spaces_read;
H5S_conv_g[i]->write = H5D_mpio_spaces_write;
/* Indicate that the I/O will be parallel */
*use_par_opt_io=TRUE;
} /* end if */
else {
/* Indicate that the I/O will _NOT_ be parallel */
*use_par_opt_io=FALSE;
#endif /* H5_HAVE_PARALLEL */
H5S_conv_g[i]->read = H5S_select_read;
H5S_conv_g[i]->write = H5S_select_write;
#ifdef H5_HAVE_PARALLEL
} /* end else */
#endif /* H5_HAVE_PARALLEL */
HGOTO_DONE(H5S_conv_g[i]);
}
}
/*
* The path wasn't found. Create a new path.
*/
if (NULL==(path = H5MM_calloc(sizeof(*path))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for data space conversion path");
/* Initialize file & memory conversion functions */
path->ftype = H5S_GET_SELECT_TYPE(file_space);
path->mtype = H5S_GET_SELECT_TYPE(mem_space);
#ifdef H5_HAVE_PARALLEL
/*
* Check if we can set direct MPI-IO read/write functions
*/
opt=H5S_mpio_opt_possible(file,mem_space,file_space,flags,layout);
if(opt==FAIL)
HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, NULL, "invalid check for direct IO dataspace ");
/* Check if we can use the optimized parallel I/O routines */
if(opt==TRUE) {
/* Set the pointers to the MPI-specific routines */
path->read = H5D_mpio_spaces_read;
path->write = H5D_mpio_spaces_write;
/* Indicate that the I/O will be parallel */
*use_par_opt_io=TRUE;
} /* end if */
else {
/* Indicate that the I/O will _NOT_ be parallel */
*use_par_opt_io=FALSE;
#endif /* H5_HAVE_PARALLEL */
path->read = H5S_select_read;
path->write = H5S_select_write;
#ifdef H5_HAVE_PARALLEL
} /* end else */
#endif /* H5_HAVE_PARALLEL */
/*
* Add the new path to the table.
*/
if (H5S_nconv_g>=H5S_aconv_g) {
size_t n = MAX(10, 2*H5S_aconv_g);
H5S_conv_t **p = H5MM_realloc(H5S_conv_g, n*sizeof(H5S_conv_g[0]));
if (NULL==p)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for data space conversion path table");
H5S_aconv_g = n;
H5S_conv_g = p;
} /* end if */
H5S_conv_g[H5S_nconv_g++] = path;
/* Set the return value */
ret_value=path;
done:
if(ret_value==NULL) {
if(path!=NULL)
H5MM_xfree(path);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_extend
*
* Purpose: Extend the dimensions of a data space.
*
* Return: Success: Number of dimensions whose size increased.
*
* Failure: Negative
*
* Programmer: Robb Matzke
* Friday, January 30, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
H5S_extend (H5S_t *space, const hsize_t *size)
{
int ret_value=0;
unsigned u;
FUNC_ENTER_NOAPI(H5S_extend, FAIL);
/* Check args */
assert (space && H5S_SIMPLE==H5S_GET_EXTENT_TYPE(space));
assert (size);
/* Check through all the dimensions to see if modifying the dataspace is allowed */
for (u=0; u<space->extent.rank; u++) {
if (space->extent.size[u]<size[u]) {
if (space->extent.max &&
H5S_UNLIMITED!=space->extent.max[u] &&
space->extent.max[u]<size[u])
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "dimension cannot be increased");
ret_value++;
}
}
/* Update */
if (ret_value) {
hsize_t nelem; /* Number of elements in extent */
/* Change the dataspace size & re-compute the number of elements in the extent */
for (u=0, nelem=1; u<space->extent.rank; u++) {
if (space->extent.size[u]<size[u])
space->extent.size[u] = size[u];
nelem*=space->extent.size[u];
}
space->extent.nelem = nelem;
/* If the selection is 'all', update the number of elements selected */
if(H5S_GET_SELECT_TYPE(space)==H5S_SEL_ALL)
if(H5S_select_all(space, FALSE)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection");
}
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Screate_simple
*
* Purpose: Creates a new simple data space object and opens it for
* access. The DIMS argument is the size of the simple dataset
* and the MAXDIMS argument is the upper limit on the size of
* the dataset. MAXDIMS may be the null pointer in which case
* the upper limit is the same as DIMS. If an element of
* MAXDIMS is H5S_UNLIMITED then the corresponding dimension is
* unlimited, otherwise no element of MAXDIMS should be smaller
* than the corresponding element of DIMS.
*
* Return: Success: The ID for the new simple data space object.
*
* Failure: Negative
*
* Errors:
*
* Programmer: Quincey Koziol
* Tuesday, January 27, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
hid_t
H5Screate_simple(int rank, const hsize_t dims[/*rank*/],
const hsize_t maxdims[/*rank*/])
{
hid_t ret_value;
H5S_t *space = NULL;
int i;
FUNC_ENTER_API(H5Screate_simple, FAIL);
H5TRACE3("i","Is*[a0]h*[a0]h",rank,dims,maxdims);
/* Check arguments */
if (rank<0)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "dimensionality cannot be negative");
if (rank>H5S_MAX_RANK)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dimensionality is too large");
if (!dims && dims!=0)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "no dimensions specified");
/* Check whether the current dimensions are valid */
for (i=0; i<rank; i++) {
if (maxdims) {
if (H5S_UNLIMITED!=maxdims[i] && maxdims[i]<dims[i])
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "maxdims is smaller than dims");
if (H5S_UNLIMITED!=maxdims[i] && dims[i]==0)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "zero sized dimension for non-unlimited dimension");
}
else {
if (dims[i]==0)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "zero sized dimension for non-unlimited dimension");
}
}
/* Create the space and set the extent */
if(NULL==(space=H5S_create_simple((unsigned)rank,dims,maxdims)))
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create simple dataspace");
/* Atomize */
if ((ret_value=H5I_register (H5I_DATASPACE, space))<0)
HGOTO_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataspace ID");
done:
if (ret_value<0) {
if (space!=NULL)
H5S_close(space);
} /* end if */
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_create_simple
*
* Purpose: Internal function to create simple dataspace
*
* Return: Success: The ID for the new simple data space object.
* Failure: Negative
*
* Errors:
*
* Programmer: Quincey Koziol
* Thursday, April 3, 2003
*
* Modifications:
* Extracted from H5Screate_simple
* Quincey Koziol, Thursday, April 3, 2003
*
*-------------------------------------------------------------------------
*/
H5S_t *
H5S_create_simple(unsigned rank, const hsize_t dims[/*rank*/],
const hsize_t maxdims[/*rank*/])
{
H5S_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5S_create_simple, NULL);
/* Check arguments */
assert(rank <=H5S_MAX_RANK);
/* Create the space and set the extent */
if(NULL==(ret_value=H5S_create(H5S_SIMPLE)))
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCREATE, NULL, "can't create simple dataspace");
if(H5S_set_extent_simple(ret_value,rank,dims,maxdims)<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTINIT, NULL, "can't set dimensions");
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5S_create_simple() */
/*-------------------------------------------------------------------------
* Function: H5Sencode
*
* Purpose: Given a dataspace ID, converts the object description
* (including selection) into binary in a buffer.
*
* Return: Success: non-negative
*
* Failure: negative
*
* Programmer: Raymond Lu
* slu@ncsa.uiuc.edu
* July 14, 2004
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5Sencode(hid_t obj_id, void *buf, size_t *nalloc)
{
H5S_t *dspace;
herr_t ret_value=SUCCEED;
FUNC_ENTER_API (H5Sencode, FAIL);
H5TRACE3("e","ix*z",obj_id,buf,nalloc);
/* Check argument and retrieve object */
if (NULL==(dspace=H5I_object_verify(obj_id, H5I_DATASPACE)))
HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
if(H5S_encode(dspace, buf, nalloc)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode datatype");
done:
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_encode
*
* Purpose: Private function for H5Sencode. Converts an object
* description for data space and its selection into binary
* in a buffer.
*
* Return: Success: non-negative
*
* Failure: negative
*
* Programmer: Raymond Lu
* slu@ncsa.uiuc.edu
* July 14, 2004
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc)
{
size_t extent_size;
hssize_t select_size;
H5S_class_t space_type;
H5F_t f; /* fake file structure*/
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5S_encode, FAIL);
/* Fake file structure, used only for header message operation */
f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t));
f.shared->sizeof_size = H5F_CRT_OBJ_BYTE_NUM_DEF;
/* Find out the size of buffer needed for extent */
if((extent_size=H5O_raw_size(H5O_SDSPACE_ID, &f, obj))==0)
HGOTO_ERROR(H5E_DATASPACE, H5E_BADSIZE, FAIL, "can't find dataspace size");
/* Get space type */
space_type = H5S_GET_EXTENT_TYPE(obj);
if((select_size=H5S_SELECT_SERIAL_SIZE(obj))<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_BADSIZE, FAIL, "can't find dataspace selection size");
/* Verify the size of buffer. If it's not big enough, simply return the
* right size without filling the buffer. */
if(!buf || *nalloc<(extent_size+select_size+1+1+1+4)) {
*nalloc = extent_size+select_size+1+1+1+4;
HGOTO_DONE(ret_value);
}
/* Encode the type of the information */
*buf++ = H5O_SDSPACE_ID;
/* Encode the version of the dataspace information */
*buf++ = H5S_ENCODE_VERSION;
/* Encode the "size of size" information */
*buf++ = f.shared->sizeof_size;
/* Encode size of extent information. Pointer is actually moved in this macro. */
UINT32ENCODE(buf, extent_size);
/* Encode the extent part of dataspace */
if(H5O_encode(&f, buf, obj, H5O_SDSPACE_ID)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode extent space");
buf +=extent_size;
/* Encode the selection part of dataspace. */
if(H5S_SELECT_SERIALIZE(obj, buf) <0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode select space");
done:
if(f.shared)
H5MM_free(f.shared);
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Sdecode
*
* Purpose: Decode a binary object description of data space and
* return a new object handle.
*
* Return: Success: dataspace ID(non-negative)
*
* Failure: negative
*
* Programmer: Raymond Lu
* slu@ncsa.uiuc.edu
* July 14, 2004
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
hid_t
H5Sdecode(const void *buf)
{
H5S_t *ds;
hid_t ret_value;
FUNC_ENTER_API (H5Sdecode, FAIL);
H5TRACE1("i","x",buf);
if (buf==NULL)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "empty buffer")
if((ds = H5S_decode(buf))==NULL)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, FAIL, "can't decode object");
/* Register the type and return the ID */
if ((ret_value=H5I_register (H5I_DATASPACE, ds))<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTREGISTER, FAIL, "unable to register dataspace");
done:
FUNC_LEAVE_API(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_decode
*
* Purpose: Private function for H5Sdecode. Reconstructs a binary
* description of dataspace and returns a new object handle.
*
* Return: Success: dataspace ID(non-negative)
*
* Failure: negative
*
* Programmer: Raymond Lu
* slu@ncsa.uiuc.edu
* July 14, 2004
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static H5S_t*
H5S_decode(const unsigned char *buf)
{
H5S_t *ds;
H5S_extent_t *extent;
size_t extent_size; /* size of the extent message*/
H5F_t f; /* fake file structure*/
H5S_t *ret_value;
FUNC_ENTER_NOAPI(H5S_decode, NULL);
/* Initialize this before anything goes bad... */
f.shared=NULL;
/* Decode the type of the information */
if(*buf++ != H5O_SDSPACE_ID)
HGOTO_ERROR(H5E_DATASPACE, H5E_BADMESG, NULL, "not an encoded dataspace");
/* Decode the version of the dataspace information */
if(*buf++ != H5S_ENCODE_VERSION)
HGOTO_ERROR(H5E_DATASPACE, H5E_VERSION, NULL, "unknown version of encoded dataspace");
/* Fake file structure, used only for header message operation */
f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t));
/* Decode the "size of size" information */
f.shared->sizeof_size = *buf++;
/* Decode size of extent information */
UINT32DECODE(buf, extent_size);
/* Decode the extent part of dataspace */
if((extent = H5O_decode(&f, buf, H5O_SDSPACE_ID))==NULL)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode object");
buf += extent_size;
/* Copy the extent into dataspace structure */
if((ds = H5FL_CALLOC(H5S_t))==NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for data space conversion path table");
if(H5O_copy(H5O_SDSPACE_ID, extent, &(ds->extent))==NULL)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy object");
if(H5S_extent_release(extent)<0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTDELETE, NULL, "can't release previous dataspace");
H5FL_FREE(H5S_extent_t,extent);
/* Initialize to "all" selection. Deserialization relies on valid existing selection. */
if(H5S_select_all(ds,0)<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection");
/* Decode the select part of dataspace. I believe this part always exists. */
if(H5S_SELECT_DESERIALIZE(ds, buf)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode space selection");
/* Set return value */
ret_value=ds;
done:
H5MM_xfree(f.shared);
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_get_simple_extent_type
*
* Purpose: Internal function for retrieving the type of extent for a dataspace object
*
* Return: Success: The class of the dataspace object
*
* Failure: N5S_NO_CLASS
*
* Errors:
*
* Programmer: Quincey Koziol
* Thursday, September 28, 2000
*
* Note: This routine participates in the "Inlining C function pointers"
* pattern, don't call it directly, use the appropriate macro
* defined in H5Sprivate.h.
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
H5S_class_t
H5S_get_simple_extent_type(const H5S_t *space)
{
H5S_class_t ret_value;
FUNC_ENTER_NOAPI(H5S_get_simple_extent_type, H5S_NO_CLASS);
assert(space);
ret_value=H5S_GET_EXTENT_TYPE(space);
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5Sget_simple_extent_type
*
* Purpose: Retrieves the type of extent for a dataspace object
*
* Return: Success: The class of the dataspace object
*
* Failure: N5S_NO_CLASS
*
* Errors:
*
* Programmer: Quincey Koziol
* Thursday, July 23, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
H5S_class_t
H5Sget_simple_extent_type(hid_t sid)
{
H5S_class_t ret_value;
H5S_t *space;
FUNC_ENTER_API(H5Sget_simple_extent_type, H5S_NO_CLASS);
H5TRACE1("Sc","i",sid);
/* Check arguments */
if (NULL == (space = H5I_object_verify(sid, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5S_NO_CLASS, "not a dataspace");
ret_value=H5S_GET_EXTENT_TYPE(space);
done:
FUNC_LEAVE_API(ret_value);
}
/*--------------------------------------------------------------------------
NAME
H5Sset_extent_none
PURPOSE
Resets the extent of a dataspace back to "none"
USAGE
herr_t H5Sset_extent_none(space_id)
hid_t space_id; IN: Dataspace object to reset
RETURNS
Non-negative on success/Negative on failure
DESCRIPTION
This function resets the type of a dataspace back to "none" with no
extent information stored for the dataspace.
--------------------------------------------------------------------------*/
herr_t
H5Sset_extent_none(hid_t space_id)
{
H5S_t *space = NULL; /* dataspace to modify */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(H5Sset_extent_none, FAIL);
H5TRACE1("e","i",space_id);
/* Check args */
if (NULL == (space = H5I_object_verify(space_id, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "not a data space");
/* Clear the previous extent from the dataspace */
if(H5S_extent_release(&space->extent)<0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTDELETE, FAIL, "can't release previous dataspace");
space->extent.type=H5S_NO_CLASS;
done:
FUNC_LEAVE_API(ret_value);
} /* end H5Sset_extent_none() */
/*--------------------------------------------------------------------------
NAME
H5Soffset_simple
PURPOSE
Changes the offset of a selection within a simple dataspace extent
USAGE
herr_t H5Soffset_simple(space_id, offset)
hid_t space_id; IN: Dataspace object to reset
const hssize_t *offset; IN: Offset to position the selection at
RETURNS
Non-negative on success/Negative on failure
DESCRIPTION
This function creates an offset for the selection within an extent, allowing
the same shaped selection to be moved to different locations within a
dataspace without requiring it to be re-defined.
--------------------------------------------------------------------------*/
herr_t
H5Soffset_simple(hid_t space_id, const hssize_t *offset)
{
H5S_t *space = NULL; /* dataspace to modify */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_API(H5Soffset_simple, FAIL);
H5TRACE2("e","i*Hs",space_id,offset);
/* Check args */
if (NULL == (space = H5I_object_verify(space_id, H5I_DATASPACE)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "not a data space");
if (space->extent.rank==0 || (H5S_GET_EXTENT_TYPE(space)==H5S_SCALAR
|| H5S_GET_EXTENT_TYPE(space)==H5S_NULL))
HGOTO_ERROR(H5E_ATOM, H5E_UNSUPPORTED, FAIL, "can't set offset on scalar or null dataspace");
if (offset == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no offset specified");
/* Set the selection offset */
if(H5S_select_offset(space,offset)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "can't set offset");
done:
FUNC_LEAVE_API(ret_value);
} /* end H5Soffset_simple() */
/*-------------------------------------------------------------------------
* Function: H5S_set_extent
*
* Purpose: Modify the dimensions of a data space. Based on H5S_extend
*
* Return: Success: Non-negative
*
* Failure: Negative
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: March 13, 2002
*
*-------------------------------------------------------------------------
*/
int
H5S_set_extent( H5S_t *space, const hsize_t *size )
{
unsigned u;
herr_t ret_value=0;
FUNC_ENTER_NOAPI( H5S_set_extent, FAIL );
/* Check args */
assert( space && H5S_SIMPLE==H5S_GET_EXTENT_TYPE(space) );
assert( size);
/* Verify that the dimensions being changed are allowed to change */
for ( u = 0; u < space->extent.rank; u++ ) {
if ( space->extent.max && H5S_UNLIMITED != space->extent.max[u] &&
space->extent.max[u]!=size[u] )
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,"dimension cannot be modified");
ret_value++;
} /* end for */
/* Update */
if (ret_value)
H5S_set_extent_real(space,size);
done:
FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5S_has_extent
*
* Purpose: Determines if a simple dataspace's extent has been set (e.g.,
* by H5Sset_extent_simple() ). Helps avoid write errors.
*
* Return: TRUE if dataspace has extent set
* FALSE if dataspace's extent is uninitialized
*
* Programmer: James Laird
*
* Date: July 23, 2004
*
*-------------------------------------------------------------------------
*/
hbool_t
H5S_has_extent(const H5S_t *ds)
{
htri_t ret_value;
FUNC_ENTER_NOAPI(H5S_has_extent, FAIL)
assert(ds);
if(ds->extent.rank==0 && ds->extent.nelem == 0 && ds->extent.type != H5S_NULL)
ret_value = FALSE;
else
ret_value = TRUE;
done:
FUNC_LEAVE_NOAPI(ret_value)
}
/*-------------------------------------------------------------------------
* Function: H5S_set_extent_real
*
* Purpose: Modify the dimensions of a data space. Based on H5S_extend
*
* Return: Success: Non-negative
*
* Failure: Negative
*
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: March 13, 2002
*
*-------------------------------------------------------------------------
*/
herr_t
H5S_set_extent_real( H5S_t *space, const hsize_t *size )
{
hsize_t nelem; /* Number of elements in extent */
unsigned u; /* Local index variable */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_set_extent_real, FAIL );
/* Check args */
assert(space && H5S_SIMPLE==H5S_GET_EXTENT_TYPE(space));
assert(size);
/* Change the dataspace size & re-compute the number of elements in the extent */
for (u=0, nelem=1; u < space->extent.rank; u++ ) {
space->extent.size[u] = size[u];
nelem*=space->extent.size[u];
} /* end for */
space->extent.nelem = nelem;
/* If the selection is 'all', update the number of elements selected */
if(H5S_GET_SELECT_TYPE(space)==H5S_SEL_ALL)
if(H5S_select_all(space, FALSE)<0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection");
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5S_set_extent_real() */
/*-------------------------------------------------------------------------
* Function: H5S_debug
*
* Purpose: Prints debugging information about a data space.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Robb Matzke
* Tuesday, July 21, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
H5S_debug(H5F_t *f, hid_t dxpl_id, const void *_mesg, FILE *stream, int indent, int fwidth)
{
const H5S_t *mesg = (const H5S_t*)_mesg;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5S_debug, FAIL);
switch (H5S_GET_EXTENT_TYPE(mesg)) {
case H5S_NULL:
fprintf(stream, "%*s%-*s H5S_NULL\n", indent, "", fwidth,
"Space class:");
break;
case H5S_SCALAR:
fprintf(stream, "%*s%-*s H5S_SCALAR\n", indent, "", fwidth,
"Space class:");
break;
case H5S_SIMPLE:
fprintf(stream, "%*s%-*s H5S_SIMPLE\n", indent, "", fwidth,
"Space class:");
H5O_debug_id(H5O_SDSPACE_ID, f, dxpl_id, &(mesg->extent), stream,
indent+3, MAX(0, fwidth-3));
break;
default:
fprintf(stream, "%*s%-*s **UNKNOWN-%ld**\n", indent, "", fwidth,
"Space class:", (long)(H5S_GET_EXTENT_TYPE(mesg)));
break;
}
done:
FUNC_LEAVE_NOAPI(ret_value);
}
|