summaryrefslogtreecommitdiffstats
path: root/fortran/test/tH5I.f90
blob: 088b4eb7af1db7060e0130db1310181f14c0f9cf (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
!****h* root/fortran/test/tH5I.f90
!
! NAME
!  tH5I.f90
!
! FUNCTION
!  Basic testing of Fortran H5I 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 files COPYING and Copyright.html.  COPYING can be found at the root   *
!   of the source code distribution tree; Copyright.html can be found at the  *
!   root level of an installed copy of the electronic HDF5 document set and   *
!   is linked from the top-level documents page.  It can also be found at     *
!   http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
!   access to either file, you may request a copy from help@hdfgroup.org.     *
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
!
! CONTAINS SUBROUTINES
!  identifier_test
!
!*****
MODULE TH5I

CONTAINS

    SUBROUTINE identifier_test(cleanup, total_error)

!   This subroutine tests following functionalities: h5iget_type_f

   USE HDF5 ! This module contains all necessary modules
   USE TH5_MISC

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

     CHARACTER(LEN=6), PARAMETER :: filename = "itestf" ! File name
     CHARACTER(LEN=80) :: fix_filename
     CHARACTER(LEN=10), PARAMETER :: dsetname = "/itestdset" ! Dataset name
     CHARACTER(LEN=10), PARAMETER :: groupname = "itestgroup"! group name
     CHARACTER(LEN=10), PARAMETER :: aname = "itestattr"! group name



     INTEGER(HID_T) :: file_id       ! File identifier
     INTEGER(HID_T) :: new_file_id   ! File identifier
     INTEGER(HID_T) :: group_id      ! group identifier
     INTEGER(HID_T) :: dset_id       ! Dataset identifier
     INTEGER(HID_T) :: dspace_id     ! Dataspace identifier
     INTEGER(HID_T) :: attr_id      ! Datatype attribute identifier
     INTEGER(HID_T) :: aspace_id     ! attribute data space identifier
     INTEGER(HID_T) :: atype_id     ! attribute data type identifier


     INTEGER, DIMENSION(1) :: dset_data = 0 ! Data value

     INTEGER(HSIZE_T), DIMENSION(1) :: dims = 1 ! Datasets dimensions
     INTEGER(HSIZE_T), DIMENSION(1) :: adims = 1 ! Attribute dimensions

     INTEGER, DIMENSION(1) ::  attr_data = 12
     INTEGER     ::   rank = 1 ! Datasets rank
     INTEGER     ::   arank = 1 ! Attribute rank

     INTEGER     ::   type !object identifier
     INTEGER     ::   error ! Error flag
     INTEGER(HSIZE_T), DIMENSION(2) :: data_dims
     CHARACTER(LEN=80) name_buf
     CHARACTER(LEN=280) name_buf1
     INTEGER(SIZE_T)   buf_size
     INTEGER(SIZE_T)   name_size
     INTEGER    ::    ref_count ! Reference count for IDs


     INTEGER(hid_t) :: dtype  ! datatype id
     LOGICAL :: tri_ret       ! value

     !
     ! Tests the function H5Iis_valid_f
     !
     ! check that the ID is not valid
     dtype = -1
     CALL H5Iis_valid_f(dtype, tri_ret, error)
     CALL check("H5Iis_valid_f", error, total_error) 
     CALL VerifyLogical("H5Iis_valid_f", tri_ret, .FALSE., total_error)
     
     ! Create a datatype id
     CALL H5Tcopy_f(H5T_NATIVE_INTEGER,dtype,error)
     CALL check("H5Tcopy_f", error, total_error) 
     
     ! Check that the ID is valid
     CALL H5Iis_valid_f(dtype, tri_ret, error)
     CALL check("H5Iis_valid_f", error, total_error) 
     CALL VerifyLogical("H5Tequal_f", tri_ret, .TRUE., total_error)
     
     CALL H5Tclose_f(dtype, error)
     CALL check("H5Tclose_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 a group named "/MyGroup" in the file.
     !
     CALL h5gcreate_f(file_id, groupname, group_id, error)
     CALL check("h5gcreate_f",error,total_error)

     !
     !Create data space for the dataset.
     !
     CALL h5screate_simple_f(rank, dims, dspace_id, error)
     CALL check("h5screate_simple_f",error,total_error)

     !
     ! create dataset in the file.
     !
     CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dspace_id, &
               dset_id, error)
     CALL check("h5dcreate_f",error,total_error)
     !
     ! Get dataset name from dataset identifier
     !
     buf_size = 80
     CALL h5iget_name_f(dset_id, name_buf, buf_size, name_size, error)
     CALL check("h5iget_name_f",error,total_error)
      if (name_size .ne. len(dsetname)) then
          write(*,*) "h5iget_name returned wrong name size"
          total_error = total_error + 1
      else
          if (name_buf(1:name_size) .ne. dsetname) then
              write(*,*) "h5iget_name returned wrong name"
              total_error = total_error + 1
          endif
      endif

     !
     ! Get file identifier from dataset identifier and then get file name
     !
     CALL h5iget_file_id_f(dset_id, new_file_id, error)
     CALL check("h5iget_file_id_f",error,total_error)
     name_size = 280
     CALL h5fget_name_f(new_file_id, name_buf1, name_size, error)
     CALL check("h5fget_name_f",error,total_error)
          if (name_buf1(1:name_size) .ne. fix_filename(1:name_size)) then
              write(*,*) "h5fget_name returned wrong file name"
              total_error = total_error + 1
          endif

     !
     ! Write data_in to the dataset
     !
     data_dims(1) = 1
     CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, dset_data, data_dims, error)
     CALL check("h5dwrite_f",error,total_error)

     !
     ! Create scalar data space for dataset attribute.
     !
     CALL h5screate_simple_f(arank, adims, aspace_id, error)
     CALL check("h5screate_simple_f",error,total_error)

     !
     ! Create datatype for the Integer attribute.
     !
     CALL h5tcopy_f(H5T_NATIVE_INTEGER, atype_id, error)
     CALL check("h5tcopy_f",error,total_error)

     !
     ! Create dataset INTEGER attribute.
     !
     CALL h5acreate_f(dset_id, aname, atype_id, aspace_id, attr_id, error)
     CALL check("h5acreate_f",error,total_error)

     !
     ! Write the Integer attribute data.
     !
     CALL h5awrite_f(attr_id, atype_id, attr_data, data_dims, error)
     CALL check("h5awrite_f",error,total_error)

     !
     !Get the file identifier
     !
     CALL h5iget_type_f(file_id, type, error)
     CALL check("h5iget_type_f",error,total_error)
     CALL verify("get file identifier wrong",type,H5I_FILE_F,total_error)

     !
     !Get the group identifier
     !
     CALL h5iget_type_f(group_id, type, error)
     CALL check("h5iget_type_f",error,total_error)
     CALL verify("get group identifier wrong",type,H5I_GROUP_F,total_error)

     !
     !Get the datatype identifier
     !
     CALL h5iget_type_f(atype_id, type, error)
     CALL check("h5iget_type_f",error,total_error)
     CALL verify("get datatype identifier wrong",type,H5I_DATATYPE_F,total_error)

     !
     !Get the dataspace identifier
     !
     CALL h5iget_type_f(aspace_id, type, error)
     CALL check("h5iget_type_f",error,total_error)
     CALL verify("get dataspace identifier wrong",type,H5I_DATASPACE_F,total_error)

     !
     !Get the dataset identifier
     !
     CALL h5iget_type_f(dset_id, type, error)
     CALL check("h5iget_type_f",error,total_error)
     CALL verify("get dataset identifier wrong",type,H5I_DATASET_F,total_error)

     !
     !Get the attribute identifier
     !
     CALL h5iget_type_f(attr_id, type, error)
     CALL check("h5iget_type_f",error,total_error)
     CALL verify("get attribute identifier wrong",type,H5I_ATTR_F,total_error)

     !
     ! Close the attribute.
     !
     CALL h5aclose_f(attr_id, error)
     CALL check("h5aclose_f",error,total_error)
     !
     ! Close the dataspace.
     !
     CALL h5sclose_f(aspace_id, error)
     CALL check("h5sclose_f",error,total_error)
     CALL h5sclose_f(dspace_id, error)
     CALL check("h5sclose_f",error,total_error)
     !
     ! Close the dataype.
     !
     CALL h5tclose_f(atype_id, error)
     CALL check("h5tclose_f",error,total_error)

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

     !
     ! Close the group.
     !
     CALL h5gclose_f(group_id, error)
     CALL check("h5gclose_f",error,total_error)

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

     !
     ! Basic Test of increment/decrement ID functions
     !

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

     ! Get the reference count for the file ID
     CALL h5iget_ref_f(file_id, ref_count, error)
     CALL check("h5iget_ref_f",error,total_error)
     CALL verify("get file ref count wrong",ref_count,1,total_error)

     ! Increment the reference count for the file ID
     CALL h5iinc_ref_f(file_id, ref_count, error)
     CALL check("h5iinc_ref_f",error,total_error)
     CALL verify("get file ref count wrong",ref_count,2,total_error)

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

     ! Get the reference count for the file ID
     CALL h5iget_ref_f(file_id, ref_count, error)
     CALL check("h5iget_ref_f",error,total_error)
     CALL verify("get file ref count wrong",ref_count,1,total_error)

     ! Close the file by decrementing the reference count
     CALL h5idec_ref_f(file_id, ref_count, error)
     CALL check("h5idec_ref_f",error,total_error)
     CALL verify("get file ref count wrong",ref_count,0,total_error)
     ! Try closing the file again (should fail)
     CALL h5eset_auto_f(0, error)
     CALL h5fclose_f(file_id, error)
     CALL verify("file close should fail",error,-1,total_error)
     ! Clear the error stack from the file close failure
     CALL h5eset_auto_f(1, error)
     CALL h5eclear_f(error)

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

     RETURN
     END SUBROUTINE identifier_test

END MODULE TH5I