7 #include <PB3D_macros.h>
79 integer function set_1d_vars(lim_tot,lim_loc,space_id,c_plist_id) &
85 character(*),
parameter :: rout_name =
'set_1D_vars'
88 integer,
intent(in) :: lim_tot(:,:)
89 integer,
intent(in) :: lim_loc(:,:)
90 integer(HID_T),
intent(in),
optional :: space_id
91 integer(HID_T),
intent(inout),
optional :: c_plist_id
99 integer(HSIZE_T) :: block(1)
100 integer(HSIZE_T) :: stride(1)
101 integer(HSIZE_T) :: count(1)
102 integer(HSIZE_T) :: offset(1)
103 integer(HSIZE_T) :: chunk_dims(1)
104 real(dp) :: max_chunk_size
105 real(dp) :: min_chunk_size
106 character(len=max_str_ln) :: err_msg
115 n_dims =
size(lim_tot,1)
118 if (
size(lim_loc,1).ne.n_dims)
then
120 err_msg =
'lim_tot and lim_loc are not compatible'
123 if (
size(lim_tot,2).ne.2 .or.
size(lim_loc,2).ne.2)
then
125 err_msg =
'lim_tot and_lim_loc need to contain 2 columns'
129 if (lim_tot(id,1).gt.lim_loc(id,1) .or. &
130 &lim_tot(id,2).lt.lim_loc(id,2))
then
131 write(*,*)
rank,
'lim_tot = ', lim_tot
132 write(*,*)
rank,
'lim_loc = ', lim_loc
134 err_msg =
'Total limits must comprise local ones'
140 write(*,*,iostat=istat)
rank,
'in set_1D_vars:'
141 write(*,*,iostat=istat)
rank,
'lim_tot_lo = ', lim_tot(:,1)
142 write(*,*,iostat=istat)
rank,
'lim_tot_hi = ', lim_tot(:,2)
143 write(*,*,iostat=istat)
rank,
'lim_loc_lo = ', lim_loc(:,1)
144 write(*,*,iostat=istat)
rank,
'lim_loc_hi = ', lim_loc(:,2)
152 if (
present(space_id))
then
153 call h5sselect_all_f(space_id,ierr)
154 chckerr(
'Failed to select hyperslab')
160 if (lim_loc(id,1).gt.lim_tot(id,1) .or. &
161 &lim_loc(id,2).lt.lim_tot(id,2))
then
163 if (div_dim.eq.n_dims+1) div_dim = id
166 if (
present(space_id))
then
168 n_prod(1) = product(lim_tot(1:id-1,2)-lim_tot(1:id-1,1)+1)
169 n_prod(2) = n_prod(1)*(lim_tot(id,2)-lim_tot(id,1)+1)
173 write(*,*,iostat=istat)
rank,
'dimension', id,
'of', &
175 write(*,*,iostat=istat)
rank,
'n_prod = ', n_prod
179 block = (lim_loc(id,2)-lim_loc(id,1)+1) * n_prod(1)
181 offset = (lim_loc(id,1)-lim_tot(id,1)) * n_prod(1)
184 count = count*(lim_tot(kd,2)-lim_tot(kd,1)+1)
189 write(*,*,iostat=istat)
rank,
'block, offset, stride, &
190 &count = ', block, offset, stride, count
194 call h5sselect_hyperslab_f(space_id,h5s_select_and_f,&
195 &offset,count,ierr,stride=stride,block=block)
196 chckerr(
'Failed to select hyperslab')
200 write(*,*,iostat=istat)
rank,
'total range DIFFERS from &
205 write(*,*,iostat=istat)
rank,
'total range EQUAL to local'
212 max_chunk_size = 4.e9_dp / sizeof(1._dp)
213 min_chunk_size = min(10.e6_dp/sizeof(1._dp),&
214 &product(lim_tot(:,2)-lim_tot(:,1)+1._dp))
215 if (
present(c_plist_id))
then
219 do while (chunk_size.le.min_chunk_size .and. id.le.
size(lim_tot,1))
220 chunk_size = chunk_size * (lim_tot(id,2)-lim_tot(id,1)+1)
225 write(*,*,iostat=istat)
rank,
'suggested chunk size', chunk_size
228 chunk_size = chunk_size / (1 + floor(chunk_size/max_chunk_size))
231 write(*,*,iostat=istat)
rank,
'def. chunk size', chunk_size
236 if (
present(c_plist_id))
then
237 chunk_dims = chunk_size
238 call h5pcreate_f(h5p_dataset_create_f,c_plist_id,ierr)
239 chckerr(
'Failed to create property list')
240 call h5pset_chunk_f(c_plist_id,1,chunk_dims,ierr)
241 chckerr(
'Failed to create chunk')
254 character(*),
parameter :: rout_name =
'probe_HDF5_group'
257 character(len=*),
intent(in) :: hdf5_name
258 character(len=*),
intent(in) :: group_name
259 logical,
intent(inout) :: group_exists
263 integer(HID_T) :: hdf5_i
264 integer(HID_T) :: group_id
271 chckerr(
'Failed to initialize HDF5')
278 call h5fopen_f(hdf5_name,h5f_acc_rdonly_f,hdf5_i,ierr)
279 chckerr(
'Failed to open file. Does it exist?')
282 call h5eset_auto_f(0,ierr)
283 chckerr(
'Failed to disable error printing')
286 call h5gopen_f(hdf5_i,group_name,group_id,istat)
287 group_exists = istat.eq.0
290 call h5eset_auto_f(1,ierr)
291 chckerr(
'Failed to enable error printing')
294 if (group_exists)
then
295 call h5gclose_f(group_id,ierr)
296 chckerr(
'Failed to close head group')
300 call h5fclose_f(hdf5_i,ierr)
301 chckerr(
'failed to close HDF5 file')
309 chckerr(
'Failed to close FORTRAN HDF5 interface')
319 character(*),
parameter :: rout_name =
'list_all_vars_in_group'
322 integer(HID_T),
intent(in) :: group_id
325 integer :: storage_type
327 integer :: max_corder
328 integer(HSIZE_T) :: id
330 integer(SIZE_T) :: name_len
331 character(len=max_str_ln) :: var_name
334 call h5gget_info_f(group_id,storage_type,nr_lnks,max_corder,&
336 chckerr(
'Failed to get group info')
339 call writo(
'The group has '//trim(
i2str(nr_lnks))//
' elements')
344 call h5lget_name_by_idx_f(group_id,
'.',h5_index_name_f,&
345 &h5_iter_native_f,id-1,var_name,ierr,size=name_len)
346 chckerr(
'Failed to get name')
350 call writo(
'Element '//trim(
i2str(id_loc))//
'/'//&
351 &trim(
i2str(nr_lnks))//
': '//trim(var_name))