KronLinInv  0.3
Kronecker-product-based linear inversion

◆ writereal2darrh5()

subroutine readwriteh5::writereal2darrh5 ( character(len=1024), intent(in)  outfile,
character(len=*), intent(in)  dsetname,
real(dp), dimension(:,:), intent(in)  arr 
)

Definition at line 158 of file rdwrhdf5.f08.

158 
159  character(len=1024),intent(in) :: outfile
160  real(dp),intent(in) :: arr(:,:)
161  character(len=*),intent(in) :: dsetname
162 
163  ! filename length must be the same than in dummy variable
164  integer(hid_t) :: file_id ! file identifier
165  integer(hid_t) :: dset_id ! dataset identifier
166  integer :: error ! error flag
167  integer(hid_t) :: dspace_id
168  integer(hsize_t), dimension(2) :: data_dims2
169  integer :: rank
170 
171  !! copmpression stuff
172  logical :: avail
173  integer :: filter_info
174  integer :: filter_info_both
175  integer(hid_t) :: dcpl
176  integer :: chunkingfactor
177  integer(hsize_t), dimension(2) :: chunk2
178 
179 
180  chunkingfactor = 10
181 
182  !##############################
183  !# initialize hdf5 #
184  !##############################
185  ! initialize fortran interface.
186  call h5open_f(error)
187  !-------------------------------------------------------------
188  ! check if gzip compression is available and can be used for both
189  ! compression and decompression. normally we do not perform error
190  ! checking in these examples for the sake of clarity, but in this
191  ! case we will make an exception because this filter is an
192  ! optional part of the hdf5 library.
193  call h5zfilter_avail_f(h5z_filter_deflate_f, avail, error)
194  if (.not.avail) then
195  write(*,'("gzip filter not available.",/)')
196  stop
197  endif
198  call h5zget_filter_info_f(h5z_filter_deflate_f, filter_info, error)
199  filter_info_both=ior(h5z_filter_encode_enabled_f,h5z_filter_decode_enabled_f)
200  if (filter_info .ne. filter_info_both) then
201  write(*,'("gzip filter not available for encoding and decoding.",/)')
202  stop
203  endif
204 
205  !-------------------------------------------------------------
206  if (h5firsttimeread.eqv..true.) then
207  call h5fcreate_f(trim(adjustl(outfile)), h5f_acc_trunc_f,file_id,error)
208  h5firsttimeread=.false.
209  else
210  ! open an existing file using the default properties.
211  call h5fopen_f(trim(adjustl(outfile)), h5f_acc_rdwr_f, file_id, error)
212  end if
213 
214 
215  !##############################
216  !# write arr #
217  !##############################
218  rank=2
219  data_dims2=shape(arr)
220  chunk2 = data_dims2/chunkingfactor
221  call checkchunking(chunk2)
222  ! create dataspace. setting maximum size to null sets the maximum
223  ! size to be the current size.
224  call h5screate_simple_f(rank, data_dims2, dspace_id, error)
225  !-------------------------------------------------------------
226  ! create the dataset creation property list, add the gzip
227  ! compression filter and set the chunk size.
228  call h5pcreate_f(h5p_dataset_create_f, dcpl, error)
229  call h5pset_deflate_f(dcpl, 9, error)
230  call h5pset_chunk_f(dcpl, rank, chunk2, error)
231  !-------------------------------------------------------------
232  ! create the dataset with default properties.
233  call h5dcreate_f(file_id, dsetname, h5t_ieee_f64le, dspace_id, &
234  dset_id, error, dcpl)
235  !-------------------------------------------------------------
236  ! write the data to the dataset.
237  call h5dwrite_f(dset_id,h5t_ieee_f64le, arr, data_dims2, error)
238  !-------------------------------------------------------------
239  ! close and release resources.
240  call h5pclose_f(dcpl,error)
241  !-------------------------------------------------------------
242  call h5sclose_f(dspace_id, error)
243  ! close the dataset.
244  call h5dclose_f(dset_id, error)
245 
246 
247  ! ##############################
248  ! # terminate hdf5 stuff #
249  ! ##############################
250  ! close the file.
251  call h5fclose_f(file_id, error)
252  ! close fortran interface.
253  call h5close_f(error)
254 
255  return
Here is the call graph for this function:
Here is the caller graph for this function: