Dice Fortran Backend Documentation
restart_fns Module Reference

Contains routines to read and write restart files. More...

Functions/Subroutines

subroutine write_res_nml (i_qoi, i_par, auto, guess)
 Writes the restart file res_nml.txt, using the current states of simulation variables. More...
 
subroutine read_res_nml (res)
 Reads the RESTART namelist in res_nml.txt. Assigns the input data to the corresponding variables in the restart derived type instance 'res'. More...
 
subroutine error_check (ierr)
 Checks error status at each point of the NetCDF read. More...
 
subroutine read_energies (filename, energies, variances, accept_rates)
 Reads restart files with energies, variances and acceptence arrays. More...
 
subroutine read_energies_h2plus (filename, energies, variances, accept_rates, c_array)
 Reads restart files with energies, variances and acceptence arrays. Also reads one extra array of optimized 'c' parameters for H2plus problem. More...
 
subroutine read_energies_h2 (filename, energies, variances, accept_rates, a_array, b_array)
 Reads restart files with energies, variances and acceptence arrays. Also reads two extra arrays of optimized parameters ('a' and 'beta') for H2 problem. More...
 

Variables

integer fu
 To store LUN of files during i/o. More...
 
integer rc
 To capture error states during file i/o. More...
 

Detailed Description

Contains routines to read and write restart files.

Contains subroutines to read and write the RESTART namelist in the res_nml.txt restart file. Also contains subroutines that read the NetCDF files storing the restart history of either total energies or parameter energies.

Function/Subroutine Documentation

◆ write_res_nml()

subroutine restart_fns::write_res_nml ( integer(int32), intent(in)  i_qoi,
integer(int32), intent(in), optional  i_par,
logical, intent(in), optional  auto,
real(real64), intent(in), optional  guess 
)

Writes the restart file res_nml.txt, using the current states of simulation variables.

Parameters
[in]iqoiIndex of last grid point of alpha (for QHO)or bond (for H2plus or H2)
[in]autoBoolean indicating if auto_params is turned on or not (for H2plus or H2)
[in]i_parIndex of last grid-point or auto-search iteration of c or beta (for H2plus or H2)
[in]guessFor auto-search, last guess value for c or beta (for H2plus or H2)

Definition at line 47 of file restart_fns.f90.

48 
49  ! Uses the following global variables: p_system, p
50  ! Local variables
51  integer(int32), intent(in) :: i_qoi ! current index on alpha (for QHO) or bond (for Hyd) grid
52  integer(int32), optional, intent(in) :: i_par ! current index of c (for H2plus) or beta (for H2)
53  logical, optional,intent(in) :: auto ! indicates if auto_params is turned on, for H2plus or H2
54  real(real64), optional, intent(in) :: guess ! for auto-search, current guess value for c (for H2plus) or beta (for H2)
55  type(restart_type) :: res
56 
57  ! Define the namelists
58  namelist /restart/ res
59 
60  ! Store grid point of quantity of interest (qoi)
61  res%i_qoi = i_qoi
62 
63  ! Check if the required optional parameters are present, and store them in res
64  if (p_system=='H2plus' .or. p_system=='H2') then
65 
66  if (.not.(present(i_par))) error stop 'Error: Missing "i_par" input to function write_res_nml().'
67  res%i_par = i_par
68 
69  if (.not.(present(auto))) error stop 'Error: Missing "auto" input to function write_res_nml().'
70  res%auto = auto
71 
72  if (auto) then
73  if (.not.(present(guess))) error stop 'Error: Missing "guess" input to function write_res_nml().'
74  res%guess = guess
75  endif
76 
77  endif
78 
79  ! Open the res_nml.txt file
80  open(action='write', file=resfile_nml, iostat=rc, newunit=fu)
81 
82  ! Write the RESTART namelist
83  write(nml=restart, iostat=rc, unit=fu)
84  if (rc /= 0) then
85  error stop 'Error: Invalid RESTART namelist defined in function write_res_nml().'
86  end if
87 
88  ! Close the res_nml.txt file
89  close(fu)
90 
+ Here is the caller graph for this function:

◆ read_res_nml()

subroutine restart_fns::read_res_nml ( type(restart_type), intent(out)  res)

Reads the RESTART namelist in res_nml.txt. Assigns the input data to the corresponding variables in the restart derived type instance 'res'.

Parameters
[out]resvalsInstance of restart_type, to store restart parameter values

Definition at line 110 of file restart_fns.f90.

111 
112  ! Local variables
113  type(restart_type), intent(out) :: res
114 
115  ! Define the namelist
116  namelist /restart/ res
117 
118  ! Check if file exists
119  inquire(file=resfile_nml, iostat=rc)
120  if (rc /= 0) then
121  print*, 'Searched for file ', resfile_nml, ' .'
122  error stop 'Error: This restart file is not present in the current directory.'
123  end if
124 
125  ! Open the file
126  open(action='read', file=resfile_nml, iostat=rc, newunit=fu)
127 
128  ! Read the RESTART namelist
129  read(nml=restart, iostat=rc, unit=fu)
130  if (rc /= 0) then
131  error stop 'Error: Invalid RESTART namelist in "res_nml.txt".'
132  end if
133 
134  ! Close the file
135  close(fu)
136 
+ Here is the caller graph for this function:

◆ error_check()

subroutine restart_fns::error_check ( integer, intent(in)  ierr)

Checks error status at each point of the NetCDF read.

Will print error message/code corresponding to ierr input. Copied from module write_netCDF.f90.

Parameters
[in]ierrInternal error value

Definition at line 152 of file restart_fns.f90.

153  integer,intent(in) :: ierr
154  if (ierr /= nf90_noerr) then
155  print*, trim(nf90_strerror(ierr))
156  return
157  endif
+ Here is the caller graph for this function:

◆ read_energies()

subroutine restart_fns::read_energies ( character(len=*), intent(in)  filename,
real(real64), dimension(:), intent(out)  energies,
real(real64), dimension(:), intent(out)  variances,
real(real64), dimension(:), intent(out)  accept_rates 
)

Reads restart files with energies, variances and acceptence arrays.

Assigns the data arrays it reads to the corresponding array variables passed to it.

Parameters
[in]filenameName of the NetCDF restart file with required energies
[in]energiesArray to store restart energies
[in]variancesArray to store restart variances
[in]accept_ratesArray to store restart acceptence rates

Definition at line 176 of file restart_fns.f90.

177 
178  ! Local variables
179  character(len=*), intent(in) :: filename
180  real(real64), dimension(:), intent(out) :: energies, variances, accept_rates
181  integer :: ierr, file_id, var_id
182 
183  ! Check if file exists
184  inquire(file=filename, iostat=rc)
185  if (rc /= 0) then
186  print*, 'Searched for file ', filename, ' .'
187  error stop 'Error: This restart file is not present in the current directory.'
188  end if
189 
190  ! Open restart netCDF file
191  ierr = nf90_open(filename, nf90_nowrite, file_id)
192  call error_check(ierr)
193 
194  ! Get var_id for energies
195  ierr = nf90_inq_varid(file_id, "total_energies", var_id)
196  call error_check(ierr)
197 
198  ! Read the energies
199  ierr = nf90_get_var(file_id, var_id, energies)
200  call error_check(ierr)
201 
202  ! Get var_id for variances
203  ierr = nf90_inq_varid(file_id, "Uncertainties", var_id)
204  call error_check(ierr)
205 
206  ! Read the variances
207  ierr = nf90_get_var(file_id, var_id, variances)
208  call error_check(ierr)
209 
210  ! Get attribute accept_rate
211  ierr = nf90_get_att(file_id, nf90_global, "accept_rate", accept_rates)
212  call error_check(ierr)
213 
214  ! Close the file
215  ierr = nf90_close(file_id)
216  call error_check(ierr)
217 
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_energies_h2plus()

subroutine restart_fns::read_energies_h2plus ( character(len=*), intent(in)  filename,
real(real64), dimension(:), intent(out)  energies,
real(real64), dimension(:), intent(out)  variances,
real(real64), dimension(:), intent(out)  accept_rates,
real(real64), dimension(:), intent(out)  c_array 
)

Reads restart files with energies, variances and acceptence arrays. Also reads one extra array of optimized 'c' parameters for H2plus problem.

Assigns the data arrays it reads to the corresponding array variables passed to it.

Parameters
[in]filenameName of the NetCDF restart file with required energies
[in]energiesArray to store restart energies
[in]variancesArray to store restart variances
[in]accept_ratesArray to store restart acceptence rates
[in]c_arrayArray to store optimized c-values for each bondlength

Definition at line 238 of file restart_fns.f90.

239 
240  ! Local variables
241  character(len=*), intent(in) :: filename
242  real(real64), dimension(:), intent(out) :: energies, variances, accept_rates, c_array
243  integer :: ierr, file_id, var_id
244 
245  ! Check if file exists
246  inquire(file=filename, iostat=rc)
247  if (rc /= 0) then
248  print*, 'Searched for file ', filename, ' .'
249  error stop 'Error: This restart file is not present in the current directory.'
250  end if
251 
252  ! Open restart netCDF file
253  ierr = nf90_open(filename, nf90_nowrite, file_id)
254  call error_check(ierr)
255 
256  ! Get var_id for energies
257  ierr = nf90_inq_varid(file_id, "total_energies", var_id)
258  call error_check(ierr)
259 
260  ! Read the energies
261  ierr = nf90_get_var(file_id, var_id, energies)
262  call error_check(ierr)
263 
264  ! Get var_id for variances
265  ierr = nf90_inq_varid(file_id, "Uncertainties", var_id)
266  call error_check(ierr)
267 
268  ! Read the variances
269  ierr = nf90_get_var(file_id, var_id, variances)
270  call error_check(ierr)
271 
272  ! Get var_id for c_array
273  ierr = nf90_inq_varid(file_id, "Parameter_array", var_id)
274  call error_check(ierr)
275 
276  ! Read the c_array
277  ierr = nf90_get_var(file_id, var_id, c_array)
278  call error_check(ierr)
279 
280  ! Get attribute accept_rate
281  ierr = nf90_get_att(file_id, nf90_global, "accept_rate", accept_rates)
282  call error_check(ierr)
283 
284  ! Close the file
285  ierr = nf90_close(file_id)
286  call error_check(ierr)
287 
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_energies_h2()

subroutine restart_fns::read_energies_h2 ( character(len=*), intent(in)  filename,
real(real64), dimension(:), intent(out)  energies,
real(real64), dimension(:), intent(out)  variances,
real(real64), dimension(:), intent(out)  accept_rates,
real(real64), dimension(:), intent(out)  a_array,
real(real64), dimension(:), intent(out)  b_array 
)

Reads restart files with energies, variances and acceptence arrays. Also reads two extra arrays of optimized parameters ('a' and 'beta') for H2 problem.

Assigns the data arrays it reads to the corresponding array variables passed to it.

Parameters
[in]filenameName of the NetCDF restart file with required energies
[in]energiesArray to store restart energies
[in]variancesArray to store restart variances
[in]accept_ratesArray to store restart acceptence rates
[in]a_arrayArray to store optimized a-values for each bondlength
[in]b_arrayArray to store optimized beta-values for each bondlength

Definition at line 309 of file restart_fns.f90.

310 
311  ! Local variables
312  character(len=*), intent(in) :: filename
313  real(real64), dimension(:), intent(out) :: energies, variances, accept_rates, a_array, b_array
314  integer :: ierr, file_id, var_id
315 
316  ! Check if file exists
317  inquire(file=filename, iostat=rc)
318  if (rc /= 0) then
319  print*, 'Searched for file ', filename, ' .'
320  error stop 'Error: This restart file is not present in the current directory.'
321  end if
322 
323  ! Open restart netCDF file
324  ierr = nf90_open(filename, nf90_nowrite, file_id)
325  call error_check(ierr)
326 
327  ! Get var_id for energies
328  ierr = nf90_inq_varid(file_id, "total_energies", var_id)
329  call error_check(ierr)
330 
331  ! Read the energies
332  ierr = nf90_get_var(file_id, var_id, energies)
333  call error_check(ierr)
334 
335  ! Get var_id for variances
336  ierr = nf90_inq_varid(file_id, "Uncertainties", var_id)
337  call error_check(ierr)
338 
339  ! Read the variances
340  ierr = nf90_get_var(file_id, var_id, variances)
341  call error_check(ierr)
342 
343  ! Get var_id for a_array
344  ierr = nf90_inq_varid(file_id, "Parameter_a_array", var_id)
345  call error_check(ierr)
346 
347  ! Read the a_array
348  ierr = nf90_get_var(file_id, var_id, a_array)
349  call error_check(ierr)
350 
351  ! Get var_id for b_array
352  ierr = nf90_inq_varid(file_id, "Parameter_beta_array", var_id)
353  call error_check(ierr)
354 
355  ! Read the b_array
356  ierr = nf90_get_var(file_id, var_id, b_array)
357  call error_check(ierr)
358 
359  ! Get attribute accept_rate
360  ierr = nf90_get_att(file_id, nf90_global, "accept_rate", accept_rates)
361  call error_check(ierr)
362 
363  ! Close the file
364  ierr = nf90_close(file_id)
365  call error_check(ierr)
366 
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ fu

integer restart_fns::fu

To store LUN of files during i/o.

Definition at line 23 of file restart_fns.f90.

23  integer :: fu

◆ rc

integer restart_fns::rc

To capture error states during file i/o.

Definition at line 24 of file restart_fns.f90.

24  integer :: rc