summaryrefslogtreecommitdiffstats
path: root/fortran/test/tH5Sselect.F90
blob: 5f7ece743981a31a814702fa4ded08a55604bef5 (plain)
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
!****h* root/fortran/test/tH5Sselect.f90
!
! NAME
!  tH5Sselect.f90
!
! FUNCTION
!  Basic testing of Fortran H5S, Selection-related Dataspace Interface, APIs.
!
! COPYRIGHT
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
!   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 COPYING file, which can be found at the root of the source code       *
!   distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
!   If you do not have access to either file, you may request a copy from     *
!   help@hdfgroup.org.                                                        *
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
!
! NOTES
!  Tests the following functionalities:
!    h5sget_select_npoints_f, h5sselect_elements_f, h5sselect_all_f,
!    h5sselect_none_f, h5sselect_valid_f, h5sselect_hyperslab_f,
!    h5sget_select_bounds_f, h5sget_select_elem_pointlist_f,
!    h5sget_select_elem_npoints_f, h5sget_select_hyper_blocklist_f,
!    h5sget_select_hyper_nblocks_f, h5sget_select_npoints_f
!
! CONTAINS SUBROUTINES
!  test_select_hyperslab, test_select_element, test_basic_select,
!  test_select_point, test_select_combine, test_select_bounds
!
!
!*****
MODULE TH5SSELECT

  USE HDF5 ! This module contains all necessary modules
  USE TH5_MISC
  USE TH5_MISC_GEN

CONTAINS

  SUBROUTINE test_select_hyperslab(cleanup, total_error)

    IMPLICIT NONE
    LOGICAL, INTENT(IN) :: cleanup
    INTEGER, INTENT(INOUT) :: total_error

    CHARACTER(LEN=7), PARAMETER :: filename = "tselect"
    CHARACTER(LEN=80) :: fix_filename

    !
    !dataset name is "IntArray"
    !
    CHARACTER(LEN=8), PARAMETER :: dsetname = "IntArray"

    INTEGER(HID_T) :: file_id       ! File identifier
    INTEGER(HID_T) :: dset_id       ! Dataset identifier
    INTEGER(HID_T) :: dataspace     ! Dataspace identifier
    INTEGER(HID_T) :: memspace      ! memspace identifier

    !
    !Memory space dimensions
    !
    INTEGER(HSIZE_T), DIMENSION(3) :: dimsm = (/7,7,3/)


    !
    !Dataset dimensions
    !
    INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/5,6/)

    !
    !Size of the hyperslab in the file
    !
    INTEGER(HSIZE_T), DIMENSION(2) :: count = (/3,4/)

    !
    !hyperslab offset in the file
    !
    INTEGER(HSIZE_T), DIMENSION(2) :: offset = (/1,2/)

    !
    !Size of the hyperslab in memory
    !
    INTEGER(HSIZE_T), DIMENSION(3) :: count_out = (/3,4,1/)

    !
    !hyperslab offset in memory
    !
    INTEGER(HSIZE_T), DIMENSION(3) :: offset_out = (/3,0,0/)

    !
    !data to write
    !
    INTEGER, DIMENSION(5,6) :: data

    !
    !output buffer
    !
    INTEGER, DIMENSION(7,7,3) :: data_out


    !
    !dataset space rank
    !
    INTEGER :: dsetrank = 2

    !
    !memspace rank
    !
    INTEGER :: memrank = 3




    !
    !general purpose integer
    !
    INTEGER :: i, j

    !
    !flag to check operation success
    !
    INTEGER :: error
    INTEGER(HSIZE_T), DIMENSION(3) :: data_dims


    !
    !This writes data to the HDF5 file.
    !

    !
    !data initialization
    !
    do i = 1, 5
       do j = 1, 6
          data(i,j) = (i-1) + (j-1);
       end do
    end do
    !
    ! 0,  1,  2,  3,  4,  5
    ! 1,  2,  3,  4,  5,  6
    ! 2,  3,  4,  5,  6,  7
    ! 3,  4,  5,  6,  7,  8
    ! 4,  5,  6,  7,  8,  9
    !

    !
    !Initialize FORTRAN predifined datatypes
    !
!    CALL h5init_types_f(error)
!    CALL check("h5init_types_f", error, total_error)

    !
    !Create a new file using default properties.
    !
          CALL h5_fixname_f(filename, fix_filename, H5P_DEFAULT_F, error)
          if (error .ne. 0) then
              write(*,*) "Cannot modify filename"
              stop
          endif
    CALL h5fcreate_f(fix_filename, H5F_ACC_TRUNC_F, file_id, error)
    CALL check("h5fcreate_f", error, total_error)

    !
    !Create the data space for the  dataset.
    !
    CALL h5screate_simple_f(dsetrank, dimsf, dataspace, error)
    CALL check("h5screate_simple_f", error, total_error)

    !
    ! Create the dataset with default properties
    !
    CALL h5dcreate_f(file_id, dsetname, H5T_STD_I32BE, dataspace, &
         dset_id, error)
    CALL check("h5dcreate_f", error, total_error)

    !
    ! Write the dataset
    !
    data_dims(1) = 5
    data_dims(2) = 6
    CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, data_dims, error)
    CALL check("h5dwrite_f", error, total_error)

    !
    !Close the dataspace for the dataset.
    !
    CALL h5sclose_f(dataspace, error)
    CALL check("h5sclose_f", error, total_error)

    !
    !Close the dataset.
    !
    CALL h5dclose_f(dset_id, error)
    CALL check("h5dclose_f", error, total_error)

    !
    !Close the file.
    !
    CALL h5fclose_f(file_id, error)
    CALL check("h5fclose_f", error, total_error)

    !
    !This reads the hyperslab from the sds.h5 file just
    !created, into a 2-dimensional plane of the 3-dimensional array.
    !

    !
    !initialize data_out array
    !
    !     do i = 1, 7
    !          do j = 1, 7
    !              do k = 1,3
    !                  data_out(i,j,k) = 0;
    !              end do
    !          end do
    !     end do

    !
    !Open the file.
    !
    CALL h5fopen_f (fix_filename, H5F_ACC_RDONLY_F, file_id, error)
    CALL check("h5fopen_f", error, total_error)

    !
    !Open the  dataset.
    !
    CALL h5dopen_f(file_id, dsetname, dset_id, error)
    CALL check("h5dopen_f", error, total_error)

    !
    !Get dataset's dataspace handle.
    !
    CALL h5dget_space_f(dset_id, dataspace, error)
    CALL check("h5dget_space_f", error, total_error)

    !
    !Select hyperslab in the dataset.
    !
    CALL h5sselect_hyperslab_f(dataspace, H5S_SELECT_SET_F, &
         offset, count, error)
    CALL check("h5sselect_hyperslab_f", error, total_error)
    !
    !create memory dataspace.
    !
    CALL h5screate_simple_f(memrank, dimsm, memspace, error)
    CALL check("h5screate_simple_f", error, total_error)

    !
    !Select hyperslab in memory.
    !
    CALL h5sselect_hyperslab_f(memspace, H5S_SELECT_SET_F, &
         offset_out, count_out, error)
    CALL check("h5sselect_hyperslab_f", error, total_error)

    !
    !Read data from hyperslab in the file into the hyperslab in
    !memory and display.
    !
    data_dims(1) = 7
    data_dims(2) = 7
    data_dims(3) = 3
    CALL h5dread_f(dset_id, H5T_NATIVE_INTEGER, data_out, data_dims, error, &
         memspace, dataspace)
    CALL check("h5dread_f", error, total_error)

    !
    !Display data_out array
    !
    !do i = 1, 7
    !   print *, (data_out(i,j,1), j = 1,7)
    !end do

    ! 0 0 0 0 0 0 0
    ! 0 0 0 0 0 0 0
    ! 0 0 0 0 0 0 0
    ! 3 4 5 6 0 0 0
    ! 4 5 6 7 0 0 0
    ! 5 6 7 8 0 0 0
    ! 0 0 0 0 0 0 0
    !

    !
    !Close the dataspace for the dataset.
    !
    CALL h5sclose_f(dataspace, error)
    CALL check("h5sclose_f", error, total_error)

    !
    !Close the memoryspace.
    !
    CALL h5sclose_f(memspace, error)
    CALL check("h5sclose_f", error, total_error)

    !
    !Close the dataset.
    !
    CALL h5dclose_f(dset_id, error)
    CALL check("h5dclose_f", error, total_error)

    !
    !Close the file.
    !
    CALL h5fclose_f(file_id, error)
    CALL check("h5fclose_f", error, total_error)


          if(cleanup) CALL h5_cleanup_f(filename, H5P_DEFAULT_F, error)
              CALL check("h5_cleanup_f", error, total_error)
    RETURN

  END SUBROUTINE test_select_hyperslab

  !
  !Subroutine to test element selection
  !

  SUBROUTINE test_select_element(cleanup, total_error)

    USE HDF5 ! This module contains all necessary modules
    USE TH5_MISC

    IMPLICIT NONE
    LOGICAL, INTENT(IN)  :: cleanup
    INTEGER, INTENT(INOUT) :: total_error

    !
    !the dataset1 is stored in file "copy1.h5"
    !
    CHARACTER(LEN=13), PARAMETER :: filename1 = "tselect_copy1"
    CHARACTER(LEN=80) :: fix_filename1

    !
    !the dataset2 is stored in file "copy2.h5"
    !
    CHARACTER(LEN=13), PARAMETER :: filename2 = "tselect_copy2"
    CHARACTER(LEN=80) :: fix_filename2
    !
    !dataset1 name is "Copy1"
    !
    CHARACTER(LEN=8), PARAMETER :: dsetname1 = "Copy1"

    !
    !dataset2 name is "Copy2"
    !
    CHARACTER(LEN=8), PARAMETER :: dsetname2 = "Copy2"

    !
    !dataset rank
    !
    INTEGER, PARAMETER :: RANK = 2

    !
    !number of points selected
    !
    INTEGER(SIZE_T), PARAMETER :: NUMP = 2

    INTEGER(HID_T) :: file1_id       ! File1 identifier
    INTEGER(HID_T) :: file2_id       ! File2 identifier
    INTEGER(HID_T) :: dset1_id       ! Dataset1 identifier
    INTEGER(HID_T) :: dset2_id       ! Dataset2 identifier
    INTEGER(HID_T) :: dataspace1     ! Dataspace identifier
    INTEGER(HID_T) :: dataspace2     ! Dataspace identifier
    INTEGER(HID_T) :: memspace       ! memspace identifier

    !
    !Memory space dimensions
    !
    INTEGER(HSIZE_T), DIMENSION(1) :: dimsm = (/2/)

    !
    !Dataset dimensions
    !
    INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/3,4/)

    !
    !Points positions in the file
    !
    INTEGER(HSIZE_T), DIMENSION(RANK,NUMP) :: coord

    !
    !data buffers
    !
    INTEGER, DIMENSION(3,4) :: buf1, buf2, bufnew

    !
    !value to write
    !
    INTEGER, DIMENSION(2) :: val = (/53, 59/)

    !
    !memory rank
    !
    INTEGER :: memrank = 1

    !
    !general purpose integer
    !
    INTEGER :: i, j

    !
    !flag to check operation success
    !
    INTEGER :: error
    INTEGER(HSIZE_T), DIMENSION(3) :: data_dims


    !
    !Create two files containing identical datasets. Write 0's to one
    !and 1's to the other.
    !

    !
    !data initialization
    !
    do i = 1, 3
       do j = 1, 4
          buf1(i,j) = 0;
       end do
    end do

    do i = 1, 3
       do j = 1, 4
          buf2(i,j) = 1;
       end do
    end do

    !
    !Initialize FORTRAN predifined datatypes
    !
!    CALL h5init_types_f(error)
!    CALL check("h5init_types_f", error, total_error)

    !
    !Create file1, file2  using default properties.
    !
          CALL h5_fixname_f(filename1, fix_filename1, H5P_DEFAULT_F, error)
          if (error .ne. 0) then
              write(*,*) "Cannot modify filename"
              stop
          endif
    CALL h5fcreate_f(fix_filename1, H5F_ACC_TRUNC_F, file1_id, error)
    CALL check("h5fcreate_f", error, total_error)

          CALL h5_fixname_f(filename2, fix_filename2, H5P_DEFAULT_F, error)
          if (error .ne. 0) then
              write(*,*) "Cannot modify filename"
              stop
          endif
    CALL h5fcreate_f(fix_filename2, H5F_ACC_TRUNC_F, file2_id, error)
    CALL check("h5fcreate_f", error, total_error)

    !
    !Create the data space for the  datasets.
    !
    CALL h5screate_simple_f(RANK, dimsf, dataspace1, error)
    CALL check("h5screate_simple_f", error, total_error)

    CALL h5screate_simple_f(RANK, dimsf, dataspace2, error)
    CALL check("h5screate_simple_f", error, total_error)

    !
    ! Create the datasets with default properties
    !
    CALL h5dcreate_f(file1_id, dsetname1, H5T_NATIVE_INTEGER, dataspace1, &
         dset1_id, error)
    CALL check("h5dcreate_f", error, total_error)

    CALL h5dcreate_f(file2_id, dsetname2, H5T_NATIVE_INTEGER, dataspace2, &
         dset2_id, error)
    CALL check("h5dcreate_f", error, total_error)

    !
    ! Write the datasets
    !
    data_dims(1) = 3
    data_dims(2) = 4
    CALL h5dwrite_f(dset1_id, H5T_NATIVE_INTEGER, buf1, data_dims, error)
    CALL check("h5dwrite_f", error, total_error)

    CALL h5dwrite_f(dset2_id, H5T_NATIVE_INTEGER, buf2, data_dims, error)
    CALL check("h5dwrite_f", error, total_error)

    !
    !Close the dataspace for the datasets.
    !
    CALL h5sclose_f(dataspace1, error)
    CALL check("h5sclose_f", error, total_error)

    CALL h5sclose_f(dataspace2, error)
    CALL check("h5sclose_f", error, total_error)

    !
    !Close the datasets.
    !
    CALL h5dclose_f(dset1_id, error)
    CALL check("h5dclose_f", error, total_error)

    CALL h5dclose_f(dset2_id, error)
    CALL check("h5dclose_f", error, total_error)

    !
    !Close the files.
    !
    CALL h5fclose_f(file1_id, error)
    CALL check("h5fclose_f", error, total_error)

    CALL h5fclose_f(file2_id, error)
    CALL check("h5fclose_f", error, total_error)

    !
    !Open the two files.  Select two points in one file, write values to
    !those point locations, then do H5Scopy and write the values to the
    !other file.  Close files.
    !

    !
    !Open the files.
    !
    CALL h5fopen_f (fix_filename1, H5F_ACC_RDWR_F, file1_id, error)
    CALL check("h5fopen_f", error, total_error)

    CALL h5fopen_f (fix_filename2, H5F_ACC_RDWR_F, file2_id, error)
    CALL check("h5fopen_f", error, total_error)

    !
    !Open the  datasets.
    !
    CALL h5dopen_f(file1_id, dsetname1, dset1_id, error)
    CALL check("h5dopen_f", error, total_error)

    CALL h5dopen_f(file2_id, dsetname2, dset2_id, error)
    CALL check("h5dopen_f", error, total_error)

    !
    !Get dataset1's dataspace handle.
    !
    CALL h5dget_space_f(dset1_id, dataspace1, error)
    CALL check("h5dget_space_f", error, total_error)

    !
    !create memory dataspace.
    !
    CALL h5screate_simple_f(memrank, dimsm, memspace, error)
    CALL check("h5screate_simple_f", error, total_error)

    !
    !Set the selected point positions.Because Fortran array index starts
    ! from 1, so add one to the actual select points in C
    !
    coord(1,1) = 1
    coord(2,1) = 2
    coord(1,2) = 1
    coord(2,2) = 4

    !
    !Select the elements in file space
    !
    CALL h5sselect_elements_f(dataspace1, H5S_SELECT_SET_F, RANK, NUMP,&
         coord, error)
    CALL check("h5sselect_elements_f", error, total_error)

    !
    !Write value into the selected points in dataset1
    !
    data_dims(1) = 2
    CALL H5dwrite_f(dset1_id, H5T_NATIVE_INTEGER, val, data_dims, error, &
         mem_space_id=memspace, file_space_id=dataspace1)
    CALL check("h5dwrite_f", error, total_error)

    !
    !Copy the daspace1 into dataspace2
    !
    CALL h5scopy_f(dataspace1, dataspace2, error)
    CALL check("h5scopy_f", error, total_error)

    !
    !Write value into the selected points in dataset2
    !
    CALL H5dwrite_f(dset2_id, H5T_NATIVE_INTEGER, val, data_dims, error, &
         mem_space_id=memspace, file_space_id=dataspace2)
    CALL check("h5dwrite_f", error, total_error)

    !
    !Close the dataspace for the datasets.
    !
    CALL h5sclose_f(dataspace1, error)
    CALL check("h5sclose_f", error, total_error)

    CALL h5sclose_f(dataspace2, error)
    CALL check("h5sclose_f", error, total_error)

    !
    !Close the memoryspace.
    !
    CALL h5sclose_f(memspace, error)
    CALL check("h5sclose_f", error, total_error)

    !
    !Close the datasets.
    !
    CALL h5dclose_f(dset1_id, error)
    CALL check("h5dclose_f", error, total_error)

    CALL h5dclose_f(dset2_id, error)
    CALL check("h5dclose_f", error, total_error)

    !
    !Close the files.
    !
    CALL h5fclose_f(file1_id, error)
    CALL check("h5fclose_f", error, total_error)

    CALL h5fclose_f(file2_id, error)
    CALL check("h5fclose_f", error, total_error)

    !
    !Open both files and print the contents of the datasets.
    !

    !
    !Open the files.
    !
    CALL h5fopen_f (fix_filename1, H5F_ACC_RDWR_F, file1_id, error)
    CALL check("h5fopen_f", error, total_error)

    CALL h5fopen_f (fix_filename2, H5F_ACC_RDWR_F, file2_id, error)
    CALL check("h5fopen_f", error, total_error)

    !
    !Open the  datasets.
    !
    CALL h5dopen_f(file1_id, dsetname1, dset1_id, error)
    CALL check("h5dopen_f", error, total_error)

    CALL h5dopen_f(file2_id, dsetname2, dset2_id, error)
    CALL check("h5dopen_f", error, total_error)

    !
    !Read dataset1.
    !
    data_dims(1) = 3
    data_dims(2) = 4
    CALL h5dread_f(dset1_id, H5T_NATIVE_INTEGER, bufnew, data_dims, error)
    CALL check("h5dread_f", error, total_error)

    !
    !Display the data read from dataset "Copy1"
    !
    !write(*,*) "The data in dataset Copy1 is: "
    !do i = 1, 3
    !   print *, (bufnew(i,j), j = 1,4)
    !end do

    !
    !Read dataset2.
    !
    CALL h5dread_f(dset2_id, H5T_NATIVE_INTEGER, bufnew, data_dims, error)
    CALL check("h5dread_f", error, total_error)

    !
    !Display the data read from dataset "Copy2"
    !
    !write(*,*) "The data in dataset Copy2 is: "
    !do i = 1, 3
    !   print *, (bufnew(i,j), j = 1,4)
    !end do

    !
    !Close the datasets.
    !
    CALL h5dclose_f(dset1_id, error)
    CALL check("h5dclose_f", error, total_error)

    CALL h5dclose_f(dset2_id, error)
    CALL check("h5dclose_f", error, total_error)

    !
    !Close the files.
    !
    CALL h5fclose_f(file1_id, error)
    CALL check("h5fclose_f", error, total_error)

    CALL h5fclose_f(file2_id, error)
    CALL check("h5fclose_f", error, total_error)


          if(cleanup) CALL h5_cleanup_f(filename1, H5P_DEFAULT_F, error)
              CALL check("h5_cleanup_f", error, total_error)
          if(cleanup) CALL h5_cleanup_f(filename2, H5P_DEFAULT_F, error)
              CALL check("h5_cleanup_f", error, total_error)
     RETURN
  END SUBROUTINE  test_select_element


  SUBROUTINE test_basic_select(cleanup, total_error)

    IMPLICIT NONE
    LOGICAL, INTENT(IN)  :: cleanup
    INTEGER, INTENT(INOUT) :: total_error

     !
     !the dataset is stored in file "testselect.h5"
     !
     CHARACTER(LEN=10), PARAMETER :: filename = "testselect"
     CHARACTER(LEN=80) :: fix_filename

     !
     !dataspace rank
     !
     INTEGER, PARAMETER :: RANK = 2

     !
     !select NUMP_POINTS points from the file
     !
     INTEGER(SIZE_T), PARAMETER :: NUMPS = 10

     !
     !dataset name is "testselect"
     !
     CHARACTER(LEN=10), PARAMETER :: dsetname = "testselect"

     INTEGER(HID_T) :: file_id       ! File identifier
     INTEGER(HID_T) :: dset_id       ! Dataset identifier
     INTEGER(HID_T) :: dataspace     ! Dataspace identifier

     !
     !Dataset dimensions
     !
     INTEGER(HSIZE_T), DIMENSION(2) :: dimsf = (/5,6/)

     !
     !Size of the hyperslab in the file
     !
     INTEGER(HSIZE_T), DIMENSION(2) :: count = (/2,2/)

     !
     !hyperslab offset in the file
     !
     INTEGER(HSIZE_T), DIMENSION(2) :: offset = (/0,0/)

     !
     !start block for getting the selected hyperslab
     !
     INTEGER(HSIZE_T) :: startblock = 0

     !
     !start point for getting the selected elements
     !
     INTEGER(HSIZE_T)  :: startpoint = 0

     !
     !Stride of the hyperslab in the file
     !
     INTEGER(HSIZE_T), DIMENSION(2) :: stride = (/3,3/)

     !
     !BLock size of the hyperslab in the file
     !
     INTEGER(HSIZE_T), DIMENSION(2) :: block = (/2,2/)

     !
     !array to give selected points' coordinations
     !
     INTEGER(HSIZE_T), DIMENSION(RANK, NUMPS) :: coord


     !
     !Number of hyperslabs selected in the current dataspace
     !
     INTEGER(HSSIZE_T) :: num_blocks

     !
     !allocatable array for putting a list of hyperslabs
     !selected in the current file dataspace
     !
     INTEGER(HSIZE_T), ALLOCATABLE, DIMENSION(:) :: blocklist

     !
     !Number of points selected in the current dataspace
     !
     INTEGER(HSSIZE_T) :: num_points
     INTEGER(HSIZE_T) :: num1_points

     !
     !allocatable array for putting a list of points
     !selected in the current file dataspace
     !
     INTEGER(HSIZE_T), ALLOCATABLE, DIMENSION(:) :: pointlist

     !
     !start and end bounds in the current dataspace selection
     !
     INTEGER(HSIZE_T), DIMENSION(RANK) :: startout, endout

     !
     !data to write
     !
     INTEGER, DIMENSION(5,6) :: data

     !
     !flag to check operation success
     !
     INTEGER :: error
     INTEGER(HSIZE_T), DIMENSION(3) :: data_dims

     !
     !initialize the coord array to give the selected points' position
     !
     coord(1,1) = 1
     coord(2,1) = 1
     coord(1,2) = 1
     coord(2,2) = 3
     coord(1,3) = 1
     coord(2,3) = 5
     coord(1,4) = 3
     coord(2,4) = 1
     coord(1,5) = 3
     coord(2,5) = 3
     coord(1,6) = 3
     coord(2,6) = 5
     coord(1,7) = 4
     coord(2,7) = 3
     coord(1,8) = 4
     coord(2,8) = 1
     coord(1,9) = 5
     coord(2,9) = 3
     coord(1,10) = 5
     coord(2,10) = 5

     !
     !Create a new file using default properties.
     !
          CALL h5_fixname_f(filename, fix_filename, H5P_DEFAULT_F, error)
          if (error .ne. 0) then
              write(*,*) "Cannot modify filename"
              stop
          endif
     CALL h5fcreate_f(fix_filename, H5F_ACC_TRUNC_F, file_id, error)
     CALL check("h5fcreate_f", error, total_error)

     !
     !Create the data space for the  dataset.
     !
     CALL h5screate_simple_f(RANK, dimsf, dataspace, error)
     CALL check("h5screate_simple_f", error, total_error)

     !
     ! Create the dataset with default properties
     !
     CALL h5dcreate_f(file_id, dsetname, H5T_STD_I32BE, dataspace, &
                      dset_id, error)
     CALL check("h5dcreate_f", error, total_error)

     !
     ! Write the dataset
     !
     data_dims(1) = 5
     data_dims(2) = 6
     CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, data_dims, error)
     CALL check("h5dwrite_f", error, total_error)

     !
     !Close the dataspace for the dataset.
     !
     CALL h5sclose_f(dataspace, error)
     CALL check("h5sclose_f", error, total_error)

     !
     !Close the dataset.
     !
     CALL h5dclose_f(dset_id, error)
     CALL check("h5dclose_f", error, total_error)

     !
     !Close the file.
     !
     CALL h5fclose_f(file_id, error)
     CALL check("h5fclose_f", error, total_error)

     !
     !Open the file.
     !
     CALL h5fopen_f (fix_filename, H5F_ACC_RDONLY_F, file_id, error)
     CALL check("h5fopen_f", error, total_error)

     !
     !Open the  dataset.
     !
     CALL h5dopen_f(file_id, dsetname, dset_id, error)
     CALL check("h5dopen_f", error, total_error)

     !
     !Get dataset's dataspace handle.
     !
     CALL h5dget_space_f(dset_id, dataspace, error)
     CALL check("h5dget_space_f", error, total_error)

     !
     !Select hyperslab in the dataset.
     !
     CALL h5sselect_hyperslab_f(dataspace, H5S_SELECT_SET_F, &
                                offset, count, error, stride, block)
     CALL check("h5sselect_hyperslab_f", error, total_error)

     !
     !get the number of hyperslab blocks in the current dataspac selection
     !
     CALL h5sget_select_hyper_nblocks_f(dataspace, num_blocks, error)
     CALL check("h5sget_select_hyper_nblocks_f", error, total_error)
     IF (num_blocks .NE. 4) write (*,*) "error occured with num_blocks"
     !write(*,*) num_blocks
     !result of num_blocks is 4

     !
     !allocate the blocklist array
     !
     ALLOCATE(blocklist(num_blocks*RANK*2), STAT= error)
     if(error .NE. 0) then
         STOP
     endif

     !
     !get the list of hyperslabs selected in the current dataspac selection
     !
     CALL h5sget_select_hyper_blocklist_f(dataspace, startblock, &
                                          num_blocks, blocklist, error)
     CALL check("h5sget_select_hyper_blocklist_f", error, total_error)
!     write(*,*) (blocklist(i), i =1, num_blocks*RANK*2)
     !result of blocklist selected is:
     !1,  1,  2,  2,  4,  1,  5,  2,  1,  4,  2,  5,  4,  4,  5,  5

     !
     !deallocate the blocklist array
     !
     DEALLOCATE(blocklist)

     !
     !get the selection bounds in the current dataspac selection
     !
     CALL h5sget_select_bounds_f(dataspace, startout, endout, error)
     CALL check("h5sget_select_bounds_f", error, total_error)
     IF ( (startout(1) .ne. 1) .or. (startout(2) .ne. 1) ) THEN
        write(*,*) "error occured to select_bounds's start position"
     END IF

     IF ( (endout(1) .ne. 5) .or. (endout(2) .ne. 5) ) THEN
        write(*,*) "error occured to select_bounds's end position"
     END IF
     !write(*,*) (startout(i), i = 1, RANK)
     !result of startout is 0, 0

     !write(*,*) (endout(i), i = 1, RANK)
     !result of endout is 5, 5

     !
     !allocate the pointlist array
     !
!     ALLOCATE(pointlist(num_blocks*RANK), STAT= error)
     ALLOCATE(pointlist(20), STAT= error)
     if(error .NE. 0) then
         STOP
     endif

     !
     !Select the elements in file space
     !
     CALL h5sselect_elements_f(dataspace, H5S_SELECT_SET_F, RANK, NUMPS,&
                               coord, error)
     CALL check("h5sselect_elements_f", error, total_error)

     !
     !Get the number of selected elements
     !
     CALL h5sget_select_elem_npoints_f(dataspace, num_points, error)
     CALL check("h5sget_select_elem_npoints_f", error, total_error)
     IF (num_points .NE. 10) write(*,*) "error occured with num_points"
     !write(*,*) num_points
     ! result of num_points is 10

     !
     !Get the list of selected elements
     !
     num1_points = num_points
     CALL h5sget_select_elem_pointlist_f(dataspace, startpoint, &
                                          num1_points, pointlist, error)
     CALL check("h5sget_select_elem_pointlist_f", error, total_error)
     !write(*,*) (pointlist(i), i =1, num1_points*RANK)
     !result of pintlist is:
     !1,  1,  3,  1,  5,  1,  1,  3,  3,  3,  5,  3,  3,
     !4,  1,  4,  3,  5,  5,  5

     !
     !deallocate the pointlist array
     !
     DEALLOCATE(pointlist)

     !
     !Close the dataspace for the dataset.
     !
     CALL h5sclose_f(dataspace, error)
     CALL check("h5sclose_f", error, total_error)

     !
     !Close the dataset.
     !
     CALL h5dclose_f(dset_id, error)
     CALL check("h5dclose_f", error, total_error)

     !
     !Close the file.
     !
     CALL h5fclose_f(file_id, error)
     CALL check("h5fclose_f", error, total_error)


          if(cleanup) CALL h5_cleanup_f(filename, H5P_DEFAULT_F, error)
              CALL check("h5_cleanup_f", error, total_error)

     RETURN
  END SUBROUTINE  test_basic_select

!***************************************************************
!**
!**  test_select_point(): Test basic H5S (dataspace) selection code.
!**      Tests element selections between dataspaces of various sizes
!**      and dimensionalities.
!**
!***************************************************************

SUBROUTINE test_select_point(cleanup, total_error)

  IMPLICIT NONE
  LOGICAL, INTENT(IN)  :: cleanup
  INTEGER, INTENT(INOUT) :: total_error
  INTEGER(HID_T) :: xfer_plist

  INTEGER, PARAMETER :: SPACE1_DIM1=3
  INTEGER, PARAMETER :: SPACE1_DIM2=15
  INTEGER, PARAMETER :: SPACE1_DIM3=13
  INTEGER, PARAMETER :: SPACE2_DIM1=30
  INTEGER, PARAMETER :: SPACE2_DIM2=26
  INTEGER, PARAMETER :: SPACE3_DIM1=15
  INTEGER, PARAMETER :: SPACE3_DIM2=26

  INTEGER, PARAMETER :: SPACE1_RANK=3
  INTEGER, PARAMETER :: SPACE2_RANK=2
  INTEGER, PARAMETER :: SPACE3_RANK=2

  !  Element selection information
  INTEGER, PARAMETER :: POINT1_NPOINTS=10
  INTEGER(hid_t) ::fid1 !  HDF5 File IDs
  INTEGER(hid_t) ::dataset !	 Dataset ID
  INTEGER(hid_t) ::sid1,sid2 !  Dataspace ID
  INTEGER(hsize_t), DIMENSION(1:3) :: dims1 = (/SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3/)
  INTEGER(hsize_t), DIMENSION(1:2) :: dims2 = (/SPACE2_DIM1, SPACE2_DIM2/)
  INTEGER(hsize_t), DIMENSION(1:2) :: dims3 = (/SPACE3_DIM1, SPACE3_DIM2/)

  INTEGER(hsize_t), DIMENSION(1:SPACE1_RANK,1:POINT1_NPOINTS) :: coord1 ! Coordinates for point selection
  INTEGER(hsize_t), DIMENSION(1:SPACE1_RANK,1:POINT1_NPOINTS) :: temp_coord1 ! Coordinates for point selection
  INTEGER(hsize_t), DIMENSION(1:SPACE2_RANK,1:POINT1_NPOINTS) :: coord2 ! Coordinates for point selection
  INTEGER(hsize_t), DIMENSION(1:SPACE2_RANK,1:POINT1_NPOINTS) :: temp_coord2 ! Coordinates for point selection
  INTEGER(hsize_t), DIMENSION(1:SPACE3_RANK,1:POINT1_NPOINTS) :: coord3 ! Coordinates for point selection
  INTEGER(hsize_t), DIMENSION(1:SPACE3_RANK,1:POINT1_NPOINTS) :: temp_coord3 ! Coordinates for point selection
  INTEGER(hssize_t) :: npoints

!!$    uint8_t    *wbuf,        buffer to write to disk
!!$               *rbuf,        buffer read from disk
!!$               *tbuf;        temporary buffer pointer
  INTEGER :: i,j;        ! Counters
!    struct pnt_iter pi;      Custom Pointer iterator struct
  INTEGER :: error    ! Generic return value
  CHARACTER(LEN=9) :: filename = 'h5s_hyper'
  CHARACTER(LEN=80) :: fix_filename
  CHARACTER(LEN=1), DIMENSION(1:SPACE2_DIM1,1:SPACE2_DIM2) :: wbuf

  CALL h5_fixname_f(filename, fix_filename, H5P_DEFAULT_F, error)
  IF (error .NE. 0) THEN
     WRITE(*,*) "Cannot modify filename"
     STOP
  ENDIF
  xfer_plist = H5P_DEFAULT_F
!    MESSAGE(5, ("Testing Element Selection Functions\n"));

    ! Allocate write & read buffers
!!$  wbuf = HDmalloc(sizeof(uint8_t) * SPACE2_DIM1 * SPACE2_DIM2);
!!$  rbuf = HDcalloc(sizeof(uint8_t), (size_t)(SPACE3_DIM1 * SPACE3_DIM2));
!!$
  ! Initialize WRITE buffer

  DO i = 1, SPACE2_DIM1
     DO j = 1, SPACE2_DIM2
        wbuf(i,j) = 'a'
     ENDDO
  ENDDO

!!$  for(i=0, tbuf=wbuf; i<SPACE2_DIM1; i++)
!!$  for(j=0; j<SPACE2_DIM2; j++)
!!$  *tbuf++=(uint8_t)((i*SPACE2_DIM2)+j);

  ! Create file
  CALL h5fcreate_f(fix_filename, H5F_ACC_TRUNC_F, fid1, error)
  CALL check("h5fcreate_f", error, total_error)

  ! Create dataspace for dataset
  CALL h5screate_simple_f(SPACE1_RANK, dims1, sid1, error)
  CALL check("h5screate_simple_f", error, total_error)

  ! Create dataspace for write buffer
  CALL h5screate_simple_f(SPACE2_RANK, dims2, sid2, error)
  CALL check("h5screate_simple_f", error, total_error)

  ! Select sequence of ten points for disk dataset
  coord1(1,1)=1; coord1(2,1)=11; coord1(3,1)= 6;
  coord1(1,2)=2; coord1(2,2)= 3; coord1(3,2)= 8;
  coord1(1,3)=3; coord1(2,3)= 5; coord1(3,3)=10;
  coord1(1,4)=1; coord1(2,4)= 7; coord1(3,4)=12;
  coord1(1,5)=2; coord1(2,5)= 9; coord1(3,5)=14;
  coord1(1,6)=3; coord1(2,6)=13; coord1(3,6)= 1;
  coord1(1,7)=1; coord1(2,7)=15; coord1(3,7)= 3;
  coord1(1,8)=2; coord1(2,8)= 1; coord1(3,8)= 5;
  coord1(1,9)=3; coord1(2,9)= 2; coord1(3,9)= 7;
  coord1(1,10)=1; coord1(2,10)= 4; coord1(3,10)= 9

  CALL h5sselect_elements_f(sid1, H5S_SELECT_SET_F, SPACE1_RANK, INT(POINT1_NPOINTS,size_t), coord1, error)
  CALL check("h5sselect_elements_f", error, total_error)

  ! Verify correct elements selected

  CALL h5sget_select_elem_pointlist_f(sid1, INT(0,hsize_t), INT(POINT1_NPOINTS,hsize_t),temp_coord1,error)
  CALL check("h5sget_select_elem_pointlist_f", error, total_error)

  DO i= 1, POINT1_NPOINTS
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord1(1,i)), INT(coord1(1,i)), total_error)
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord1(2,i)), INT(coord1(2,i)), total_error)
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord1(3,i)), INT(coord1(3,i)), total_error)
  ENDDO

  CALL H5Sget_select_npoints_f(sid1, npoints, error)
  CALL check("h5sget_select_npoints_f", error, total_error)
  CALL verify("h5sget_select_npoints_f", INT(npoints), 10, total_error)

  ! Append another sequence of ten points to disk dataset

  coord1(1,1)=1; coord1(2,1)=3; coord1(3,1)= 1;
  coord1(1,2)=2; coord1(2,2)=11; coord1(3,2)= 9;
  coord1(1,3)=3; coord1(2,3)= 9; coord1(3,3)=11;
  coord1(1,4)=1; coord1(2,4)= 8; coord1(3,4)=13;
  coord1(1,5)=2; coord1(2,5)= 4; coord1(3,5)=12;
  coord1(1,6)=3; coord1(2,6)= 2; coord1(3,6)= 2;
  coord1(1,7)=1; coord1(2,7)=14; coord1(3,7)= 8;
  coord1(1,8)=2; coord1(2,8)=15; coord1(3,8)= 7;
  coord1(1,9)=3; coord1(2,9)= 3; coord1(3,9)= 6;
  coord1(1,10)=1; coord1(2,10)= 7; coord1(3,10)= 14


  CALL h5sselect_elements_f(sid1, H5S_SELECT_APPEND_F, SPACE1_RANK, INT(POINT1_NPOINTS,size_t), coord1, error)
  CALL check("h5sselect_elements_f", error, total_error)
  !  Verify correct elements selected

  CALL h5sget_select_elem_pointlist_f(sid1, INT(POINT1_NPOINTS,hsize_t), INT(POINT1_NPOINTS,hsize_t),temp_coord1,error)
  CALL check("h5sget_select_elem_pointlist_f", error, total_error)

  DO i= 1, POINT1_NPOINTS
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord1(1,i)), INT(coord1(1,i)), total_error)
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord1(2,i)), INT(coord1(2,i)), total_error)
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord1(3,i)), INT(coord1(3,i)), total_error)
  ENDDO

  CALL H5Sget_select_npoints_f(sid1, npoints, error)
  CALL check("h5sget_select_npoints_f", error, total_error)
  CALL verify("h5sget_select_npoints_f", INT(npoints), 20, total_error)

  !  Select sequence of ten points for memory dataset
  coord2(1,1)=13; coord2(2,1)= 4;
  coord2(1,2)=16; coord2(2,2)=14;
  coord2(1,3)= 8; coord2(2,3)=26;
  coord2(1,4)= 1; coord2(2,4)= 7;
  coord2(1,5)=14; coord2(2,5)= 1;
  coord2(1,6)=25; coord2(2,6)=12;
  coord2(1,7)=13; coord2(2,7)=22;
  coord2(1,8)=30; coord2(2,8)= 5;
  coord2(1,9)= 9; coord2(2,9)= 9;
  coord2(1,10)=20; coord2(2,10)=18

  CALL h5sselect_elements_f(sid2, H5S_SELECT_SET_F, SPACE2_RANK, INT(POINT1_NPOINTS,size_t), coord2, error)
  CALL check("h5sselect_elements_f", error, total_error)


  ! Verify correct elements selected

  CALL h5sget_select_elem_pointlist_f(sid2, INT(0,hsize_t), INT(POINT1_NPOINTS,hsize_t),temp_coord2,error)
  CALL check("h5sget_select_elem_pointlist_f", error, total_error)

  DO i= 1, POINT1_NPOINTS
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord2(1,i)), INT(coord2(1,i)), total_error)
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord2(2,i)), INT(coord2(2,i)), total_error)
  ENDDO

!!$
!!$     Save points for later iteration
!!$     (these are in the second half of the buffer, because we are prepending
!!$      the next list of points to the beginning of the point selection list)
!!$    HDmemcpy(((char *)pi.coord)+sizeof(coord2),coord2,sizeof(coord2));
!!$

  CALL H5Sget_select_npoints_f(sid2, npoints, error)
  CALL check("h5sget_select_npoints_f", error, total_error)
  CALL verify("h5sget_select_npoints_f", INT(npoints), 10, total_error)

  ! Append another sequence of ten points to memory dataset
  coord2(1,1)=25; coord2(2,1)= 1;
  coord2(1,2)= 3; coord2(2,2)=26;
  coord2(1,3)=14; coord2(2,3)=18;
  coord2(1,4)= 9; coord2(2,4)= 4;
  coord2(1,5)=30; coord2(2,5)= 5;
  coord2(1,6)=12; coord2(2,6)=15;
  coord2(1,7)= 6; coord2(2,7)=23;
  coord2(1,8)=13; coord2(2,8)= 3;
  coord2(1,9)=22; coord2(2,9)=13;
  coord2(1,10)= 10; coord2(2,10)=19

  CALL h5sselect_elements_f(sid2, H5S_SELECT_PREPEND_F, SPACE2_RANK, INT(POINT1_NPOINTS,size_t), coord2, error)
  CALL check("h5sselect_elements_f", error, total_error)


  ! Verify correct elements selected
  CALL h5sget_select_elem_pointlist_f(sid2, INT(0,hsize_t), INT(POINT1_NPOINTS,hsize_t),temp_coord2,error)
  CALL check("h5sget_select_elem_pointlist_f", error, total_error)

  DO i= 1, POINT1_NPOINTS
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord2(1,i)), INT(coord2(1,i)), total_error)
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord2(2,i)), INT(coord2(2,i)), total_error)
  ENDDO

  CALL H5Sget_select_npoints_f(sid2, npoints, error)
  CALL check("h5sget_select_npoints_f", error, total_error)
  CALL verify("h5sget_select_npoints_f", INT(npoints), 20, total_error)

!!$     Save points for later iteration
!!$    HDmemcpy(pi.coord,coord2,sizeof(coord2));

  !  Create a dataset
  CALL h5dcreate_f(fid1, "Dataset1", H5T_NATIVE_CHARACTER, sid1, dataset, error)
  CALL check("h5dcreate_f", error, total_error)

  !  Write selection to disk
  CALL h5dwrite_f(dataset, H5T_NATIVE_CHARACTER, wbuf, dims2, error, sid2, sid1, xfer_plist)
  CALL check("h5dwrite_f", error, total_error)

  !  Close memory dataspace
  CALL h5sclose_f(sid2, error)
  CALL check("h5sclose_f", error, total_error)

  !  Create dataspace for reading buffer
  CALL h5screate_simple_f(SPACE3_RANK, dims3, sid2, error)
  CALL check("h5screate_simple_f", error, total_error)

  !  Select sequence of points for read dataset
  coord3(1,1)= 1; coord3(2,1)= 3;
  coord3(1,2)= 5; coord3(2,2)= 9;
  coord3(1,3)=14; coord3(2,3)=14;
  coord3(1,4)=15; coord3(2,4)=21;
  coord3(1,5)= 8; coord3(2,5)=10;
  coord3(1,6)= 3; coord3(2,6)= 1;
  coord3(1,7)= 10; coord3(2,7)=20;
  coord3(1,8)= 2; coord3(2,8)=23;
  coord3(1,9)=13; coord3(2,9)=22;
  coord3(1,10)=12; coord3(2,10)=7;

  CALL h5sselect_elements_f(sid2, H5S_SELECT_SET_F, SPACE3_RANK, INT(POINT1_NPOINTS,size_t), coord3, error)
  CALL check("h5sselect_elements_f", error, total_error)

  !  Verify correct elements selected
  CALL h5sget_select_elem_pointlist_f(sid2, INT(0,hsize_t), INT(POINT1_NPOINTS,hsize_t),temp_coord3,error)
  CALL check("h5sget_select_elem_pointlist_f", error, total_error)
  DO i= 1, POINT1_NPOINTS
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord3(1,i)), INT(coord3(1,i)), total_error)
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord3(2,i)), INT(coord3(2,i)), total_error)
  ENDDO

  CALL H5Sget_select_npoints_f(sid2, npoints, error)
  CALL check("h5sget_select_npoints_f", error, total_error)
  CALL verify("h5sget_select_npoints_f", INT(npoints), 10, total_error)

  ! Append another sequence of ten points to disk dataset
    coord3(1,1)=15; coord3(2,1)=26;
    coord3(1,2)= 1; coord3(2,2)= 1;
    coord3(1,3)=12; coord3(2,3)=12;
    coord3(1,4)= 6; coord3(2,4)=15;
    coord3(1,5)= 4; coord3(2,5)= 6;
    coord3(1,6)= 3; coord3(2,6)= 3;
    coord3(1,7)= 8; coord3(2,7)=14;
    coord3(1,8)=10; coord3(2,8)=17;
    coord3(1,9)=13; coord3(2,9)=23;
    coord3(1,10)=14; coord3(2,10)=10

    CALL h5sselect_elements_f(sid2, H5S_SELECT_APPEND_F, SPACE3_RANK, INT(POINT1_NPOINTS,size_t), coord3, error)
    CALL check("h5sselect_elements_f", error, total_error)

  !  Verify correct elements selected
  CALL h5sget_select_elem_pointlist_f(sid2, INT(POINT1_NPOINTS,hsize_t), INT(POINT1_NPOINTS,hsize_t),temp_coord3,error)
  CALL check("h5sget_select_elem_pointlist_f", error, total_error)
  DO i= 1, POINT1_NPOINTS
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord3(1,i)), INT(coord3(1,i)), total_error)
     CALL verify("h5sget_select_elem_pointlist_f", INT(temp_coord3(2,i)), INT(coord3(2,i)), total_error)
  ENDDO

  CALL H5Sget_select_npoints_f(sid2, npoints, error)
  CALL check("h5sget_select_npoints_f", error, total_error)
  CALL verify("h5sget_select_npoints_f", INT(npoints), 20, total_error)

! F2003 feature
!!$  Read selection from disk
!!$    ret=H5Dread(dataset,H5T_NATIVE_UCHAR,sid2,sid1,xfer_plist,rbuf);
!!$    CHECK(ret, FAIL, "H5Dread");
!!$
!!$     Check that the values match with a dataset iterator
!!$    pi.buf=wbuf;
!!$    pi.offset=0;
!!$    ret = H5Diterate(rbuf,H5T_NATIVE_UCHAR,sid2,test_select_point_iter1,&pi);
!!$    CHECK(ret, FAIL, "H5Diterate");
!!$
! F2003 feature

  ! Close memory dataspace
  CALL h5sclose_f(sid2, error)
  CALL check("h5sclose_f", error, total_error)

  ! Close disk dataspace
  CALL h5sclose_f(sid1, error)
  CALL check("h5sclose_f", error, total_error)

  ! Close Dataset
  CALL h5dclose_f(dataset, error)
  CALL check("h5dclose_f", error, total_error)

  ! Close file
  CALL h5fclose_f(fid1, error)
  CALL check("h5fclose_f", error, total_error)

  IF(cleanup) CALL h5_cleanup_f(filename, H5P_DEFAULT_F, error)
  CALL check("h5_cleanup_f", error, total_error)

END SUBROUTINE test_select_point


!***************************************************************
!**
!**  test_select_combine(): Test basic H5S (dataspace) selection code.
!**      Tests combining "all" and "none" selections with hyperslab
!**      operations.
!**
!***************************************************************

SUBROUTINE test_select_combine(total_error)

  IMPLICIT NONE
  INTEGER, INTENT(INOUT) :: total_error

  INTEGER, PARAMETER :: SPACE7_RANK = 2
  INTEGER, PARAMETER :: SPACE7_DIM1 = 10
  INTEGER, PARAMETER :: SPACE7_DIM2 = 10

  INTEGER(hid_t) :: base_id !       Base dataspace for test
  INTEGER(hid_t) :: all_id !        Dataspace for "all" selection
  INTEGER(hid_t) :: none_id !       Dataspace for "none" selection
  INTEGER(hid_t) :: space1 !        Temporary dataspace #1
  INTEGER(hsize_t), DIMENSION(1:SPACE7_RANK) :: start !  Hyperslab start
  INTEGER(hsize_t), DIMENSION(1:SPACE7_RANK) :: stride !  Hyperslab stride
  INTEGER(hsize_t), DIMENSION(1:SPACE7_RANK) :: icount !  Hyperslab count
  INTEGER(hsize_t), DIMENSION(1:SPACE7_RANK) :: iblock !  Hyperslab BLOCK
  INTEGER(hsize_t), DIMENSION(1:SPACE7_RANK) :: dims = (/SPACE7_DIM1,SPACE7_DIM2/) ! Dimensions of dataspace
  INTEGER :: sel_type !  Selection type
  INTEGER(hssize_t) :: nblocks   ! Number of hyperslab blocks
  INTEGER(hsize_t), DIMENSION(1:128,1:2,1:SPACE7_RANK) :: blocks !  List of blocks
  INTEGER :: error, area

  ! Create dataspace for dataset on disk
  CALL h5screate_simple_f(SPACE7_RANK, dims, base_id, error)
  CALL check("h5screate_simple_f", error, total_error)

  !  Copy base dataspace and set selection to "all"
  CALL h5scopy_f(base_id, all_id, error)
  CALL check("h5scopy_f", error, total_error)

  CALL H5Sselect_all_f(all_id, error)
  CALL check("H5Sselect_all_f", error, total_error)

  CALL H5Sget_select_type_f(all_id, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT(H5S_SEL_ALL_F), total_error)

  ! Copy base dataspace and set selection to "none"
  CALL h5scopy_f(base_id, none_id, error)
  CALL check("h5scopy_f", error, total_error)

  CALL H5Sselect_none_f(none_id, error)
  CALL check("H5Sselect_none_f", error, total_error)

  CALL H5Sget_select_type_f(none_id, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT(H5S_SEL_NONE_F), total_error)

  ! Copy "all" selection & space
  CALL H5Scopy_f(all_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  ! 'OR' "all" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/)
  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_OR_F, start, &
                                icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  ! Verify that it's still "all" selection
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT(H5S_SEL_ALL_F), total_error)

  ! Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  ! Copy "all" selection & space
  CALL H5Scopy_f(all_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'AND' "all" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/)
  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_AND_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  ! Verify that the new selection is the same at the original block
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_HYPERSLABS_F), total_error)

  ! Verify that there is only one block
  CALL h5sget_select_hyper_nblocks_f(space1, nblocks, error)
  CALL check("h5sget_select_hyper_nblocks_f", error, total_error)
  CALL verify("h5sget_select_hyper_nblocks_f", INT(nblocks), 1, total_error)

  ! Retrieve the block defined
  CALL h5sget_select_hyper_blocklist_f(space1, INT(0, hsize_t), INT(nblocks,hsize_t), blocks, error)
  CALL check("h5sget_select_hyper_blocklist_f", error, total_error)

  ! Verify that the correct block is defined

  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(1,1,1)), 1, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(2,1,1)), 1, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(3,1,1)), 5, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(4,1,1)), 4, total_error)

  ! Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  ! Copy "all" selection & space
  CALL H5Scopy_f(all_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'XOR' "all" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/)

  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_XOR_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  !  Verify that the new selection is an inversion of the original block
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_HYPERSLABS_F), total_error)

  !  Verify that there are two blocks
  CALL h5sget_select_hyper_nblocks_f(space1, nblocks, error)
  CALL check("h5sget_select_hyper_nblocks_f", error, total_error)
  CALL verify("h5sget_select_hyper_nblocks_f", INT(nblocks), 2, total_error)

  !  Retrieve the block defined

  blocks = -1 !  Reset block list
  CALL h5sget_select_hyper_blocklist_f(space1, INT(0, hsize_t), INT(nblocks,hsize_t), blocks, error)
  CALL check("h5sget_select_hyper_blocklist_f", error, total_error)

  !  Verify that the correct block is defined

  ! No guarantee is implied as the order in which blocks are listed.
  ! So this will ONLY work for square domains iblock(1:2) = (/5,5/)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(1,1,1)), 1, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(2,1,1)), 5, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(3,1,1)), 5, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(4,1,1)), 10, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(5,1,1)), 6, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(6,1,1)), 1, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(7,1,1)), 10, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(8,1,1)), 10, total_error)

  ! Otherwise make sure the "area" of the block is correct
  area = (ABS(INT(blocks(1,1,1)-blocks(3,1,1)))+1)*(ABS(INT(blocks(2,1,1)-blocks(4,1,1)))+1)
  area = area + (ABS(INT(blocks(5,1,1)-blocks(7,1,1)))+1)*(ABS(INT(blocks(6,1,1)-blocks(8,1,1)))+1)
  CALL verify("h5sget_select_hyper_blocklist_f", area, 80, total_error)

  ! Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  !  Copy "all" selection & space
  CALL H5Scopy_f(all_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'NOTB' "all" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/) !5

  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_NOTB_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  !  Verify that the new selection is an inversion of the original block
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_HYPERSLABS_F), total_error)

  !  Verify that there are two blocks
  CALL h5sget_select_hyper_nblocks_f(space1, nblocks, error)
  CALL check("h5sget_select_hyper_nblocks_f", error, total_error)
  CALL verify("h5sget_select_hyper_nblocks_f", INT(nblocks), 2, total_error)

  !  Retrieve the block defined
  blocks = -1 !  Reset block list
  CALL h5sget_select_hyper_blocklist_f(space1, INT(0, hsize_t), INT(nblocks,hsize_t), blocks, error)
  CALL check("h5sget_select_hyper_blocklist_f", error, total_error)

  !  Verify that the correct block is defined

  ! No guarantee is implied as the order in which blocks are listed.
  ! So this will ONLY work for square domains iblock(1:2) = (/5,5/)

!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(1,1,1)), 1, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(2,1,1)), 5, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(3,1,1)), 5, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(4,1,1)),10, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(5,1,1)), 6, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(6,1,1)), 1, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(7,1,1)),10, total_error)
!!$  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(8,1,1)),10, total_error)

  ! Otherwise make sure the "area" of the block is correct
  area = (ABS(INT(blocks(1,1,1)-blocks(3,1,1)))+1)*(ABS(INT(blocks(2,1,1)-blocks(4,1,1)))+1)
  area = area + (ABS(INT(blocks(5,1,1)-blocks(7,1,1)))+1)*(ABS(INT(blocks(6,1,1)-blocks(8,1,1)))+1)
  CALL verify("h5sget_select_hyper_blocklist_f", area, 80, total_error)


  !  Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)
  !  Copy "all" selection & space
  CALL H5Scopy_f(all_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'NOTA' "all" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/) !5

  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_NOTA_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  ! Verify that the new selection is the "none" selection
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_NONE_F), total_error)

  !  Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  !  Copy "none" selection & space
  CALL H5Scopy_f(none_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'OR' "none" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/) !5

  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_OR_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  !  Verify that the new selection is the same as the original hyperslab
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_HYPERSLABS_F), total_error)


  !  Verify that there is only one block
  CALL h5sget_select_hyper_nblocks_f(space1, nblocks, error)
  CALL check("h5sget_select_hyper_nblocks_f", error, total_error)
  CALL verify("h5sget_select_hyper_nblocks_f", INT(nblocks), 1, total_error)

  !  Retrieve the block defined
  blocks = -1 !  Reset block list
  CALL h5sget_select_hyper_blocklist_f(space1, INT(0, hsize_t), INT(nblocks,hsize_t), blocks, error)
  CALL check("h5sget_select_hyper_blocklist_f", error, total_error)

  !  Verify that the correct block is defined
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(1,1,1)), 1, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(2,1,1)), 1, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(3,1,1)), 5, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(4,1,1)), 4, total_error)

  !  Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  !  Copy "none" selection & space
  CALL H5Scopy_f(none_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'AND' "none" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/) !5

  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_AND_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  !  Verify that the new selection is the "none" selection
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_NONE_F), total_error)

  !  Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  !  Copy "none" selection & space
  CALL H5Scopy_f(none_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'XOR' "none" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/) !5

  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_XOR_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  !  Verify that the new selection is the same as the original hyperslab
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_HYPERSLABS_F), total_error)


  !  Verify that there is only one block
  CALL h5sget_select_hyper_nblocks_f(space1, nblocks, error)
  CALL check("h5sget_select_hyper_nblocks_f", error, total_error)
  CALL verify("h5sget_select_hyper_nblocks_f", INT(nblocks), 1, total_error)

  !  Retrieve the block defined
  blocks = -1 !  Reset block list
  CALL h5sget_select_hyper_blocklist_f(space1, INT(0, hsize_t), INT(nblocks,hsize_t), blocks, error)
  CALL check("h5sget_select_hyper_blocklist_f", error, total_error)
  !  Verify that the correct block is defined
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(1,1,1)), 1, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(2,1,1)), 1, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(3,1,1)), 5, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(4,1,1)), 4, total_error)

  !  Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  !  Copy "none" selection & space
  CALL H5Scopy_f(none_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'NOTB' "none" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/) !5

  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_NOTB_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  !  Verify that the new selection is the "none" selection
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_NONE_F), total_error)

  !  Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  !  Copy "none" selection & space
  CALL H5Scopy_f(none_id, space1, error)
  CALL check("h5scopy_f", error, total_error)

  !  'NOTA' "none" selection with another hyperslab
  start(1:2) = 0
  stride(1:2) = 1
  icount(1:2) = 1
  iblock(1:2) = (/5,4/) !5
  CALL h5sselect_hyperslab_f(space1, H5S_SELECT_NOTA_F, start, &
       icount, error, stride, iblock)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  !  Verify that the new selection is the same as the original hyperslab
  CALL H5Sget_select_type_f(space1, sel_type, error)
  CALL check("H5Sget_select_type_f", error, total_error)
  CALL verify("H5Sget_select_type_f", INT(sel_type), INT( H5S_SEL_HYPERSLABS_F), total_error)

  !  Verify that there is ONLY one BLOCK
  CALL h5sget_select_hyper_nblocks_f(space1, nblocks, error)
  CALL check("h5sget_select_hyper_nblocks_f", error, total_error)
  CALL verify("h5sget_select_hyper_nblocks_f", INT(nblocks), 1, total_error)

  !  Retrieve the block defined

  blocks = -1 !  Reset block list
  CALL h5sget_select_hyper_blocklist_f(space1, INT(0, hsize_t), INT(nblocks,hsize_t), blocks, error)
  CALL check("h5sget_select_hyper_blocklist_f", error, total_error)


  !  Verify that the correct block is defined

  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(1,1,1)), 1, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(2,1,1)), 1, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(3,1,1)), 5, total_error)
  CALL verify("h5sget_select_hyper_blocklist_f", INT(blocks(4,1,1)), 4, total_error)

  !  Close temporary dataspace
  CALL h5sclose_f(space1, error)
  CALL check("h5sclose_f", error, total_error)

  !  Close dataspaces

  CALL h5sclose_f(base_id, error)
  CALL check("h5sclose_f", error, total_error)
  CALL h5sclose_f(all_id, error)
  CALL check("h5sclose_f", error, total_error)
  CALL h5sclose_f(none_id, error)
  CALL check("h5sclose_f", error, total_error)

END SUBROUTINE test_select_combine

!***************************************************************
!**
!**  test_select_bounds(): Tests selection bounds on dataspaces,
!**      both with and without offsets.
!**
!***************************************************************

SUBROUTINE test_select_bounds(total_error)

  IMPLICIT NONE
  INTEGER, INTENT(INOUT) :: total_error

  INTEGER, PARAMETER :: SPACE11_RANK=2
  INTEGER, PARAMETER :: SPACE11_DIM1=100
  INTEGER, PARAMETER :: SPACE11_DIM2=50
  INTEGER, PARAMETER :: SPACE11_NPOINTS=4

  INTEGER(hid_t) :: sid !  Dataspace ID
  INTEGER(hsize_t), DIMENSION(1:SPACE11_RANK) :: dims = (/SPACE11_DIM1, SPACE11_DIM2/) !Dataspace dimensions
  INTEGER(hsize_t), DIMENSION(SPACE11_RANK, SPACE11_NPOINTS) :: coord ! Coordinates for point selection
  INTEGER(hsize_t), DIMENSION(SPACE11_RANK) :: start !  The start of the hyperslab
  INTEGER(hsize_t), DIMENSION(SPACE11_RANK) :: stride ! The stride between block starts for the hyperslab
  INTEGER(hsize_t), DIMENSION(SPACE11_RANK) :: count ! The number of blocks for the hyperslab
  INTEGER(hsize_t), DIMENSION(SPACE11_RANK) :: BLOCK ! The size of each block for the hyperslab
  INTEGER(hssize_t), DIMENSION(SPACE11_RANK) :: offset ! Offset amount for selection
  INTEGER(hsize_t), DIMENSION(SPACE11_RANK) :: low_bounds ! The low bounds for the selection
  INTEGER(hsize_t), DIMENSION(SPACE11_RANK) :: high_bounds ! The high bounds for the selection

  INTEGER :: error

  ! Create dataspace
  CALL h5screate_simple_f(SPACE11_RANK, dims, sid, error)
  CALL check("h5screate_simple_f", error, total_error)

  !  Get bounds for 'all' selection
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL check("h5sget_select_bounds_f", error, total_error)

  CALL verify("h5sget_select_bounds_f", low_bounds(1), 1_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", low_bounds(2), 1_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(1), INT(SPACE11_DIM1, hsize_t), total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(2), INT(SPACE11_DIM2, hsize_t), total_error)

  ! Set offset for selection
  offset(1:2) = 1
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  ! Get bounds for 'all' selection with offset (which should be ignored)
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL check("h5sget_select_bounds_f", error, total_error)

  CALL verify("h5sget_select_bounds_f", low_bounds(1), 1_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", low_bounds(2), 1_hsize_t, total_error)
  CALL VERIFY("h5sget_select_bounds_f", high_bounds(1), INT(SPACE11_DIM1, hsize_t), total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(2), INT(SPACE11_DIM2, hsize_t), total_error)

  ! Reset offset for selection
  offset(1:2) = 0
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  ! Set 'none' selection
  CALL H5Sselect_none_f(sid, error)
  CALL check("H5Sselect_none_f", error, total_error)

  ! Get bounds for 'none' selection, should fail
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL verify("h5sget_select_bounds_f", error, -1, total_error)

  ! Set point selection

  coord(1,1)=  3; coord(2,1)=  3;
  coord(1,2)=  3; coord(2,2)= 46;
  coord(1,3)= 96; coord(2,3)=  3;
  coord(1,4)= 96; coord(2,4)= 46;

  CALL h5sselect_elements_f(sid, H5S_SELECT_SET_F, SPACE11_RANK, INT(SPACE11_NPOINTS,size_t), coord, error)
  CALL check("h5sselect_elements_f", error, total_error)

  ! Get bounds for point selection
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL check("h5sget_select_bounds_f", error, total_error)

  CALL verify("h5sget_select_bounds_f", low_bounds(1), 3_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", low_bounds(2), 3_hsize_t, total_error)
  CALL VERIFY("h5sget_select_bounds_f", high_bounds(1), INT(SPACE11_DIM1-4,hsize_t), total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(2), INT(SPACE11_DIM2-4,hsize_t), total_error)

  !  Set bad offset for selection

  offset(1:2) = (/5,-5/)
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  !  Get bounds for hyperslab selection with negative offset
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL verify("h5sget_select_bounds_f", error, -1, total_error)

  !  Set valid offset for selection
  offset(1:2) = (/2,-2/)
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  !  Get bounds for point selection with offset
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL check("h5sget_select_bounds_f", error, total_error)

  CALL verify("h5sget_select_bounds_f", low_bounds(1), 5_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", low_bounds(2), 1_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(1), INT(SPACE11_DIM1-2,hsize_t), total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(2), INT(SPACE11_DIM2-6,hsize_t), total_error)

  !  Reset offset for selection
  offset(1:2) = 0
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  !  Set "regular" hyperslab selection
  start(1:2) = 2
  stride(1:2) = 10
  count(1:2) = 4
  block(1:2) = 5

  CALL h5sselect_hyperslab_f(sid, H5S_SELECT_SET_F, start, &
       count, error, stride, block)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  ! Get bounds for hyperslab selection
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL check("h5sget_select_bounds_f", error, total_error)

  CALL verify("h5sget_select_bounds_f", low_bounds(1), 3_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", low_bounds(2), 3_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(1), 37_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(2), 37_hsize_t, total_error)

  ! Set bad offset for selection
  offset(1:2) = (/5,-5/)
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  !  Get bounds for hyperslab selection with negative offset
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL verify("h5sget_select_bounds_f", error, -1, total_error)

  !  Set valid offset for selection
  offset(1:2) = (/5,-2/)
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  ! Get bounds for hyperslab selection with offset
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL check("h5sget_select_bounds_f", error, total_error)

  CALL verify("h5sget_select_bounds_f", low_bounds(1), 8_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", low_bounds(2), 1_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(1), 42_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(2), 35_hsize_t, total_error)

  ! Reset offset for selection
  offset(1:2) = 0
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  !  Make "irregular" hyperslab selection
  start(1:2) = 20
  stride(1:2) = 20
  count(1:2) = 2
  block(1:2) = 10

  CALL h5sselect_hyperslab_f(sid, H5S_SELECT_OR_F, start, &
       count, error, stride, block)
  CALL check("h5sselect_hyperslab_f", error, total_error)

  ! Get bounds for hyperslab selection
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL check("h5sget_select_bounds_f", error, total_error)

  CALL verify("h5sget_select_bounds_f", low_bounds(1), 3_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", low_bounds(2), 3_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(1), 50_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(2), 50_hsize_t, total_error)

  !  Set bad offset for selection
  offset(1:2) = (/5,-5/)
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  !  Get bounds for hyperslab selection with negative offset
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL verify("h5sget_select_bounds_f", error, -1, total_error)

  ! Set valid offset for selection
  offset(1:2) = (/5,-2/)
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  ! Get bounds for hyperslab selection with offset
  CALL h5sget_select_bounds_f(sid, low_bounds, high_bounds, error)
  CALL check("h5sget_select_bounds_f", error, total_error)

  CALL verify("h5sget_select_bounds_f", low_bounds(1), 8_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", low_bounds(2), 1_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(1), 55_hsize_t, total_error)
  CALL verify("h5sget_select_bounds_f", high_bounds(2), 48_hsize_t, total_error)

  ! Reset offset for selection
  offset(1:2) = 0
  CALL H5Soffset_simple_f(sid, offset, error)
  CALL check("H5Soffset_simple_f", error, total_error)

  ! Close the dataspace
  CALL h5sclose_f(sid, error)
  CALL check("h5sclose_f", error, total_error)

END SUBROUTINE test_select_bounds

END MODULE TH5SSELECT