18 h5aclose_f, h5acreate_f, h5aopen_f, h5aread_f, h5awrite_f, h5close_f, h5dclose_f, &
19 h5dcreate_f, h5dget_space_f, h5dopen_f, h5dread_f, h5dwrite_f, h5f_acc_rdonly_f, h5f_acc_rdwr_f, &
20 h5f_acc_trunc_f, h5fclose_f, h5fcreate_f, h5fopen_f, h5gclose_f, h5gcreate_f, h5gopen_f, &
21 h5open_f, h5s_scalar_f, h5sclose_f, h5screate_f, h5screate_simple_f, &
22 h5sget_simple_extent_npoints_f, h5t_c_s1, h5t_cset_utf8_f, h5t_enum_f, h5t_native_double, &
23 h5t_native_integer, h5t_str_nullpad_f, h5t_string, h5tclose_f, h5tcopy_f, h5tcreate_f, &
24 h5tenum_insert_f, h5tset_cset_f, h5tset_size_f, h5tset_strpad_f, hid_t, hsize_t, size_t
25#if defined(__parallel)
26 USE hdf5,
ONLY: h5pcreate_f, h5pclose_f, h5p_file_access_f, h5p_default_f, h5pset_fapl_mpio_f
29 USE iso_c_binding,
ONLY: c_loc, &
34#include "./base/base_uses.f90"
38 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'hdf5_wrapper'
40 INTEGER,
PARAMETER,
PUBLIC :: hdf5_id = hid_t
53 IF (error < 0) cpabort(
'ERROR: failed to initialize HDF5 interface')
64 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 interface')
66 END SUBROUTINE h5close
73 SUBROUTINE h5fcreate(filename, file_id)
74 CHARACTER(LEN=*),
INTENT(IN) :: filename
75 INTEGER(KIND=hid_t),
INTENT(OUT) :: file_id
78#if defined(__parallel)
79 INTEGER(KIND=hid_t) :: plist_id
82#if defined(__parallel)
83 CALL h5pcreate_f(h5p_file_access_f, plist_id, error)
85 CALL h5fcreate_f(filename, h5f_acc_trunc_f, file_id, error, access_prp=plist_id)
86 CALL h5pclose_f(plist_id, error)
88 CALL h5fcreate_f(filename, h5f_acc_trunc_f, file_id, error)
91 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 file')
93 END SUBROUTINE h5fcreate
100 SUBROUTINE h5fopen(filename, file_id)
101 CHARACTER(LEN=*),
INTENT(IN) :: filename
102 INTEGER(KIND=hid_t),
INTENT(OUT) :: file_id
105#if defined(__parallel)
106 INTEGER(KIND=hid_t) :: plist_id
109#if defined(__parallel)
110 CALL h5pcreate_f(h5p_file_access_f, plist_id, error)
112 CALL h5fopen_f(filename, h5f_acc_rdwr_f, file_id, error, access_prp=plist_id)
113 CALL h5pclose_f(plist_id, error)
115 CALL h5fopen_f(filename, h5f_acc_rdwr_f, file_id, error)
118 IF (error < 0) cpabort(
'ERROR: failed to open HDF5 file')
120 END SUBROUTINE h5fopen
126 SUBROUTINE h5fclose(file_id)
127 INTEGER(KIND=hid_t),
INTENT(IN) :: file_id
131 CALL h5fclose_f(file_id, error)
132 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 file')
134 END SUBROUTINE h5fclose
142 SUBROUTINE h5gcreate(loc_id, name, grp_id)
143 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
144 CHARACTER(LEN=*),
INTENT(IN) :: name
145 INTEGER(KIND=hid_t),
INTENT(OUT) :: grp_id
149 CALL h5gcreate_f(loc_id, name, grp_id, error)
150 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 group')
152 END SUBROUTINE h5gcreate
160 SUBROUTINE h5gopen(loc_id, name, grp_id)
161 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
162 CHARACTER(LEN=*),
INTENT(IN) :: name
163 INTEGER(KIND=hid_t),
INTENT(OUT) :: grp_id
167 CALL h5gopen_f(loc_id, name, grp_id, error)
168 IF (error < 0) cpabort(
'ERROR: failed to open HDF5 group')
170 END SUBROUTINE h5gopen
176 SUBROUTINE h5gclose(grp_id)
177 INTEGER(KIND=hid_t),
INTENT(IN) :: grp_id
181 CALL h5gclose_f(grp_id, error)
182 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 group')
184 END SUBROUTINE h5gclose
192 SUBROUTINE h5awrite_varlen_string(loc_id, attr_name, attr_data)
193 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
194 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
195 CHARACTER(LEN=*),
INTENT(IN),
TARGET :: attr_data
197 INTEGER :: error, output_unit
198 INTEGER(KIND=hid_t) :: attr_id, space_id, type_id
199 TYPE(c_ptr) :: buffer
200 TYPE(c_ptr),
TARGET :: in_between_ptr
205 CALL h5screate_f(h5s_scalar_f, space_id, error)
207 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
208 ' ERROR: failed to create HDF5 dataspace'
213 CALL h5tcopy_f(h5t_string, type_id, error)
214 CALL h5tset_cset_f(type_id, h5t_cset_utf8_f, error)
215 CALL h5tset_strpad_f(type_id, h5t_str_nullpad_f, error)
218 CALL h5acreate_f(loc_id, attr_name, type_id, space_id, attr_id, error)
220 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
221 ' ERROR: failed to create HDF5 attribute'
227 in_between_ptr = c_loc(attr_data)
229 buffer = c_loc(in_between_ptr)
232 CALL h5awrite_f(attr_id, type_id, buffer, error)
234 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
235 ' ERROR: failed to write HDF5 attribute'
240 CALL h5aclose_f(attr_id, error)
242 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
243 ' ERROR: failed to close HDF5 attribute'
248 CALL h5sclose_f(space_id, error)
250 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
251 ' ERROR: failed to close HDF5 dataspace'
256 CALL h5tclose_f(type_id, error)
258 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
259 ' ERROR: failed to close HDF5 datatype'
263 END SUBROUTINE h5awrite_varlen_string
271 SUBROUTINE h5awrite_fixlen_string(loc_id, attr_name, attr_data)
272 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
273 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
274 CHARACTER(LEN=*),
INTENT(IN),
TARGET :: attr_data
276 INTEGER :: error, output_unit
277 INTEGER(KIND=hid_t) :: attr_id, space_id, type_id
278 TYPE(c_ptr) :: buffer
283 CALL h5screate_f(h5s_scalar_f, space_id, error)
285 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
286 ' ERROR: failed to create HDF5 dataspace'
291 CALL h5tcopy_f(h5t_c_s1, type_id, error)
292 CALL h5tset_cset_f(type_id, h5t_cset_utf8_f, error)
293 CALL h5tset_size_f(type_id, len(attr_data, size_t), error)
296 CALL h5acreate_f(loc_id, attr_name, type_id, space_id, attr_id, error)
298 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
299 ' ERROR: failed to create HDF5 attribute'
304 buffer = c_loc(attr_data)
307 CALL h5awrite_f(attr_id, type_id, buffer, error)
309 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
310 ' ERROR: failed to write HDF5 attribute'
315 CALL h5aclose_f(attr_id, error)
317 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
318 ' ERROR: failed to close HDF5 attribute'
323 CALL h5sclose_f(space_id, error)
325 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
326 ' ERROR: failed to close HDF5 dataspace'
331 CALL h5tclose_f(type_id, error)
333 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
334 ' ERROR: failed to close HDF5 datatype'
338 END SUBROUTINE h5awrite_fixlen_string
346 SUBROUTINE h5awrite_boolean(loc_id, attr_name, attr_data)
347 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
348 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
349 LOGICAL,
INTENT(IN) :: attr_data
351 INTEGER :: error, output_unit
352 INTEGER(KIND=hid_t) :: attr_id, space_id, type_id
353 INTEGER,
TARGET :: attr_data_to_int
354 TYPE(c_ptr) :: buffer
361 CALL h5screate_f(h5s_scalar_f, space_id, error)
363 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
364 ' ERROR: failed to create HDF5 dataspace'
369 CALL h5tcreate_f(h5t_enum_f, int(1, size_t), type_id, error)
370 CALL h5tenum_insert_f(type_id,
"FALSE", 0, error)
371 CALL h5tenum_insert_f(type_id,
"TRUE", 1, error)
379 buffer = c_loc(attr_data_to_int)
382 CALL h5acreate_f(loc_id, attr_name, type_id, space_id, attr_id, error)
384 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
385 ' ERROR: failed to create HDF5 attribute'
390 CALL h5awrite_f(attr_id, type_id, buffer, error)
392 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
393 ' ERROR: failed to write HDF5 attribute'
398 CALL h5aclose_f(attr_id, error)
400 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
401 ' ERROR: failed to close HDF5 attribute'
406 CALL h5sclose_f(space_id, error)
408 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
409 ' ERROR: failed to close HDF5 dataspace'
414 CALL h5tclose_f(type_id, error)
416 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
417 ' ERROR: failed to close HDF5 datatype'
421 END SUBROUTINE h5awrite_boolean
429 SUBROUTINE h5awrite_integer_scalar(loc_id, attr_name, attr_data)
430 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
431 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
432 INTEGER,
INTENT(IN),
TARGET :: attr_data
434 INTEGER :: error, output_unit
435 INTEGER(KIND=hid_t) :: attr_id, space_id, type_id
436 TYPE(c_ptr) :: buffer
441 CALL h5screate_f(h5s_scalar_f, space_id, error)
443 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
444 ' ERROR: failed to create HDF5 dataspace'
449 buffer = c_loc(attr_data)
452 type_id = h5t_native_integer
455 CALL h5acreate_f(loc_id, attr_name, type_id, space_id, attr_id, error)
457 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
458 ' ERROR: failed to create HDF5 attribute'
463 CALL h5awrite_f(attr_id, type_id, buffer, error)
465 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
466 ' ERROR: failed to write HDF5 attribute'
471 CALL h5aclose_f(attr_id, error)
473 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
474 ' ERROR: failed to close HDF5 attribute'
479 CALL h5sclose_f(space_id, error)
481 WRITE (unit=output_unit, fmt=
"(/,T5,A,/)") &
482 ' ERROR: failed to close HDF5 dataspace'
486 END SUBROUTINE h5awrite_integer_scalar
494 SUBROUTINE h5awrite_double_scalar(loc_id, attr_name, attr_data)
495 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
496 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
497 REAL(KIND=
dp),
INTENT(IN),
TARGET :: attr_data
500 INTEGER(KIND=hid_t) :: attr_id, space_id, type_id
501 TYPE(c_ptr) :: buffer
504 CALL h5screate_f(h5s_scalar_f, space_id, error)
505 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 dataspace')
508 buffer = c_loc(attr_data)
511 type_id = h5t_native_double
514 CALL h5acreate_f(loc_id, attr_name, type_id, space_id, attr_id, error)
515 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 attribute')
518 CALL h5awrite_f(attr_id, type_id, buffer, error)
519 IF (error < 0) cpabort(
'ERROR: failed to write HDF5 attribute')
522 CALL h5aclose_f(attr_id, error)
523 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 attribute')
526 CALL h5sclose_f(space_id, error)
527 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 dataspace')
529 END SUBROUTINE h5awrite_double_scalar
537 SUBROUTINE h5awrite_string_simple(loc_id, attr_name, attr_data)
538 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
539 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
540 CHARACTER(LEN=*),
DIMENSION(:),
INTENT(IN),
TARGET :: attr_data
543 INTEGER(KIND=hid_t) :: attr_id, space_id, type_id
544 INTEGER(KIND=hsize_t),
DIMENSION(2) :: dims
545 TYPE(c_ptr) :: buffer
547 dims(1) = len(attr_data(1), kind=hsize_t)
548 dims(2) =
SIZE(attr_data, kind=hsize_t)
551 CALL h5tcopy_f(h5t_c_s1, type_id, error)
552 CALL h5tset_cset_f(type_id, h5t_cset_utf8_f, error)
553 CALL h5tset_size_f(type_id, int(dims(1), size_t), error)
556 CALL h5screate_simple_f(1, dims(2:2), space_id, error)
557 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 dataspace')
560 CALL h5acreate_f(loc_id, attr_name, type_id, space_id, attr_id, error)
561 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 attribute')
564 buffer = c_loc(attr_data(1))
567 CALL h5awrite_f(attr_id, type_id, buffer, error)
568 IF (error < 0) cpabort(
'ERROR: failed to write HDF5 attribute')
571 CALL h5aclose_f(attr_id, error)
572 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 attribute')
575 CALL h5sclose_f(space_id, error)
576 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 dataspace')
579 CALL h5tclose_f(type_id, error)
580 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 datatype')
582 END SUBROUTINE h5awrite_string_simple
590 SUBROUTINE h5awrite_double_simple(loc_id, attr_name, attr_data)
591 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
592 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
593 REAL(KIND=
dp),
DIMENSION(:),
INTENT(IN),
TARGET :: attr_data
596 INTEGER(KIND=hid_t) :: attr_id, space_id, type_id
597 INTEGER(KIND=hsize_t),
DIMENSION(1) :: dims
598 TYPE(c_ptr) :: buffer
600 dims(1) =
SIZE(attr_data, kind=hsize_t)
603 type_id = h5t_native_double
606 CALL h5screate_simple_f(1, dims, space_id, error)
607 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 dataspace')
610 CALL h5acreate_f(loc_id, attr_name, type_id, space_id, attr_id, error)
611 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 attribute')
614 buffer = c_loc(attr_data(1))
617 CALL h5awrite_f(attr_id, type_id, buffer, error)
618 IF (error < 0) cpabort(
'ERROR: failed to write HDF5 attribute')
621 CALL h5aclose_f(attr_id, error)
622 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 attribute')
625 CALL h5sclose_f(space_id, error)
626 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 dataspace')
628 END SUBROUTINE h5awrite_double_simple
636 SUBROUTINE h5awrite_integer_simple(loc_id, attr_name, attr_data)
637 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
638 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
639 INTEGER,
DIMENSION(:),
INTENT(IN),
TARGET :: attr_data
642 INTEGER(KIND=hid_t) :: attr_id, space_id, type_id
643 INTEGER(KIND=hsize_t),
DIMENSION(1) :: dims
644 TYPE(c_ptr) :: buffer
646 dims(1) =
SIZE(attr_data, kind=hsize_t)
649 type_id = h5t_native_integer
652 CALL h5screate_simple_f(1, dims, space_id, error)
653 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 dataspace')
656 CALL h5acreate_f(loc_id, attr_name, type_id, space_id, attr_id, error)
657 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 attribute')
660 buffer = c_loc(attr_data(1))
663 CALL h5awrite_f(attr_id, type_id, buffer, error)
664 IF (error < 0) cpabort(
'ERROR: failed to write HDF5 attribute')
667 CALL h5aclose_f(attr_id, error)
668 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 attribute')
671 CALL h5sclose_f(space_id, error)
672 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 dataspace')
674 END SUBROUTINE h5awrite_integer_simple
682 SUBROUTINE h5dwrite_double_simple(loc_id, dset_name, dset_data)
683 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
684 CHARACTER(LEN=*),
INTENT(IN) :: dset_name
685 REAL(KIND=
dp),
DIMENSION(:),
INTENT(IN),
TARGET :: dset_data
688 INTEGER(KIND=hid_t) :: dset_id, space_id, type_id
689 INTEGER(KIND=hsize_t),
DIMENSION(1) :: dims
690 TYPE(c_ptr) :: buffer
692 dims(1) =
SIZE(dset_data, kind=hsize_t)
695 type_id = h5t_native_double
698 CALL h5screate_simple_f(1, dims, space_id, error)
699 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 dataspace')
702 CALL h5dcreate_f(loc_id, dset_name, type_id, space_id, dset_id, error)
703 IF (error < 0) cpabort(
'ERROR: failed to create HDF5 dataset')
706 buffer = c_loc(dset_data(1))
709 CALL h5dwrite_f(dset_id, type_id, buffer, error)
710 IF (error < 0) cpabort(
'ERROR: failed to write HDF5 dataset')
713 CALL h5dclose_f(dset_id, error)
714 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 dataset')
717 CALL h5sclose_f(space_id, error)
718 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 dataspace')
720 END SUBROUTINE h5dwrite_double_simple
728 SUBROUTINE h5dread_double_simple(loc_id, dset_name, dset_data)
729 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
730 CHARACTER(LEN=*),
INTENT(IN) :: dset_name
731 REAL(KIND=
dp),
DIMENSION(:),
INTENT(OUT) :: dset_data
734 INTEGER(KIND=hid_t) :: dset_id, npoints, space_id, type_id
735 INTEGER(KIND=hsize_t),
DIMENSION(1) :: dims
737 dims(1) =
SIZE(dset_data, kind=hsize_t)
740 type_id = h5t_native_double
743 CALL h5dopen_f(loc_id, dset_name, dset_id, error)
744 IF (error < 0) cpabort(
'ERROR: failed to open HDF5 dataset')
747 CALL h5dget_space_f(dset_id, space_id, error)
748 IF (error < 0) cpabort(
'ERROR: failed to fetch HDF5 dataspace info')
751 CALL h5sget_simple_extent_npoints_f(space_id, npoints, error)
752 IF (error < 0) cpabort(
'ERROR: failed to fetch HDF5 dataspace dimension')
755 CALL h5dread_f(dset_id, type_id, dset_data, dims, error)
756 IF (error < 0) cpabort(
'ERROR: failed to read HDF5 dataset')
759 CALL h5dclose_f(dset_id, error)
760 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 dataset')
763 CALL h5sclose_f(space_id, error)
764 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 dataspace')
766 END SUBROUTINE h5dread_double_simple
774 SUBROUTINE h5aread_double_scalar(loc_id, attr_name, attr_data)
775 INTEGER(KIND=hid_t),
INTENT(IN) :: loc_id
776 CHARACTER(LEN=*),
INTENT(IN) :: attr_name
777 REAL(KIND=
dp),
INTENT(OUT),
TARGET :: attr_data
780 INTEGER(KIND=hid_t) :: attr_id, type_id
781 TYPE(c_ptr) :: buffer
784 type_id = h5t_native_double
787 CALL h5aopen_f(loc_id, attr_name, attr_id, error)
788 IF (error < 0) cpabort(
'ERROR: failed to open HDF5 attribute')
790 buffer = c_loc(attr_data)
792 CALL h5aread_f(attr_id, type_id, buffer, error)
793 IF (error < 0) cpabort(
'ERROR: failed to read HDF5 attribute')
796 CALL h5aclose_f(attr_id, error)
797 IF (error < 0) cpabort(
'ERROR: failed to close HDF5 attribute')
799 END SUBROUTINE h5aread_double_scalar
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
A wrapper around the HDF5 Fortran API.
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
type(mp_comm_type), parameter, public mp_comm_world
type(mp_info_type), parameter, public mp_info_null