summaryrefslogtreecommitdiffstats
path: root/hl/fortran/src/H5DSff.F90
blob: 2dca47989977f3f09eb036cb46164665a78d945a (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
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
!   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.                                                        *
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
!
!
! This file contains FORTRAN90 interfaces for H5DS functions
!

MODULE h5ds

  USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_PTR, C_CHAR, C_FLOAT, C_DOUBLE, C_LOC, C_CHAR
  USE h5fortran_types
  USE hdf5

CONTAINS

!-------------------------------------------------------------------------
! Function: H5DSset_scale_f
!
! Purpose: Convert dataset dsid to a dimension scale, with optional name, dimname. 
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 17, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSset_scale_f( dsid, errcode, dimname)

    IMPLICIT NONE

    INTEGER(hid_t),   INTENT(in) :: dsid               ! The dataset to be made a Dimension Scale
    CHARACTER(LEN=*), INTENT(in), OPTIONAL :: dimname  ! The dimension name
    INTEGER :: errcode                                 ! Error code

    INTEGER(SIZE_T) :: dimname_len                     ! length of dimname (if present)

    INTERFACE
       INTEGER FUNCTION H5DSset_scale_c(dsid, dimname, dimname_len) &
            BIND(C,NAME='h5dsset_scale_c')
         IMPORT :: C_CHAR
         IMPORT :: HID_T, SIZE_T
         IMPLICIT NONE
         INTEGER(hid_t),   INTENT(in) :: dsid     ! The dataset to be made a Dimension Scale
         CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(in) :: dimname  ! The dimension name
         INTEGER(SIZE_T),  INTENT(in) :: dimname_len
       END FUNCTION H5DSset_scale_c
    END INTERFACE

    IF(PRESENT(dimname))THEN
       dimname_len = LEN(dimname)
       errcode = H5DSset_scale_c(dsid, dimname, dimname_len )
    ELSE
       errcode = H5DSset_scale_c(dsid, " ", INT(0,SIZE_T) )
    ENDIF

  END SUBROUTINE H5DSset_scale_f

!-------------------------------------------------------------------------
! Function: H5DSattach_scale_f
!
! Purpose: Attach dimension scale dsid to dimension idx of dataset did.
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 17, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSattach_scale_f( did, dsid, idx, errcode)

    IMPLICIT NONE

    INTEGER(hid_t), INTENT(in) :: did     ! the dataset
    INTEGER(hid_t), INTENT(in) :: dsid    ! the scale to be attached 
    INTEGER       , INTENT(in) :: idx     ! the dimension of did that dsid is associated with.
    INTEGER                    :: errcode ! error code
    INTEGER                    :: c_idx
    
    INTERFACE
       INTEGER FUNCTION  H5DSattach_scale_c(did, dsid, idx) &
            BIND(C,NAME='h5dsattach_scale_c') 
         IMPORT :: HID_T
         IMPLICIT NONE
         INTEGER(hid_t), INTENT(in) :: did     ! the dataset
         INTEGER(hid_t), INTENT(in) :: dsid    ! the scale to be attached 
         INTEGER       , INTENT(in) :: idx     ! the dimension of did that dsid is associated with.
       END FUNCTION H5DSattach_scale_c
    END INTERFACE

    c_idx = idx -1 ! account for C-dimensions starting at 0 
    
    errcode = H5DSattach_scale_c( did, dsid, c_idx)
    
  END SUBROUTINE H5DSattach_scale_f
  
!-------------------------------------------------------------------------
! Function: H5DSdetach_scale_f
!
! Purpose: Detach dimension scale dsid from the dimension idx of Dataset did.
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 17, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSdetach_scale_f( did, dsid, idx, errcode)
    
    IMPLICIT NONE

    INTEGER(hid_t), INTENT(in) :: did     ! the dataset
    INTEGER(hid_t), INTENT(in) :: dsid    ! the scale to be detached 
    INTEGER       , INTENT(in) :: idx     ! the dimension of did to detach
    INTEGER                    :: errcode ! error code
    INTEGER                    :: c_idx
    
    INTERFACE
       INTEGER FUNCTION  H5DSdetach_scale_c(did, dsid, idx) &
            BIND(C,NAME='h5dsdetach_scale_c')
         IMPORT :: HID_T
         IMPLICIT NONE
         INTEGER(hid_t), INTENT(in) :: did     ! the dataset
         INTEGER(hid_t), INTENT(in) :: dsid    ! the scale to be detached 
         INTEGER       , INTENT(in) :: idx     ! the dimension of did to detach
       END FUNCTION H5DSdetach_scale_c
    END INTERFACE

    c_idx = idx - 1 ! account for C-dimensions starting at 0 

    errcode = H5DSdetach_scale_c( did, dsid, c_idx)
    
  END SUBROUTINE H5DSdetach_scale_f


!-------------------------------------------------------------------------
! Function: H5DSis_attached_f
!
! Purpose: Report if dimension scale dsid is currently attached to dimension idx of dataset did. 
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 17, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSis_attached_f( did, dsid, idx, is_attached, errcode)
    
    IMPLICIT NONE

    INTEGER(hid_t), INTENT(in)  :: did         ! the dataset
    INTEGER(hid_t), INTENT(in)  :: dsid        ! the scale to be attached
    INTEGER       , INTENT(in)  :: idx         ! the dimension of did that dsid is associated with
    LOGICAL       , INTENT(out) :: is_attached ! logical: dimension scale dsid is currently attached to 
                                               ! dimension idx of dataset did
    INTEGER                     :: errcode     ! error code
    INTEGER                     :: c_is_attached
    INTEGER                     :: c_idx
    
    INTERFACE
       INTEGER FUNCTION H5DSis_attached_c(did, dsid, idx, c_is_attached) &
            BIND(C,NAME='h5dsis_attached_c')
         IMPORT :: HID_T
         IMPLICIT NONE
         INTEGER(hid_t), INTENT(in)  :: did         ! the dataset
         INTEGER(hid_t), INTENT(in)  :: dsid        ! the scale to be detached 
         INTEGER       , INTENT(in)  :: idx         ! the dimension of did to detach
         INTEGER       , INTENT(out) :: c_is_attached ! dimension scale dsid is currently attached to 
       END FUNCTION H5DSis_attached_c
    END INTERFACE

    c_idx = idx - 1 ! account for C-dimensions starting at 0 
    
    errcode = H5DSis_attached_c(did, dsid, c_idx, c_is_attached)

    is_attached = .FALSE. ! default
    IF(c_is_attached.GT.0)THEN
       is_attached = .TRUE.
    ELSE IF(errcode.LT.0)THEN
       errcode = -1
    ENDIF
    
  END SUBROUTINE H5DSis_attached_f

!
! H5DSiterate_scales: Impliment in  F2003
!

!-------------------------------------------------------------------------
! Function: H5DSis_scale_f
!
! Purpose: Determines whether dset is a Dimension Scale. 
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 18, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSis_scale_f( did, is_scale, errcode)
    
    IMPLICIT NONE

    INTEGER(hid_t), INTENT(in)  :: did         ! the data set to query
    LOGICAL       , INTENT(out) :: is_scale    ! logical:  
                                               ! .TRUE. if did is a Dimension Scale
    INTEGER                     :: errcode     ! error code
    INTEGER                     :: c_is_scale
    
    INTERFACE
       INTEGER FUNCTION H5DSis_scale_c(did,c_is_scale) &
            BIND(C,NAME='h5dsis_scale_c')
         IMPORT :: HID_T
         IMPLICIT NONE
         INTEGER(hid_t), INTENT(in) :: did
         INTEGER, INTENT(out) :: c_is_scale
       END FUNCTION H5DSis_scale_c
    END INTERFACE
    
    errcode = H5DSis_scale_c(did, c_is_scale)

    is_scale = .FALSE. ! default
    IF(c_is_scale.GT.0)THEN
       is_scale = .TRUE.
    ELSE IF(errcode.LT.0)THEN
       errcode = -1
    ENDIF
    
  END SUBROUTINE H5DSis_scale_f

!-------------------------------------------------------------------------
! Function: H5DSset_label_f
!
! Purpose: Set label for the dimension idx of did to the value label
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 18, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSset_label_f( did, idx, label, errcode)

    IMPLICIT NONE

    INTEGER(hid_t),   INTENT(in) :: did    ! The dataset
    INTEGER       ,   INTENT(in) :: idx    ! The dimension
    CHARACTER(LEN=*), INTENT(in) :: label  ! The label
    INTEGER :: errcode                     ! Error code

    INTEGER(SIZE_T) :: label_len  ! Length of label
    INTEGER :: c_idx

    INTERFACE
       INTEGER FUNCTION H5DSset_label_c(did, idx, label, label_len) &
            BIND(C,NAME='h5dsset_label_c')
         IMPORT :: C_CHAR
         IMPORT :: HID_T, SIZE_T
         IMPLICIT NONE
         INTEGER(hid_t),   INTENT(in) :: did        ! The dataset
         INTEGER       ,   INTENT(in) :: idx        ! The dimension
         CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(in) :: label      ! The label
         INTEGER(SIZE_T),  INTENT(in) :: label_len  ! Length of label
       END FUNCTION H5DSset_label_c
    END INTERFACE

    c_idx = idx - 1

    label_len = LEN(label)
    errcode = H5DSset_label_c(did, c_idx, label, label_len)

  END SUBROUTINE H5DSset_label_f

!-------------------------------------------------------------------------
! Function: H5DSget_label_f
!
! Purpose: Read the label for dimension idx of did into buffer label. 
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 18, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSget_label_f( did, idx, label, size, errcode)

    IMPLICIT NONE

    INTEGER(hid_t),   INTENT(in) :: did     ! The dataget
    INTEGER       ,   INTENT(in) :: idx     ! The dimension
    CHARACTER(LEN=*), INTENT(in) :: label   ! The label
    INTEGER(size_t) , INTENT(inout) :: size ! The length of the label buffer
    INTEGER :: errcode                      ! Error code
    INTEGER :: c_idx

    INTERFACE
       INTEGER FUNCTION H5DSget_label_c(did, idx, label, size) &
            BIND(C,NAME='h5dsget_label_c')
         IMPORT :: C_CHAR
         IMPORT :: HID_T, SIZE_T
         IMPLICIT NONE
         INTEGER(hid_t),   INTENT(in)    :: did        ! The dataget
         INTEGER       ,   INTENT(in)    :: idx        ! The dimension
         CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(in) :: label      ! The label
         INTEGER(SIZE_T),  INTENT(inout) :: size       ! Length of label
       END FUNCTION H5DSget_label_c
    END INTERFACE

    c_idx = idx - 1

    errcode = H5DSget_label_c(did, c_idx, label, size)

  END SUBROUTINE H5DSget_label_f


!-------------------------------------------------------------------------
! Function: H5DSget_scale_name_f
!
! Purpose: Read the name of scale did into buffer name.
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 18, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSget_scale_name_f(did, name, size, errcode)

    IMPLICIT NONE

    INTEGER(hid_t),   INTENT(in) :: did     ! The dataget
    CHARACTER(LEN=*), INTENT(out) :: name   ! The name
    INTEGER(size_t) , INTENT(inout) :: size ! The length of the name buffer
    INTEGER :: errcode                      ! Error code

    INTERFACE
       INTEGER FUNCTION H5DSget_scale_name_c(did, name, size) &
            bind(c,name='h5dsget_scale_name_c')
         IMPORT :: C_CHAR
         IMPORT :: HID_T, SIZE_T
         IMPLICIT NONE
         INTEGER(hid_t),   INTENT(in)    :: did       ! The dataget
         CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(out) :: name      ! The name
         INTEGER(SIZE_T),  INTENT(inout) :: size      ! Length of name
       END FUNCTION H5DSget_scale_name_c
    END INTERFACE

    errcode = H5DSget_scale_name_c(did, name, size)

  END SUBROUTINE H5DSget_scale_name_f

!-------------------------------------------------------------------------
! Function: H5DSget_num_scales_f
!
! Purpose: Determines how many Dimension Scales are attached to dimension idx of did
!
! Return: Success: 0, Failure: -1
!
! Programmer: M. Scot Breitenfeld
!
! Date: April 18, 2011
!
! Comments:
!
! Modifications:
!
!-------------------------------------------------------------------------

  SUBROUTINE H5DSget_num_scales_f( did, idx, num_scales, errcode)

    IMPLICIT NONE
    INTEGER(hid_t), INTENT(in)  :: did         ! the dataset
    INTEGER       , INTENT(in)  :: idx         ! the dimension of did to query
    INTEGER       , INTENT(out) :: num_scales  ! the number of Dimension Scales associated with did
    INTEGER                     :: errcode     ! error code
    INTEGER                     :: c_idx
    
    INTERFACE
       INTEGER FUNCTION H5DSget_num_scales_c(did, idx, num_scales) &
            BIND(C,NAME='h5dsget_num_scales_c')
         IMPORT :: HID_T
         IMPLICIT NONE
         INTEGER(hid_t), INTENT(in)  :: did        ! the dataset
         INTEGER       , INTENT(in)  :: idx        ! the dimension of did to query
         INTEGER       , INTENT(out) :: num_scales ! the number of Dimension Scales associated with did
       END FUNCTION H5DSget_num_scales_c
    END INTERFACE
    
    c_idx = idx - 1
    errcode = H5DSget_num_scales_c(did, c_idx, num_scales)
    
  END SUBROUTINE H5DSget_num_scales_f

END MODULE h5ds