28 #include <PB3D_macros.h>
59 module procedure reset_hdf5_item_ind
61 module procedure reset_hdf5_item_arr
76 integer function open_hdf5_file(file_info,file_name,sym_type,descr,&
77 &ind_plot,cont_plot)
result(ierr)
83 character(*),
parameter :: rout_name =
'open_HDF5_file'
87 character(len=*),
intent(in) :: file_name
88 integer,
intent(inout),
optional :: sym_type
89 character(len=*),
intent(in),
optional :: descr
90 logical,
intent(in),
optional :: ind_plot
91 logical,
intent(in),
optional :: cont_plot
94 character(len=max_str_ln) :: full_file_name
95 character(len=max_str_ln) :: line
96 character(len=max_str_ln) :: err_msg
97 integer(HID_T) :: hdf5_i
98 integer(HID_T) :: plist_id
99 integer :: sym_type_loc
100 integer :: mpi_comm_loc
101 integer :: disable_rw
104 logical :: ind_plot_loc
105 logical :: cont_plot_loc
111 ind_plot_loc = .false.
112 if (
present(ind_plot)) ind_plot_loc = ind_plot
115 cont_plot_loc = .false.
116 if (
present(cont_plot)) cont_plot_loc = cont_plot
119 if (ind_plot_loc)
then
120 mpi_comm_loc = mpi_comm_self
122 mpi_comm_loc = mpi_comm_world
126 full_file_name = data_dir//
'/'//trim(file_name)
130 chckerr(
'Failed to initialize HDF5')
134 call mpi_info_create(disable_rw,ierr)
135 chckerr(
'Failed to create MPI info')
136 call mpi_info_set(disable_rw,
'romio_ds_read',
'disable',ierr)
137 chckerr(
'Failed to set MPI info')
138 call mpi_info_set(disable_rw,
'romio_ds_write',
'disable',ierr)
139 chckerr(
'Failed to set MPI info')
141 disable_rw = mpi_info_null
145 call h5pcreate_f(h5p_file_access_f,plist_id,ierr)
146 chckerr(
'Failed to create property list')
147 call h5pset_fapl_mpio_f(plist_id,mpi_comm_loc,disable_rw,ierr)
148 chckerr(
'Failed to set file access property')
152 call mpi_info_free(disable_rw,ierr)
153 chckerr(
'Failed to free MPI info')
157 if (cont_plot_loc)
then
158 call h5fopen_f(trim(full_file_name)//
'.h5',h5f_acc_rdwr_f,&
159 &hdf5_i,ierr,access_prp=plist_id)
160 chckerr(
'Failed to open file')
162 call h5fcreate_f(trim(full_file_name)//
'.h5',h5f_acc_trunc_f,&
163 &hdf5_i,ierr,access_prp=plist_id)
164 err_msg =
'Failed to create file. Is '//trim(data_dir)//
'/ present?'
169 call h5pclose_f(plist_id,ierr)
170 chckerr(
'Failed to close property list')
173 file_info%HDF5_i = hdf5_i
174 file_info%name = file_name
178 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
179 if (cont_plot_loc)
then
181 open(
nextunit(file_info%XDMF_i),status=
'old',action=
'read',&
182 &file=trim(full_file_name)//
'.xmf',iostat=ierr)
183 chckerr(
'Failed to open xmf file')
186 if (
present(sym_type))
then
188 read(file_info%XDMF_i,
'(A)',iostat=ierr) line
189 chckerr(
'Failed to read file')
191 i_st(1) = index(line,
'Value="')
192 if (i_st(1).eq.0)
then
194 chckerr(
'Can''t find symmetry type')
196 i_st(1) = i_st(1) + 7
198 i_st(2) = index(line(i_st(1):),
'"/>') + i_st(1)
199 if (i_st(2).eq.0)
then
201 chckerr(
'Can''t find symmetry type')
203 i_st(2) = i_st(2) - 2
205 read(line(i_st(1):i_st(2)),*,iostat=ierr) sym_type_loc
206 chckerr(
'Can''t read symmetry type')
207 if (sym_type_loc.ne.sym_type)
then
209 err_msg =
'Symmetry type of continued plot does not &
210 &match previous plot'
216 open(
nextunit(file_info%XDMF_i),status=
'replace',&
217 &file=trim(full_file_name)//
'.xmf',iostat=ierr)
218 chckerr(
'Failed to create xmf file')
221 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
222 &
'<?xml version="1.0" ?>'
223 chckerr(
'Failed to write')
224 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
225 &
'<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>'
226 chckerr(
'Failed to write')
227 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
228 &
'<Xdmf Version="2.0">'
229 chckerr(
'Failed to write')
230 if (
present(sym_type))
then
231 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
232 &
'<Information Name="sym_type" &
233 &Value="'//trim(
i2str(sym_type))//
'"/>'
234 chckerr(
'Failed to write')
236 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
238 chckerr(
'Failed to write')
239 if (
present(descr))
then
240 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
241 &
'<Information Name="Description">'
242 chckerr(
'Failed to write')
243 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
245 chckerr(
'Failed to write')
246 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
248 chckerr(
'Failed to write')
254 if (cont_plot_loc .and. .not.ind_plot_loc .and.
present(sym_type))
then
263 integer function close_hdf5_file(file_info,ind_plot,cont_plot)
result(ierr)
266 character(*),
parameter :: rout_name =
'close_HDF5_file'
270 logical,
intent(in),
optional :: ind_plot
271 logical,
intent(in),
optional :: cont_plot
274 character(len=max_str_ln) :: err_msg
275 character(len=max_str_ln) :: full_file_name
276 integer(HID_T) :: hdf5_i
277 logical :: ind_plot_loc
278 logical :: cont_plot_loc
284 ind_plot_loc = .false.
285 if (
present(ind_plot)) ind_plot_loc = ind_plot
288 cont_plot_loc = .false.
289 if (
present(cont_plot)) cont_plot_loc = cont_plot
292 full_file_name = data_dir//
'/'//trim(file_info%name)
293 hdf5_i = file_info%HDF5_i
296 call h5fclose_f(hdf5_i,ierr)
297 chckerr(
'failed to close HDF5 file')
301 err_msg =
'Failed to close FORTRAN HDF5 interface'
305 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
307 if (.not.cont_plot_loc)
then
309 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
311 chckerr(
'Failed to write')
312 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
314 chckerr(
'Failed to write')
318 close(file_info%XDMF_i,iostat=ierr)
319 chckerr(
'Failed to close xmf file')
322 if (cont_plot_loc)
then
323 call writo(
'Contributed to HDF5/XMF plot in output file "'//&
324 &trim(full_file_name)//
'.xmf''')
326 call writo(
'Created HDF5/XMF plot in output file "'//&
327 &trim(full_file_name)//
'.xmf''')
338 integer function add_hdf5_item(file_info,XDMF_item,reset,ind_plot) &
342 character(*),
parameter :: rout_name =
'add_HDF5_item'
347 logical,
intent(in),
optional :: reset
348 logical,
intent(in),
optional :: ind_plot
354 logical :: ind_plot_loc
360 ind_plot_loc = .false.
361 if (
present(ind_plot)) ind_plot_loc = ind_plot
364 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
366 item_len =
size(xdmf_item%xml_str)
369 if (
present(reset))
then
377 write(unit=file_info%XDMF_i,fmt=
xmf_fmt,iostat=ierr) &
378 &trim(xdmf_item%xml_str(id))
379 chckerr(
'Failed to write HDF5 item')
394 &var,dim_tot,loc_dim,loc_offset,init_val,ind_plot,cont_plot) &
399 character(*),
parameter :: rout_name =
'print_HDF5_3D_data_item'
404 character(len=*),
intent(in) :: var_name
405 real(dp),
intent(in) :: var(:,:,:)
406 integer,
intent(in) :: dim_tot(3)
407 integer,
intent(in),
optional :: loc_dim(3)
408 integer,
intent(in),
optional :: loc_offset(3)
409 real(dp),
intent(in),
optional :: init_val
410 logical,
intent(in),
optional :: ind_plot
411 logical,
intent(in),
optional :: cont_plot
415 integer :: loc_dim_loc(3)
416 integer :: loc_offset_loc(3)
417 integer(HSIZE_T) :: dimsf(3)
418 integer(HSIZE_T) :: dimsm(3)
419 integer(HID_T) :: filespace
420 integer(HID_T) :: memspace
421 integer(HID_T) :: plist_id
422 integer(HID_T) :: dset_id
423 integer(HSIZE_T) :: mem_offset(3)
424 integer(HSIZE_T) :: mem_block(3)
425 integer(HSIZE_T) :: mem_stride(3)
426 integer(HSIZE_T) :: mem_count(3)
427 character(len=max_str_ln) :: dim_str
428 character(len=max_str_ln) :: err_msg
429 logical :: ind_plot_loc
430 logical :: cont_plot_loc
431 integer(HID_T) :: hdf5_kind_64
440 ind_plot_loc = .false.
441 if (
present(ind_plot)) ind_plot_loc = ind_plot
444 cont_plot_loc = .false.
445 if (
present(cont_plot)) cont_plot_loc = cont_plot
448 hdf5_kind_64 = h5kind_to_type(dp,h5_real_kind)
451 ierr = check_for_parallel_3d(dim_tot,loc_dim_loc,loc_offset_loc,&
458 call h5screate_simple_f(
size(dimsf),dimsf,filespace,ierr)
459 chckerr(
'Failed to create file space')
460 call h5screate_simple_f(
size(dimsm),dimsm,memspace,ierr)
461 chckerr(
'Failed to create memory space')
464 if (cont_plot_loc)
then
466 call h5dopen_f(file_info%HDF5_i,trim(var_name),dset_id,ierr)
467 chckerr(
'Failed to open file data set')
470 call h5dget_space_f(dset_id,filespace,ierr)
471 chckerr(
'Failed to get file space')
474 if (
present(init_val))
then
475 call h5pcreate_f(h5p_dataset_create_f,plist_id,ierr)
476 err_msg =
'Failed to create property list'
478 call h5pset_fill_value_f(plist_id,hdf5_kind_64,init_val,ierr)
479 err_msg =
'Failed to set default fill value property'
481 call h5dcreate_f(file_info%HDF5_i,trim(var_name),hdf5_kind_64,&
482 &filespace,dset_id,ierr,plist_id)
483 chckerr(
'Failed to create file data set')
484 call h5pclose_f(plist_id,ierr)
485 chckerr(
'Failed to close property list')
487 call h5dcreate_f(file_info%HDF5_i,trim(var_name),hdf5_kind_64,&
488 &filespace,dset_id,ierr)
489 chckerr(
'Failed to create file data set')
496 mem_block = loc_dim_loc
497 mem_offset = loc_offset_loc
498 call h5sselect_hyperslab_f(filespace,h5s_select_set_f,mem_offset,&
499 &mem_count,ierr,mem_stride,mem_block)
500 chckerr(
'Failed to select hyperslab')
503 call h5pcreate_f(h5p_dataset_xfer_f,plist_id,ierr)
504 chckerr(
'Failed to create property list')
505 if (ind_plot_loc)
then
506 plist_id = h5p_default_f
508 call h5pset_dxpl_mpio_f(plist_id,h5fd_mpio_collective_f,ierr)
509 chckerr(
'Failed to set parallel property')
513 call h5dwrite_f(dset_id,hdf5_kind_64,var,dimsf,ierr,&
514 &file_space_id=filespace,mem_space_id=memspace,xfer_prp=plist_id)
515 chckerr(
'Failed to write data set')
516 call h5pclose_f(plist_id,ierr)
517 chckerr(
'Failed to close property list')
520 call h5sclose_f(filespace,ierr)
521 chckerr(
'Unable to close file space')
522 call h5sclose_f(memspace,ierr)
523 chckerr(
'Unable to close memory space')
526 call h5dclose_f(dset_id,ierr)
527 chckerr(
'Failed to close data set')
531 if (.not.cont_plot_loc)
then
532 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
535 do id = 1,
size(dim_tot)
537 dim_str = trim(dim_str)//
' '//trim(
i2str(dim_tot(id)))
540 dataitem_id%name =
'DataItem - '//trim(var_name)
541 allocate(dataitem_id%xml_str(3))
542 dataitem_id%xml_str(1) =
'<DataItem Dimensions="'//&
543 &trim(dim_str)//
'" NumberType="Float" Precision="8" &
545 dataitem_id%xml_str(2) = trim(file_info%name)//
'.h5:/'//&
547 dataitem_id%xml_str(3) =
'</DataItem>'
551 &
'created data item "'//trim(dataitem_id%name)//
'"'
559 integer function check_for_parallel_3d(dim_tot,loc_dim_out,&
560 &loc_offset_out,loc_dim_in,loc_offset_in)
result(ierr)
561 character(*),
parameter :: rout_name =
'check_for_parallel_3D'
564 integer,
intent(in) :: dim_tot(3)
565 integer,
intent(inout) :: loc_dim_out(3), loc_offset_out(3)
566 integer,
intent(in),
optional :: loc_dim_in(3), loc_offset_in(3)
569 character(len=max_str_ln) :: err_msg
575 if (
present(loc_dim_in))
then
576 if (.not.
present(loc_offset_in))
then
577 err_msg =
'Need to specify offset as well as group &
582 loc_dim_out = loc_dim_in
583 loc_offset_out = loc_offset_in
585 do id = 1,
size(dim_tot)
586 if (loc_dim_in(id).gt.dim_tot(id))
then
587 err_msg =
'Total dimension '//trim(
i2str(id))//&
588 &
' cannot be smaller than group dimension'
594 loc_dim_out = dim_tot
597 end function check_for_parallel_3d
602 &dim_tot,reset,ind_plot,cont_plot)
608 character(len=*),
intent(in) :: var_name
609 integer,
intent(in) :: dim_tot(3)
610 logical,
intent(in),
optional :: reset
611 logical,
intent(in),
optional :: ind_plot
612 logical,
intent(in),
optional :: cont_plot
615 integer :: dataitem_len
619 logical :: ind_plot_loc
620 logical :: cont_plot_loc
621 character(len=max_str_ln) :: dim_str
622 character(len=max_str_ln) :: fun_str
628 ind_plot_loc = .false.
629 if (
present(ind_plot)) ind_plot_loc = ind_plot
632 cont_plot_loc = .false.
633 if (
present(cont_plot)) cont_plot_loc = cont_plot
637 if (
present(reset)) reset_loc = reset
641 if (.not.cont_plot_loc)
then
642 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
645 do id = 1,
size(dataitem_ids)
646 dataitem_len = dataitem_len +
size(dataitem_ids(id)%xml_str)
650 merged_id%name =
'DataItem - '//trim(var_name)
651 allocate(merged_id%xml_str(dataitem_len+2))
655 do id = 1,
size(dim_tot)
657 dim_str = trim(dim_str)//
' '//trim(
i2str(dim_tot(id)))
660 dim_str = trim(dim_str)//
' '//trim(
i2str(
size(dataitem_ids)))
664 do id = 1,
size(dataitem_ids)
665 if (id.gt.1) fun_str = trim(fun_str)//
','
666 fun_str = trim(fun_str)//
' $'//trim(
i2str(id-1))
668 fun_str = trim(fun_str)//
')"'
670 merged_id%xml_str(1) =
'<DataItem Dimensions="'//&
671 &trim(dim_str)//
'" Function='//trim(fun_str)//&
672 &
' ItemType="Function" >'
674 do id = 1,
size(dataitem_ids)
675 do jd = 1,
size(dataitem_ids(id)%xml_str)
676 merged_id%xml_str(jd_loc) = dataitem_ids(id)%xml_str(jd)
680 merged_id%xml_str(jd_loc) =
'</DataItem>'
687 &
'merged data items into "'//trim(merged_id%name)//
'"'
694 subroutine print_hdf5_att(att_id,att_dataitem,att_name,att_center,att_type,&
702 character(len=*),
intent(in) :: att_name
703 integer,
intent(in) :: att_center
704 integer,
intent(in) :: att_type
705 logical,
intent(in),
optional :: reset
706 logical,
intent(in),
optional :: ind_plot
709 integer :: dataitem_len
712 logical :: ind_plot_loc
718 ind_plot_loc = .false.
719 if (
present(ind_plot)) ind_plot_loc = ind_plot
722 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
724 dataitem_len =
size(att_dataitem%xml_str)
728 if (
present(reset)) reset_loc = reset
731 att_id%name =
'Attribute - '//trim(att_name)
732 allocate(att_id%xml_str(dataitem_len+2))
733 att_id%xml_str(1) =
'<Attribute Name="'//trim(att_name)//&
736 do id = 1,dataitem_len
737 att_id%xml_str(id+1) = att_dataitem%xml_str(id)
739 att_id%xml_str(dataitem_len+2) =
'</Attribute>'
742 if (
debug_hdf5_ops)
write(*,*,iostat=istat)
'created attribute "'//&
743 &trim(att_id%name)//
'"'
759 integer,
intent(in) :: top_type
760 integer,
intent(in) :: top_n_elem(:)
761 logical,
intent(in),
optional :: ind_plot
766 character(len=max_str_ln) :: work_str
767 logical :: ind_plot_loc
773 ind_plot_loc = .false.
774 if (
present(ind_plot)) ind_plot_loc = ind_plot
777 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
779 n_dims =
size(top_n_elem)
785 work_str = trim(work_str)//
' '//trim(
i2str(top_n_elem(id)))
790 top_id%name =
'Topology'
791 allocate(top_id%xml_str(1))
792 top_id%xml_str(1) =
'<Topology TopologyType="'//&
794 &trim(work_str)//
'"/>'
797 if (
debug_hdf5_ops)
write(*,*,iostat=istat)
'created topology "'//&
798 &trim(top_id%name)//
'"'
804 subroutine print_hdf5_geom(geom_id,geom_type,geom_dataitems,reset,ind_plot)
809 integer,
intent(in) :: geom_type
811 logical,
intent(in),
optional :: reset
812 logical,
intent(in),
optional :: ind_plot
817 integer,
allocatable :: dataitem_len(:)
818 integer :: n_dataitems
820 logical :: ind_plot_loc
826 ind_plot_loc = .false.
827 if (
present(ind_plot)) ind_plot_loc = ind_plot
830 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
832 n_dataitems =
size(geom_dataitems)
835 allocate(dataitem_len(n_dataitems))
836 do id = 1,n_dataitems
837 dataitem_len(id) =
size(geom_dataitems(id)%xml_str)
841 if (
present(reset))
then
848 geom_id%name =
'Geometry'
849 allocate(geom_id%xml_str(sum(dataitem_len)+2))
850 geom_id%xml_str(1) =
'<Geometry GeometryType="'//&
853 do id = 1,n_dataitems
854 do jd = 1,dataitem_len(id)
855 geom_id%xml_str(id_sum) = geom_dataitems(id)%xml_str(jd)
859 geom_id%xml_str(id_sum) =
'</Geometry>'
862 if (
debug_hdf5_ops)
write(*,*,iostat=istat)
'created geometry "'//&
863 &trim(geom_id%name)//
'"'
884 integer function print_hdf5_grid(grid_id,grid_name,grid_type,grid_time,&
885 &grid_top,grid_geom,grid_atts,grid_grids,reset,ind_plot)
result(ierr)
888 character(*),
parameter :: rout_name =
'print_HDF5_grid'
892 character(len=*),
intent(in) :: grid_name
893 integer,
intent(in) :: grid_type
894 real(dp),
intent(in),
optional :: grid_time
899 logical,
intent(in),
optional :: reset
900 logical,
intent(in),
optional :: ind_plot
910 integer,
allocatable :: atts_len(:)
911 integer,
allocatable :: grids_len(:)
913 character(len=max_str_ln) :: err_msg
914 logical :: ind_plot_loc
923 ind_plot_loc = .false.
924 if (
present(ind_plot)) ind_plot_loc = ind_plot
927 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
929 if (grid_type.eq.1)
then
932 else if (grid_type.eq.2 .or. grid_type.eq.3)
then
933 if (.not.
present(grid_grids))
then
935 err_msg =
'For grid collections, the grids in the &
936 &collection have to be specified'
941 err_msg =
'Grid type '//trim(
i2str(grid_type))//
' not supported'
947 if (
present(grid_time)) time_len = 1
949 if (
present(grid_top))
then
950 top_len =
size(grid_top%xml_str)
952 if (grid_type.eq.1) top_len = 1
955 if (
present(grid_geom))
then
956 geom_len =
size(grid_geom%xml_str)
958 if (grid_type.eq.1) geom_len = 1
961 if (
present(grid_atts))
then
962 n_atts =
size(grid_atts)
963 allocate(atts_len(n_atts))
966 atts_len(id) =
size(grid_atts(id)%xml_str)
969 allocate(atts_len(0))
973 if (
present(grid_grids))
then
974 n_grids =
size(grid_grids)
975 allocate(grids_len(n_grids))
978 grids_len(id) =
size(grid_grids(id)%xml_str)
981 allocate(grids_len(0))
986 if (
present(reset))
then
994 if (grid_type.eq.1)
then
995 grid_id%name =
'Uniform Grid - '//trim(grid_name)
997 &grid_id%xml_str(time_len+top_len+geom_len+sum(atts_len)+2))
998 grid_id%xml_str(1) =
'<Grid Name="'//trim(grid_name)//&
999 &
'" GridType="Uniform">'
1000 if (
present(grid_time))
then
1001 grid_id%xml_str(id_sum) =
'<Time Value="'//&
1002 &trim(
r2str(grid_time))//
'" />'
1005 if (
present(grid_top))
then
1007 grid_id%xml_str(id_sum) = grid_top%xml_str(jd)
1011 grid_id%xml_str(id_sum) =
'<Topology Reference="/Xdmf/&
1012 &Domain/Topology[1]"/>'
1015 if (
present(grid_geom))
then
1017 grid_id%xml_str(id_sum) = grid_geom%xml_str(jd)
1021 grid_id%xml_str(id_sum) =
'<Geometry Reference="/Xdmf/&
1022 &Domain/Geometry[1]"/>'
1026 do jd = 1,atts_len(id)
1027 grid_id%xml_str(id_sum) = grid_atts(id)%xml_str(jd)
1032 grid_id%name =
'Collection Grid - '//trim(grid_name)
1033 allocate(grid_id%xml_str(time_len+sum(grids_len)+2))
1034 grid_id%xml_str(1) =
'<Grid Name="'//trim(grid_name)//&
1035 &
'" GridType="Collection" CollectionType="'//&
1037 if (
present(grid_time))
then
1038 grid_id%xml_str(id_sum) =
'<Time Value="'//&
1039 &trim(
r2str(grid_time))//
'" />'
1043 do jd = 1,grids_len(id)
1044 grid_id%xml_str(id_sum) = grid_grids(id)%xml_str(jd)
1049 grid_id%xml_str(id_sum) =
'</Grid>'
1053 &trim(grid_id%name)//
'"'
1058 if (grid_type.eq.1)
then
1059 if (
present(grid_top)) &
1061 if (
present(grid_geom)) &
1063 if (
present(grid_atts)) &
1065 else if (grid_type.eq.2 .or. grid_type.eq.3)
then
1066 if (
present(grid_grids)) &
1075 character(*),
parameter :: rout_name =
'create_output_HDF5'
1078 character(len=*),
intent(in) :: hdf5_name
1081 character(len=max_str_ln) :: err_msg
1082 integer(HID_T) :: hdf5_i
1091 chckerr(
'Failed to initialize HDF5')
1094 call h5fcreate_f(trim(hdf5_name),h5f_acc_trunc_f,hdf5_i,ierr)
1095 err_msg =
'Failed to create file "'//trim(hdf5_name)//
'"'
1099 call h5fclose_f(hdf5_i,ierr)
1100 chckerr(
'failed to close HDF5 file')
1103 call h5close_f(ierr)
1104 err_msg =
'Failed to close FORTRAN HDF5 interface'
1110 call writo(
'HDF5 output file '//trim(hdf5_name)//
' created')
1131 &disp_info,ind_print,remove_previous_arrs)
result(ierr)
1138 character(*),
parameter :: rout_name =
'print_HDF5_arrs'
1142 character(len=*),
intent(in) :: pb3d_name
1143 character(len=*),
intent(in) :: head_name
1144 integer,
intent(in),
optional :: rich_lvl
1145 logical,
intent(in),
optional :: disp_info
1146 logical,
intent(in),
optional :: ind_print
1147 logical,
intent(in),
optional :: remove_previous_arrs
1151 integer :: mpi_comm_loc
1154 integer,
allocatable :: lim_tot(:,:)
1155 integer,
allocatable :: lim_loc(:,:)
1156 character(len=max_str_ln) :: err_msg
1157 character(len=max_str_ln) :: head_name_loc
1158 logical :: ind_print_loc
1159 logical :: disp_info_loc
1160 logical :: remove_previous_arrs_loc
1161 logical :: group_exists
1162 integer(HID_T) :: a_plist_id
1163 integer(HID_T) :: x_plist_id
1164 integer(HID_T) :: chunk_c_plist_id
1165 integer(HID_T) :: hdf5_i
1166 integer(HID_T) :: hdf5_kind_64
1167 integer(HID_T) :: filespace
1168 integer(HID_T) :: memspace
1169 integer(HID_T) :: dset_id
1170 integer(HID_T) :: group_id
1171 integer(HID_T) :: head_group_id
1172 integer(HSIZE_T) :: dimsf(1)
1173 integer(HSIZE_T) :: dimsm(1)
1174 integer :: disable_rw
1177 integer(SIZE_T) :: rdcc_nslots
1178 integer(SIZE_T) :: rdcc_nbytes
1185 disp_info_loc = .false.
1186 if (
present(disp_info)) disp_info_loc = disp_info
1189 head_name_loc = head_name
1190 if (
present(rich_lvl))
then
1191 if (rich_lvl.gt.0) head_name_loc = trim(head_name_loc)//
'_R_'//&
1192 &trim(
i2str(rich_lvl))
1196 remove_previous_arrs_loc = .false.
1197 if (
present(remove_previous_arrs)) remove_previous_arrs_loc = &
1198 &remove_previous_arrs
1201 call detect_ind_print(ind_print_loc)
1202 if (
present(ind_print)) ind_print_loc = ind_print
1205 if (ind_print_loc)
then
1206 mpi_comm_loc = mpi_comm_self
1208 mpi_comm_loc = mpi_comm_world
1213 chckerr(
'Failed to initialize HDF5')
1217 call mpi_info_create(disable_rw,ierr)
1218 chckerr(
'Failed to create MPI info')
1219 call mpi_info_set(disable_rw,
'romio_ds_read',
'disable',ierr)
1220 chckerr(
'Failed to set MPI info')
1221 call mpi_info_set(disable_rw,
'romio_ds_write',
'disable',ierr)
1222 chckerr(
'Failed to set MPI info')
1224 disable_rw = mpi_info_null
1228 call h5pcreate_f(h5p_file_access_f,a_plist_id,ierr)
1229 chckerr(
'Failed to create property list')
1230 if (ind_print_loc)
then
1231 call h5pset_fapl_stdio_f(a_plist_id,ierr)
1233 call h5pset_fapl_mpio_f(a_plist_id,mpi_comm_loc,disable_rw,ierr)
1235 chckerr(
'Failed to set file access property')
1239 call mpi_info_free(disable_rw,ierr)
1240 chckerr(
'Failed to free MPI info')
1244 if (
n_procs.gt.1 .and. ind_print_loc)
then
1250 call h5fopen_f(trim(pb3d_name),h5f_acc_rdwr_f,hdf5_i,ierr,&
1251 &access_prp=a_plist_id)
1252 chckerr(
'Failed to open file')
1253 call h5pclose_f(a_plist_id,ierr)
1254 chckerr(
'Failed to close property list')
1257 hdf5_kind_64 = h5kind_to_type(dp,h5_real_kind)
1260 call h5eset_auto_f(0,ierr)
1261 chckerr(
'Failed to disable error printing')
1262 call h5gopen_f(hdf5_i,trim(head_name_loc),head_group_id,istat)
1263 group_exists = istat.eq.0
1264 call h5eset_auto_f(1,ierr)
1265 if (group_exists .and. remove_previous_arrs_loc)
then
1266 call h5gclose_f(head_group_id, ierr)
1267 chckerr(
'Failed to close head group')
1268 call h5ldelete_f(hdf5_i,trim(head_name_loc),ierr)
1269 chckerr(
'Failed to delete group')
1270 group_exists = .false.
1273 &trim(head_name_loc)//
'" existed and was deleted')
1276 if (.not.group_exists)
then
1277 call h5gcreate_f(hdf5_i,trim(head_name_loc),head_group_id,ierr)
1278 chckerr(
'Failed to create group')
1280 chckerr(
'Failed to enable error printing')
1283 call writo(
'Write data to PB3D output "'//trim(pb3d_name)//
'/'//&
1284 &trim(head_name_loc)//
'"')
1288 do id = 1,
size(vars)
1290 if (disp_info_loc)
then
1291 call writo(
'Writing '//trim(vars(id)%var_name))
1295 call h5eset_auto_f(0,ierr)
1296 chckerr(
'Failed to disable error printing')
1297 call h5gopen_f(head_group_id,trim(vars(id)%var_name),group_id,istat)
1298 group_exists = istat.eq.0
1299 call h5eset_auto_f(1,ierr)
1300 chckerr(
'Failed to enable error printing')
1301 if (.not.group_exists)
then
1303 call h5gcreate_f(head_group_id,trim(vars(id)%var_name),&
1305 chckerr(
'Failed to create group')
1311 n_dims =
size(vars(id)%tot_i_min)
1312 allocate(lim_tot(n_dims,2))
1313 allocate(lim_loc(n_dims,2))
1315 &reshape([vars(id)%tot_i_min,vars(id)%tot_i_max],[n_dims,2])
1317 &reshape([vars(id)%loc_i_min,vars(id)%loc_i_max],[n_dims,2])
1320 dimsf = product(lim_tot(:,2)-lim_tot(:,1)+1)
1323 if (.not.group_exists)
then
1325 call h5screate_simple_f(1,dimsf,filespace,ierr)
1326 chckerr(
'Failed to create file space')
1329 ierr =
set_1d_vars(lim_tot,lim_loc,c_plist_id=chunk_c_plist_id)
1333 call h5dcreate_f(group_id,
'var',hdf5_kind_64,filespace,&
1334 &dset_id,ierr,dcpl_id=chunk_c_plist_id)
1335 chckerr(
'Failed to create file data set')
1338 call h5pclose_f(chunk_c_plist_id,ierr)
1339 chckerr(
'Failed to close property list')
1342 call h5dopen_f(group_id,
'var',dset_id,ierr)
1343 chckerr(
'Failed to open file data set')
1346 call h5dget_space_f(dset_id,filespace,ierr)
1347 chckerr(
'Failed to get file space')
1353 call h5dget_access_plist_f(dset_id,a_plist_id,ierr)
1354 chckerr(
'Failed to get property list')
1357 call h5pget_chunk_cache_f(a_plist_id,rdcc_nslots,&
1358 &rdcc_nbytes,rdcc_w0,ierr)
1359 write(*,*,iostat=istat)
rank,
'Number of chunk slots in the &
1360 &raw data chunk cache hash table:', rdcc_nslots
1361 write(*,*,iostat=istat)
rank,
'Total size of the raw data &
1362 &chunk cache, in Mbytes:', rdcc_nbytes*1.e-6_dp
1363 write(*,*,iostat=istat)
rank,
'Preemption Policy:', rdcc_w0
1364 chckerr(
'Failed to get chunk cache')
1367 call h5pclose_f(a_plist_id,ierr)
1368 chckerr(
'Failed to close property list')
1373 ierr =
set_1d_vars(lim_tot,lim_loc,space_id=filespace)
1377 call h5pcreate_f(h5p_dataset_xfer_f,x_plist_id,ierr)
1378 chckerr(
'Failed to create property list')
1379 if (ind_print_loc)
then
1380 x_plist_id = h5p_default_f
1382 call h5pset_dxpl_mpio_f(x_plist_id,h5fd_mpio_collective_f,ierr)
1383 chckerr(
'Failed to set parallel property')
1387 dimsm = product(lim_loc(:,2)-lim_loc(:,1)+1)
1390 call h5screate_simple_f(1,dimsm,memspace,ierr)
1391 chckerr(
'Failed to create memory space')
1394 call h5dwrite_f(dset_id,hdf5_kind_64,vars(id)%p,dimsf,ierr,&
1395 &file_space_id=filespace,mem_space_id=memspace,&
1396 &xfer_prp=x_plist_id)
1398 call writo(
'Did you increase max_tot_mem while restarting &
1399 &Richardson or jumping to solution with different grid &
1400 &size?',alert=.true.)
1402 call writo(
'If so, must restart from lvl = 1.')
1403 call writo(
'Or modify the code to use "remove_previous_arrs".')
1406 chckerr(
'Failed to write data data set')
1407 call h5pclose_f(x_plist_id,ierr)
1408 chckerr(
'Failed to close property list')
1411 call h5sclose_f(filespace,ierr)
1412 chckerr(
'Unable to close file space')
1413 call h5sclose_f(memspace,ierr)
1414 chckerr(
'Unable to close memory space')
1417 call h5dclose_f(dset_id,ierr)
1418 chckerr(
'Failed to close data set')
1423 dimsf =
size(lim_tot)
1426 if (.not.group_exists)
then
1428 call h5screate_simple_f(1,dimsf,filespace,ierr)
1429 chckerr(
'Failed to create file space')
1432 call h5dcreate_f(group_id,
'lim',h5t_native_integer,&
1433 &filespace,dset_id,ierr)
1434 chckerr(
'Failed to create file data set')
1437 call h5sclose_f(filespace,ierr)
1438 chckerr(
'Unable to close file space')
1441 call h5dopen_f(group_id,
'lim',dset_id,ierr)
1442 chckerr(
'Failed to open file data set')
1446 if (
rank.eq.0 .or. ind_print_loc)
then
1448 call h5dwrite_f(dset_id,h5t_native_integer,&
1449 &[vars(id)%tot_i_min,vars(id)%tot_i_max],dimsf,ierr)
1451 chckerr(
'Failed to write limit data set')
1455 call h5dclose_f(dset_id,ierr)
1456 chckerr(
'Failed to close data set')
1459 deallocate(lim_tot,lim_loc)
1462 call h5gclose_f(group_id,ierr)
1463 chckerr(
'Failed to close group')
1469 call h5gclose_f(head_group_id,ierr)
1470 chckerr(
'Failed to close group')
1473 call h5fclose_f(hdf5_i,ierr)
1474 chckerr(
'failed to close HDF5 file')
1475 if (
n_procs.gt.1 .and. ind_print_loc)
then
1482 call h5close_f(ierr)
1483 err_msg =
'Failed to close FORTRAN HDF5 interface'
1488 subroutine detect_ind_print(ind_print)
1490 logical,
intent(inout) :: ind_print
1499 do id = 1,
size(vars)
1500 do jd = 1,
size(vars(id)%tot_i_min)
1501 if (vars(id)%tot_i_min(jd).ne.vars(id)%loc_i_min(jd) .or. &
1502 &vars(id)%tot_i_max(jd).ne.vars(id)%loc_i_max(jd))
then
1528 integer function read_hdf5_arr(var,PB3D_name,head_name,var_name,rich_lvl,&
1529 &disp_info,lim_loc)
result(ierr)
1537 character(*),
parameter :: rout_name =
'read_HDF5_arr_ind'
1541 character(len=*),
intent(in) :: pb3d_name
1542 character(len=*),
intent(in) :: head_name
1543 character(len=*),
intent(in) :: var_name
1544 integer,
intent(in),
optional :: rich_lvl
1545 logical,
intent(in),
optional :: disp_info
1546 integer,
intent(in),
optional :: lim_loc(:,:)
1549 character(len=max_str_ln) :: err_msg
1550 integer(HID_T) :: hdf5_i
1551 integer(HID_T) :: dset_id
1552 integer(HID_T) :: hdf5_kind_64
1553 integer(HID_T) :: group_id
1554 integer(HID_T) :: head_group_id
1555 integer(HID_T) :: filespace
1556 integer(HID_T) :: memspace
1557 integer(HSIZE_T) :: id
1558 integer(HSIZE_T) :: data_size
1559 integer(HSIZE_T) :: n_dims
1560 integer(SIZE_T) :: name_len
1561 integer :: storage_type
1562 integer :: nr_lnks_head
1563 integer :: max_corder
1564 integer,
allocatable :: lim_tot(:,:)
1565 integer,
allocatable :: lim_loc_loc(:,:)
1566 character(len=max_str_ln) :: name_len_loc
1567 character(len=max_str_ln) :: group_name
1568 character(len=max_str_ln) :: head_name_loc
1569 logical :: disp_info_loc
1578 disp_info_loc = .false.
1579 if (
present(disp_info)) disp_info_loc = disp_info
1582 head_name_loc = head_name
1583 if (
present(rich_lvl))
then
1584 if (rich_lvl.gt.0) head_name_loc = trim(head_name_loc)//
'_R_'//&
1585 &trim(
i2str(rich_lvl))
1591 write(*,*,iostat=istat)
'Reading data from PB3D output "'//&
1592 &trim(pb3d_name)//
'/'//trim(head_name_loc)//
'/'//&
1593 &trim(var_name)//
'"'
1599 chckerr(
'Failed to initialize HDF5')
1602 hdf5_kind_64 = h5kind_to_type(
dp,h5_real_kind)
1609 if (disp_info_loc)
then
1610 call writo(
'Opening file '//trim(pb3d_name))
1614 call h5fopen_f(trim(pb3d_name),h5f_acc_rdonly_f,hdf5_i,ierr)
1615 chckerr(
'Failed to open file')
1618 if (disp_info_loc)
then
1619 call writo(
'Opening variable "'//trim(head_name_loc)//
'"')
1623 call h5gopen_f(hdf5_i,trim(head_name_loc),head_group_id,ierr)
1624 err_msg =
'Failed to open head group "'//trim(head_name_loc)//
'"'
1629 if (disp_info_loc)
then
1636 call h5gget_info_f(head_group_id,storage_type,nr_lnks_head,&
1638 chckerr(
'Failed to get group info')
1641 do id = 1, nr_lnks_head
1642 call h5lget_name_by_idx_f(head_group_id,
'.',h5_index_name_f,&
1643 &h5_iter_native_f,id-1,group_name,ierr,size=name_len)
1644 chckerr(
'Failed to get name')
1649 write(name_len_loc,*) name_len
1651 err_msg =
'Recompile with max_str_ln > '//trim(name_len_loc)
1656 if (trim(group_name).ne.trim(var_name))
then
1661 if (disp_info_loc)
then
1662 call writo(
'Reading '//trim(group_name))
1666 var%var_name = trim(group_name)
1669 call h5gopen_f(head_group_id,trim(group_name),group_id,ierr)
1671 chckerr(
'Failed to open group')
1676 call h5dopen_f(group_id,
'lim',dset_id,ierr)
1677 chckerr(
'Failed to open dataset')
1680 call h5dget_space_f(dset_id,filespace,ierr)
1681 chckerr(
'Failed to get file space')
1684 call h5sget_simple_extent_npoints_f(filespace,data_size,ierr)
1686 chckerr(
'Failed to get storage size')
1687 n_dims = data_size/2
1688 allocate(var%tot_i_min(n_dims))
1689 allocate(var%tot_i_max(n_dims))
1692 call h5sclose_f(filespace,ierr)
1693 chckerr(
'Failed to close file space')
1696 allocate(lim_tot(n_dims,2))
1697 allocate(lim_loc_loc(n_dims,2))
1700 call h5dread_f(dset_id,h5t_native_integer,lim_tot,[2*n_dims],&
1702 chckerr(
'Failed to read dataset')
1705 if (
present(lim_loc))
then
1706 lim_loc_loc = lim_loc
1707 where (lim_loc(:,1).lt.0) lim_loc_loc(:,1) = lim_tot(:,1)
1708 where (lim_loc(:,2).lt.0) lim_loc_loc(:,2) = lim_tot(:,2)
1710 lim_loc_loc = lim_tot
1718 var%tot_i_max = lim_loc_loc(:,2)-lim_loc_loc(:,1)+1
1721 call h5dclose_f(dset_id,ierr)
1722 chckerr(
'Failed to close data set')
1727 data_size = product(lim_loc_loc(:,2)-lim_loc_loc(:,1)+1)
1728 allocate(var%p(data_size))
1731 call h5dopen_f(group_id,
'var',dset_id,ierr)
1732 chckerr(
'Failed to open dataset')
1735 call h5dget_space_f(dset_id,filespace,ierr)
1736 chckerr(
'Failed to get file space')
1739 ierr = set_1d_vars(lim_tot,lim_loc_loc,space_id=filespace)
1743 call h5screate_simple_f(1,[data_size],memspace,ierr)
1744 chckerr(
'Failed to create memory space')
1747 call h5dread_f(dset_id,hdf5_kind_64,var%p,[data_size],&
1748 &ierr,mem_space_id=memspace,file_space_id=filespace)
1749 chckerr(
'Failed to read dataset')
1752 call h5sclose_f(filespace,ierr)
1753 chckerr(
'Failed to close file space')
1754 call h5sclose_f(memspace,ierr)
1755 chckerr(
'Unable to close memory space')
1758 call h5dclose_f(dset_id,ierr)
1759 chckerr(
'Failed to close data set')
1764 deallocate(lim_tot,lim_loc_loc)
1767 call h5gclose_f(group_id,ierr)
1768 chckerr(
'Failed to close group')
1775 call h5gclose_f(head_group_id,ierr)
1776 chckerr(
'Failed to close head group')
1779 call h5fclose_f(hdf5_i,ierr)
1780 chckerr(
'failed to close HDF5 file')
1787 call h5close_f(ierr)
1788 err_msg =
'Failed to close FORTRAN HDF5 interface'
1793 subroutine reset_hdf5_item_arr(XDMF_items,ind_plot)
1798 logical,
intent(in),
optional :: ind_plot
1803 logical :: ind_plot_loc
1809 ind_plot_loc = .false.
1810 if (
present(ind_plot)) ind_plot_loc = ind_plot
1813 n_items =
size(xdmf_items)
1816 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
1818 if (.not.
allocated(xdmf_items(id)%xml_str))
then
1819 call writo(
'Could not reset HDF5 XDMF item "'&
1820 &//trim(xdmf_items(id)%name)//
'"',warning=.true.)
1824 &trim(xdmf_items(id)%name)//
'"'
1826 xdmf_items(id)%name =
''
1827 deallocate(xdmf_items(id)%xml_str)
1831 end subroutine reset_hdf5_item_arr
1833 subroutine reset_hdf5_item_ind(XDMF_item,ind_plot)
1838 logical,
intent(in),
optional :: ind_plot
1841 logical :: ind_plot_loc
1847 ind_plot_loc = .false.
1848 if (
present(ind_plot)) ind_plot_loc = ind_plot
1851 if (ind_plot_loc .or. .not.ind_plot_loc.and.
rank.eq.0)
then
1852 if (.not.
allocated(xdmf_item%xml_str))
then
1853 call writo(
'Could not reset HDF5 XDMF item "'&
1854 &//trim(xdmf_item%name)//
'"',warning=.true.)
1858 &trim(xdmf_item%name)//
'"'
1861 deallocate(xdmf_item%xml_str)
1864 end subroutine reset_hdf5_item_ind