summaryrefslogtreecommitdiffstats
path: root/fortran/test/tH5S.f90
blob: 7d64adacb4c83dfe1c926e42786c175abc9a6a38 (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
!
! 
!    Testing Dataspace Interface functionality.
!
!      MODULE H5STEST

!        USE HDF5 ! This module contains all necessary modules 
        
!      CONTAINS
      
!
!The following subroutine tests the following functionalities:
!h5screate_f, h5scopy_f, h5screate_simple_f, h5sis_simple_f,   
!h5sget_simple_extent_dims_f,h5sget_simple_extent_ndims_f 
!h5sget_simple_extent_npoints_f, h5sget_simple_extent_type_f,
!h5sextent_copy_f, h5sset_extent_simple_f, h5sset_extent_none_f     
!
        SUBROUTINE dataspace_basic_test(total_error)

        USE HDF5 ! This module contains all necessary modules 

          IMPLICIT NONE
          INTEGER, INTENT(OUT) :: total_error 

          CHARACTER(LEN=13), PARAMETER :: filename1 = "basicspace.h5" ! File1 name
          CHARACTER(LEN=12), PARAMETER :: filename2 = "copyspace.h5"  ! File2 name
          CHARACTER(LEN=9), PARAMETER :: dsetname = "basicdset"       ! Dataset name

          INTEGER(HID_T) :: file1_id, file2_id     ! File identifiers 
          INTEGER(HID_T) :: dset1_id, dset2_id     ! Dataset identifiers 
          INTEGER(HID_T) :: space1_id, space2_id   ! Dataspace identifiers

          INTEGER(HSIZE_T), DIMENSION(2) :: dims1 = (/4,6/) ! Dataset dimensions
          INTEGER(HSIZE_T), DIMENSION(2) :: maxdims1 = (/4,6/) ! maximum dimensions
          INTEGER(HSIZE_T), DIMENSION(2) :: dims2 = (/6,6/) ! Dataset dimensions
          INTEGER(HSIZE_T), DIMENSION(2) :: maxdims2 = (/6,6/) ! maximum dimensions
          INTEGER(HSIZE_T), DIMENSION(2) :: dimsout, maxdimsout ! dimensions
          INTEGER(HSIZE_T)   ::   npoints  !number of elements in the dataspace

          INTEGER     ::   rank1 = 2               ! Dataspace1 rank
          INTEGER     ::   rank2 = 2               ! Dataspace2 rank
          INTEGER     ::   classtype               ! Dataspace class type

          INTEGER, DIMENSION(4,6) :: data1_in, data1_out   ! Data input buffers
          INTEGER, DIMENSION(6,6) :: data2_in, data2_out  ! Data output buffers
          INTEGER     ::   error ! Error flag

          LOGICAL     ::   flag  !flag to test datyspace is simple or not
          INTEGER     :: i, j    !general purpose integers

          !
          ! Initialize the dset_data array.
          !
          do i = 1, 4
             do j = 1, 6
                data1_in(i,j) = (i-1)*6 + j;
             end do
          end do

          do i = 1, 6
             do j = 1, 6
                data2_in(i,j) = i*6 + j;
             end do
          end do

          !
          !  Initialize FORTRAN predefined datatypes.
          !
!          CALL h5init_types_f(error)
!              CALL check("h5init_types_f", error, total_error)
          
          !
          ! Create new files using default properties.
          ! 
          CALL h5fcreate_f(filename1, H5F_ACC_TRUNC_F, file1_id, error)
              CALL check("h5fcreate_f", error, total_error)

          CALL h5fcreate_f(filename2, H5F_ACC_TRUNC_F, file2_id, error)
              CALL check("h5fcreate_f", error, total_error)

          ! 
          ! Create dataspace for file1.
          !
          CALL h5screate_simple_f(rank1, dims1, space1_id, error, maxdims1)
              CALL check("h5screate_simple_f", error, total_error)
          ! 
          ! Copy space1_id to space2_id.
          !
          CALL h5scopy_f(space1_id, space2_id, error)
              CALL check("h5scopy_f", error, total_error)

          ! 
          !Check whether copied space is simple.
          !
          CALL h5sis_simple_f(space2_id, flag, error)
              CALL check("h5sissimple_f", error, total_error)
          IF (.NOT. flag) write(*,*) "dataspace is not simple type"
      
          ! 
          !set the copied space to none.
          !
          CALL h5sset_extent_none_f(space2_id, error)
              CALL check("h5sset_extent_none_f", error, total_error)
 
          ! 
          !copy the extent of space1_id to space2_id.
          !
          CALL h5sextent_copy_f(space2_id, space1_id, error) 
              CALL check("h5sextent_copy_f", error, total_error)

          ! 
          !get the copied space's dimensions.
          !
          CALL h5sget_simple_extent_dims_f(space2_id, dimsout, maxdimsout, error)
              CALL check("h5sget_simple_extent_dims_f", error, total_error)
          IF ((dimsout(1) .NE. dims1(1)) .OR. (dimsout(2) .NE. dims1(2)) ) THEN
              write(*,*)"error occured, copied dims not same" 
          END IF
   
          ! 
          !get the copied space's rank.
          !
          CALL h5sget_simple_extent_ndims_f(space2_id, rank2, error)
              CALL check("h5sget_simple_extent_ndims_f", error, total_error)
          IF (rank2 .NE. rank1) write(*,*)"error occured, copied ranks not same" 
   
          ! 
          !get the copied space's number of elements.
          !
          CALL h5sget_simple_extent_npoints_f(space2_id, npoints, error)
              CALL check("h5sget_simple_extent_npoints_f", error, total_error)
          IF (npoints .NE. 24) write(*,*)"error occured, number of elements not correct"


          ! 
          !get the copied space's class type.
          !
          CALL h5sget_simple_extent_type_f(space2_id, classtype, error)   
              CALL check("h5sget_simple_extent_type_f", error, total_error)
          IF (classtype .NE. 1) write(*,*)"class type not H5S_SIMPLE_f"

          ! 
          !set the copied space to dim2 size.
          !
          CALL h5sset_extent_simple_f(space2_id, rank2, dims2, maxdims2, error)
              CALL check("h5sset_extent_simple_f", error, total_error)

          ! 
          !get the copied space's dimensions.
          !
          CALL h5sget_simple_extent_dims_f(space2_id, dimsout, maxdimsout, error)
              CALL check("h5sget_simple_extent_dims_f", error, total_error)
          IF ((dimsout(1) .NE. dims2(1)) .OR. (dimsout(2) .NE. dims2(2)) ) THEN
              write(*,*)"error occured, copied dims not same"
          END IF 

          !
          ! Create the datasets with default properties in two files.
          !
          CALL h5dcreate_f(file1_id, dsetname, H5T_NATIVE_INTEGER, space1_id, &
                           dset1_id, error)
              CALL check("h5dcreate_f", error, total_error)

          CALL h5dcreate_f(file2_id, dsetname, H5T_NATIVE_INTEGER, space2_id, &
                           dset2_id, error)
              CALL check("h5dcreate_f", error, total_error)

          !
          ! Write the datasets.
          !
          CALL h5dwrite_f(dset1_id, H5T_NATIVE_INTEGER, data1_in, error)
              CALL check("h5dwrite_f", error, total_error)

          CALL h5dwrite_f(dset2_id, H5T_NATIVE_INTEGER, data2_in, error)
              CALL check("h5dwrite_f", error, total_error)

          !
          ! Read the first dataset.
          !
          CALL h5dread_f(dset1_id, H5T_NATIVE_INTEGER, data1_out, error)
              CALL check("h5dread_f", error, total_error)

          !
          !Compare the data.
          ! 
          do i = 1, 4
              do j = 1, 6
                  IF (data1_out(i,j) .NE. data1_in(i, j)) THEN 
                      write(*, *) "dataset test error occured"
                      write(*,*) "data read is not the same as the data writen"
                  END IF
              end do    
          end do


          !
          ! Read the second dataset.
          !
          CALL h5dread_f(dset2_id, H5T_NATIVE_INTEGER, data2_out, error)
              CALL check("h5dread_f", error, total_error)

          !
          !Compare the data.
          ! 
          do i = 1, 6
              do j = 1, 6
                  IF (data2_out(i,j) .NE. data2_in(i, j)) THEN 
                      write(*, *) "dataset test error occured"
                      write(*,*) "data read is not the same as the data writen"
                  END IF
              end do    
          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)

          !
          ! Terminate access to the data spaces.
          !
          CALL h5sclose_f(space1_id, error)
              CALL check("h5sclose_f", error, total_error)
          CALL h5sclose_f(space2_id, error)
              CALL check("h5sclose_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)
     
         !
         !Close FORTRAN predifined datatypes
         !
!         CALL h5close_types_f(error)
!              CALL check("h5close_types_f",error,total_error)

          RETURN
        END SUBROUTINE dataspace_basic_test


!      END MODULE H5STEST