@@ -194,6 +194,7 @@ module manager_hdf5
194194 interface h5_read_dataset_collect_hyperslab
195195 module procedure h5_read_dataset_1d_l_collect_hyperslab ! logical
196196 module procedure h5_read_dataset_1d_i_collect_hyperslab ! integer
197+ module procedure h5_read_dataset_1d_i64_collect_hyperslab ! integer 64-bit
197198 module procedure h5_read_dataset_2d_i_collect_hyperslab
198199 module procedure h5_read_dataset_3d_i_collect_hyperslab
199200 module procedure h5_read_dataset_4d_i_collect_hyperslab
@@ -254,6 +255,7 @@ module manager_hdf5
254255 interface h5_write_dataset_collect_hyperslab
255256 module procedure h5_write_dataset_1d_l_collect_hyperslab ! logical
256257 module procedure h5_write_dataset_1d_i_collect_hyperslab ! integer
258+ module procedure h5_write_dataset_1d_i64_collect_hyperslab ! integer 64-bit
257259 module procedure h5_write_dataset_2d_i_collect_hyperslab
258260 module procedure h5_write_dataset_3d_i_collect_hyperslab
259261 module procedure h5_write_dataset_4d_i_collect_hyperslab
@@ -265,6 +267,13 @@ module manager_hdf5
265267 module procedure h5_write_dataset_2d_d_collect_hyperslab ! double
266268 end interface h5_write_dataset_collect_hyperslab
267269
270+ ! generic interface to create dataset
271+ interface h5_create_dataset_gen
272+ module procedure h5_create_dataset_gen_int
273+ module procedure h5_create_dataset_gen_int64
274+ end interface h5_create_dataset_gen
275+
276+
268277 ! object-oriented interface
269278 ! (Fortran 2003 standard style)
270279 !
@@ -410,7 +419,7 @@ end subroutine h5_initialize
410419 subroutine write_attenuation_file_hdf5 (factor_common , scale_factor , factor_common_kappa , scale_factor_kappa )
411420
412421#if defined(USE_HDF5)
413- use shared_parameters, only: NPROC, LOCAL_PATH
422+ use shared_parameters, only: NPROC, LOCAL_PATH,H5_COL
414423 use constants, only: myrank,N_SLS,NGLLX,NGLLY,NGLLZ
415424#endif
416425
@@ -463,16 +472,16 @@ subroutine write_attenuation_file_hdf5(factor_common, scale_factor, factor_commo
463472 call h5_open_file_p_collect(filename)
464473 dset_name = " scale_factor"
465474 call h5_write_dataset_4d_r_collect_hyperslab(dset_name, &
466- scale_factor,(/ 0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ),.true. )
475+ scale_factor,(/ 0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ),H5_COL )
467476 dset_name = " scale_factor_kappa"
468477 call h5_write_dataset_4d_r_collect_hyperslab(dset_name, &
469- scale_factor_kappa,(/ 0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ),.true. )
478+ scale_factor_kappa,(/ 0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ),H5_COL )
470479 dset_name = " factor_common"
471480 call h5_write_dataset_5d_r_collect_hyperslab(dset_name, &
472- factor_common,(/ 0 ,0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ),.true. )
481+ factor_common,(/ 0 ,0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ),H5_COL )
473482 dset_name = " factor_common_kappa"
474483 call h5_write_dataset_5d_r_collect_hyperslab(dset_name, &
475- factor_common_kappa,(/ 0 ,0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ),.true. )
484+ factor_common_kappa,(/ 0 ,0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ),H5_COL )
476485
477486 call h5_close_file_p()
478487 call h5_finalize()
@@ -499,7 +508,7 @@ end subroutine write_attenuation_file_hdf5
499508 subroutine read_attenuation_file_hdf5 (factor_common , scale_factor , factor_common_kappa , scale_factor_kappa )
500509
501510#if defined(USE_HDF5)
502- use shared_parameters, only: NPROC, LOCAL_PATH
511+ use shared_parameters, only: NPROC, LOCAL_PATH, H5_COL
503512 use constants, only: myrank
504513#endif
505514
@@ -526,16 +535,16 @@ subroutine read_attenuation_file_hdf5(factor_common, scale_factor, factor_common
526535 ! open file
527536 call h5_open_file_p_collect(fname)
528537 ! read offset array
529- call h5_read_dataset_1d_i_collect_hyperslab (" offset_nspec" ,offset_nspec, (/ 0 / ), .true. )
538+ call h5_read_dataset_collect_hyperslab (" offset_nspec" ,offset_nspec, (/ 0 / ), H5_COL )
530539
531- call h5_read_dataset_4d_r_collect_hyperslab (" scale_factor" , scale_factor, &
532- (/ 0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ), .true. )
533- call h5_read_dataset_4d_r_collect_hyperslab (" scale_factor_kappa" , scale_factor_kappa, &
534- (/ 0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ), .true. )
535- call h5_read_dataset_5d_r_collect_hyperslab (" factor_common" , factor_common, &
536- (/ 0 ,0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ), .true. )
537- call h5_read_dataset_5d_r_collect_hyperslab (" factor_common_kappa" , factor_common_kappa, &
538- (/ 0 ,0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ), .true. )
540+ call h5_read_dataset_collect_hyperslab (" scale_factor" , scale_factor, &
541+ (/ 0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ), H5_COL )
542+ call h5_read_dataset_collect_hyperslab (" scale_factor_kappa" , scale_factor_kappa, &
543+ (/ 0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ), H5_COL )
544+ call h5_read_dataset_collect_hyperslab (" factor_common" , factor_common, &
545+ (/ 0 ,0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ), H5_COL )
546+ call h5_read_dataset_collect_hyperslab (" factor_common_kappa" , factor_common_kappa, &
547+ (/ 0 ,0 ,0 ,0 ,sum (offset_nspec(0 :myrank-1 ))/ ), H5_COL )
539548
540549 call h5_close_file_p()
541550 call h5_finalize()
@@ -562,7 +571,7 @@ end subroutine read_attenuation_file_hdf5
562571 subroutine write_checkmesh_data_hdf5 (dset_name ,dump_array )
563572
564573#if defined(USE_HDF5)
565- use shared_parameters, only: LOCAL_PATH, NPROC
574+ use shared_parameters, only: LOCAL_PATH, NPROC, H5_COL
566575 use constants, only: myrank
567576#endif
568577
@@ -612,9 +621,14 @@ subroutine write_checkmesh_data_hdf5(dset_name,dump_array)
612621 endif
613622 call synchronize_all()
614623
615- ! open file
616- call h5_open_file_p_collect(filename)
617- call h5_write_dataset_1d_r_collect_hyperslab(dset_name, dump_array, (/ sum (offset(0 :myrank-1 ))/ ),.true. )
624+ ! open file (usually *_collect can be used with H5_COL = .false.)
625+ ! but I got a strange error on some systems, so I use if statement here
626+ if (H5_COL) then
627+ call h5_open_file_p_collect(filename)
628+ else
629+ call h5_open_file_p(filename)
630+ endif
631+ call h5_write_dataset_collect_hyperslab(dset_name, dump_array, (/ sum (offset(0 :myrank-1 ))/ ), H5_COL)
618632 call h5_close_file_p()
619633
620634 call h5_finalize()
@@ -1751,7 +1765,7 @@ end subroutine h5_open_file_p_collect
17511765!- ------------------------------------------------------------------------------
17521766!
17531767
1754- subroutine h5_create_dataset_gen (dataset_name , dim_in , rank , dtype_id )
1768+ subroutine h5_create_dataset_gen_int (dataset_name , dim_in , rank , dtype_id )
17551769 implicit none
17561770 character (len=* ), intent (in ) :: dataset_name
17571771 integer , dimension (:), intent (in ) :: dim_in
@@ -1812,7 +1826,75 @@ subroutine h5_create_dataset_gen(dataset_name, dim_in, rank, dtype_id)
18121826 if (error /= 0 ) write (* ,* ) ' hdf5 dataspace close failed for ' , dataset_name
18131827 call check_error()
18141828
1815- end subroutine h5_create_dataset_gen
1829+ end subroutine h5_create_dataset_gen_int
1830+
1831+ !
1832+ !- ------------------------------------------------------------------------------
1833+ !
1834+
1835+ subroutine h5_create_dataset_gen_int64 (dataset_name , dim_in , rank , dtype_id )
1836+ implicit none
1837+ character (len=* ), intent (in ) :: dataset_name
1838+ integer (kind= 8 ), dimension (:), intent (in ) :: dim_in
1839+
1840+ integer (HSIZE_T), dimension (size (dim_in)) :: dim
1841+ integer , intent (in ) :: dtype_id ! 1:int, 4:real4, 8:real8,
1842+ integer , intent (in ) :: rank
1843+
1844+ integer (HID_T) :: dspace_id
1845+ ! logical :: if_chunk = .true.
1846+ ! integer :: i
1847+
1848+ dim = dim_in ! convert data type
1849+
1850+ call h5screate_simple_f(rank, dim, dspace_id, error)
1851+ if (error /= 0 ) write (* ,* ) ' hdf5 dataspace create failed for ' , dataset_name
1852+ call check_error()
1853+ call h5pcreate_f(H5P_DATASET_CREATE_F, plist_id, error)
1854+ call check_error()
1855+
1856+ ! chunk size setting
1857+ ! do i = 1, rank
1858+ ! if (dim(i) <= 0) then
1859+ ! if_chunk = .false.
1860+ ! print *, "dataset not chunk set: ", dataset_name
1861+ ! endif
1862+ ! enddo
1863+ ! if (if_chunk) call h5pset_chunk_f(plist_id,rank,dim,error)
1864+
1865+ if (dtype_id == 0 ) then ! bool uses integer
1866+ call h5dcreate_f(file_id, trim (dataset_name), H5T_NATIVE_INTEGER, dspace_id, dataset_id, error, &
1867+ dcpl_id= plist_id)
1868+ else if (dtype_id == 1 ) then ! integer
1869+ call h5dcreate_f(file_id, trim (dataset_name), H5T_NATIVE_INTEGER, dspace_id, dataset_id, error, &
1870+ dcpl_id= plist_id)
1871+ else if (dtype_id == 2 ) then ! character
1872+ call h5dcreate_f(file_id, trim (dataset_name), str_type, dspace_id, dataset_id, error, &
1873+ dcpl_id= plist_id)
1874+ else if (dtype_id == 4 ) then ! real
1875+ call h5dcreate_f(file_id, trim (dataset_name), H5T_NATIVE_REAL, dspace_id, dataset_id, error, &
1876+ dcpl_id= plist_id)
1877+ else if (dtype_id == 8 ) then ! double
1878+ call h5dcreate_f(file_id, trim (dataset_name), H5T_NATIVE_DOUBLE, dspace_id, dataset_id, error, &
1879+ dcpl_id= plist_id)
1880+ else
1881+ print * , " specified dtype_id is not implemented yet for hdf5 io. aborting..."
1882+ stop ' Invalid dtype_id, not implemented yet in h5_create_dataset_gen() routine'
1883+ endif
1884+ if (error /= 0 ) write (* ,* ) ' hdf5 dataset create failed for ' , dataset_name
1885+ call check_error()
1886+
1887+ call h5_close_prop_list_nocheck(dataset_name)
1888+
1889+ call h5dclose_f(dataset_id,error)
1890+ if (error /= 0 ) write (* ,* ) ' hdf5 dataset close failed for ' , dataset_name
1891+ call check_error()
1892+ call h5sclose_f(dspace_id, error)
1893+ if (error /= 0 ) write (* ,* ) ' hdf5 dataspace close failed for ' , dataset_name
1894+ call check_error()
1895+
1896+ end subroutine h5_create_dataset_gen_int64
1897+
18161898
18171899!
18181900!- ------------------------------------------------------------------------------
@@ -2524,7 +2606,60 @@ subroutine h5_read_dataset_1d_i_collect_hyperslab(dataset_name, data, offset_in,
25242606 call h5_close_dataset()
25252607 end subroutine h5_read_dataset_1d_i_collect_hyperslab
25262608
2609+ !
2610+ !- ------------------------------------------------------------------------------
25272611!
2612+
2613+ subroutine h5_read_dataset_1d_i64_collect_hyperslab (dataset_name , data , offset_in , if_collective )
2614+ implicit none
2615+ character (len=* ), intent (in ) :: dataset_name
2616+ integer , dimension (:), intent (inout ), target :: data
2617+ integer (kind= 8 ), dimension (:), intent (in ) :: offset_in
2618+ logical , intent (in ) :: if_collective
2619+ ! local parameters
2620+ integer :: rank = 1
2621+ integer (HSIZE_T), dimension (1 ) :: dim
2622+ integer (HSIZE_T), dimension (1 ) :: count ! size of hyperslab
2623+ integer (HSSIZE_T), dimension (1 ) :: offset ! the position where the datablock is inserted
2624+
2625+ dim = shape (data )
2626+ offset = offset_in ! convert data type
2627+
2628+ ! open dataset
2629+ call h5_open_dataset2(trim (dataset_name))
2630+
2631+ ! select a place where data is inserted.
2632+ count (1 ) = dim (1 )
2633+
2634+ ! select hyperslab in the file
2635+ call h5screate_simple_f(rank,count, mem_dspace_id, error)
2636+ call check_error()
2637+ call h5dget_space_f(dataset_id, file_dspace_id, error)
2638+ call check_error()
2639+ call h5sselect_hyperslab_f(file_dspace_id, H5S_SELECT_SET_F, offset, count, error)
2640+ call check_error()
2641+ call h5_create_dataset_prop_list(if_collective)
2642+
2643+ call h5_check_arr_dim(dim)
2644+
2645+ ! write array using Fortran pointer
2646+ ! call h5dread_f(dataset_id, H5T_NATIVE_INTEGER, data, dim, error, &
2647+ ! file_space_id=file_dspace_id, mem_space_id=mem_dspace_id, xfer_prp=plist_id)
2648+ ! use F2003 API
2649+ f_ptr = c_loc(data (1 ))
2650+ call h5dread_f(dataset_id, H5T_NATIVE_INTEGER, f_ptr, error, &
2651+ file_space_id= file_dspace_id, mem_space_id= mem_dspace_id, xfer_prp= plist_id)
2652+ if (error /= 0 ) write (* ,* ) ' hdf5 dataset write failed for ' , dataset_name
2653+ call check_error()
2654+ call h5_close_prop_list(dataset_name)
2655+ call h5sclose_f(mem_dspace_id, error)
2656+ call check_error()
2657+ call h5sclose_f(file_dspace_id, error)
2658+ call check_error()
2659+ call h5_close_dataset()
2660+ end subroutine h5_read_dataset_1d_i64_collect_hyperslab
2661+
2662+
25282663!- ------------------------------------------------------------------------------
25292664!
25302665
@@ -3976,6 +4111,59 @@ end subroutine h5_write_dataset_1d_i_collect_hyperslab
39764111!- ------------------------------------------------------------------------------
39774112!
39784113
4114+ ! store local 1d array to global 1d array
4115+ subroutine h5_write_dataset_1d_i64_collect_hyperslab (dataset_name , data , offset_in , if_collective )
4116+ implicit none
4117+ character (len=* ), intent (in ) :: dataset_name
4118+ integer , dimension (:), intent (in ), target :: data
4119+ integer (kind= 8 ), dimension (:), intent (in ) :: offset_in
4120+ logical , intent (in ) :: if_collective
4121+ ! local parameters
4122+ integer :: rank = 1
4123+ integer (HSIZE_T), dimension (1 ) :: dim
4124+ integer (HSIZE_T), dimension (1 ) :: count ! size of hyperslab
4125+ integer (HSSIZE_T), dimension (1 ) :: offset ! the position where the datablock is inserted
4126+
4127+ dim = shape (data )
4128+ offset = offset_in ! convert data type
4129+
4130+ ! open dataset
4131+ call h5_open_dataset2(trim (dataset_name))
4132+
4133+ ! select a place where data is inserted.
4134+ count (1 ) = dim (1 )
4135+
4136+ ! select hyperslab in the file
4137+ call h5screate_simple_f(rank,count, mem_dspace_id, error)
4138+ call check_error()
4139+ call h5dget_space_f(dataset_id, file_dspace_id, error)
4140+ call check_error()
4141+ call h5sselect_hyperslab_f(file_dspace_id, H5S_SELECT_SET_F, offset, count, error)
4142+ call check_error()
4143+ call h5_create_dataset_prop_list(if_collective)
4144+
4145+ call h5_check_arr_dim(dim)
4146+ ! write array using Fortran pointer
4147+ ! call h5dwrite_f(dataset_id, H5T_NATIVE_INTEGER, data, dim, error, &
4148+ ! file_space_id=file_dspace_id, mem_space_id=mem_dspace_id, xfer_prp=plist_id)
4149+ ! use F2003 API
4150+ call h5dwrite_f(dataset_id, H5T_NATIVE_INTEGER, c_loc(data (1 )), error, &
4151+ file_space_id= file_dspace_id, mem_space_id= mem_dspace_id, xfer_prp= plist_id)
4152+ if (error /= 0 ) write (* ,* ) ' hdf5 dataset write failed for ' , dataset_name
4153+ call check_error()
4154+ call h5_close_prop_list(dataset_name)
4155+ call h5sclose_f(mem_dspace_id, error)
4156+ call check_error()
4157+ call h5sclose_f(file_dspace_id, error)
4158+ call check_error()
4159+ call h5_close_dataset()
4160+ end subroutine h5_write_dataset_1d_i64_collect_hyperslab
4161+
4162+ !
4163+ !- ------------------------------------------------------------------------------
4164+ !
4165+
4166+
39794167 subroutine h5_write_dataset_1d_r_collect_hyperslab (dataset_name , data , offset_in , if_collective )
39804168 implicit none
39814169 character (len=* ), intent (in ) :: dataset_name
0 commit comments