MONC
Functions/Subroutines | Variables
checkpointer_write_checkpoint_mod Module Reference

Writes out model state_mod to a checkpoint NetCDF file. More...

Functions/Subroutines

subroutine, public write_checkpoint_file (current_state, filename)
 Will write out the current model state_mod into a NetCDF checkpoint file. More...
 
subroutine write_out_global_attributes (ncid)
 Writes out global attributes into the checkpoint. More...
 
subroutine write_out_q_indices (ncid, q_indices_id)
 Writes out the specific Q indicies that are active and need writing. More...
 
subroutine write_out_options (current_state, ncid, options_id)
 Writes out the options that the model was run with. More...
 
subroutine write_out_all_fields (current_state, ncid, u_id, v_id, w_id, zu_id, zv_id, zw_id, th_id, zth_id, q_id, zq_id, p_id)
 Will write out all prognostic model fields to the checkpoint. It will work in 1, 2 or 3D depending on the model. More...
 
subroutine write_out_velocity_field (ncid, local_grid, field, variable_id, multi_process, fourth_dim_loc)
 Will write out a single velocity field to the checkpoint file. If there are multiple processes then will determine the bounds, otherwise for serial just dump data field. More...
 
subroutine write_out_grid (ncid, grid)
 Will write out the grid to the checkpoint, it will work in 1, 2 or 3D depending on what is in the model. More...
 
subroutine write_out_mean_fields (ncid, grid)
 
subroutine write_z_grid_gimension (ncid, vertical_grid)
 Writes out the Z dimension of the grids_mod points which are explicitly calculated. More...
 
subroutine define_options_variable (current_state, ncid, string_dim_id, key_value_dim_id, options_id)
 Defines the NetCDF options variable which is basically a 3D character array to form key-value pair strings for each entry. More...
 
logical function define_q_indices_variable (ncid, string_dim_id, key_value_dim_id, q_indices_id)
 Defines the NetCDF Q indices variable which is, same as the options, stored as key-value pair of strings. This will only store and create these dimensions if there are any Q indicies to store. More...
 
subroutine define_q_field_dimension (current_state, ncid, q_dim_id)
 Defines the Q field dimension in the NetCDF. More...
 
subroutine define_grid_dimensions (current_state, ncid, z_dim_id, y_dim_id, x_dim_id)
 Will define the grid dimensions and works for 1, 2 or 3D grids_mod. More...
 
subroutine define_grid_variables (current_state, ncid)
 Defines the NetCDF grid variables. This works for 1, 2 or 3D grids_mod. More...
 
subroutine define_mean_fields (current_state, ncid)
 
subroutine define_q_variable (ncid, multi_process, q_dim_id, z_dim_id, y_dim_id, x_dim_id, q_id, zq_id)
 Defines the Q variable in the checkpoint file. More...
 
subroutine define_prognostic_variables (current_state, multi_process, ncid, z_dim_id, y_dim_id, x_dim_id, u_id, v_id, w_id, th_id, p_id, zu_id, zv_id, zw_id, zth_id)
 Defines prognostic variables in the NetCDF. This handles 1, 2 and 3D grids_mod and 1, 2 and 3D fields, which most likely have the same dimensions but this is not mandatory here. All prognostic fields are 3D, if the grid is not 3D then the empty (size 1) dimension is used in that dimension. More...
 
subroutine define_misc_variables (ncid, timestep_id, time_id, ugal_id, vgal_id, number_q_fields_id, dtm_id, dtm_new_id, absolute_new_dtm_id)
 Defines misc variables in the NetCDF file. More...
 
subroutine write_out_misc_variables (current_state, ncid, timestep_id, time_id, ugal_id, vgal_id, number_q_fields_id, dtm_id, dtm_new_id, absolute_new_dtm_id)
 Will dump out (write) misc model data to the checkpoint. More...
 
subroutine define_velocity_variable (ncid, multi_process, dimone, dimtwo, dimthree, field_name, field_id)
 Will define a single velocity variable in the NetCDF file. More...
 

Variables

character(len= *), parameter checkpoint_title = "MONC checkpoint file"
 Title of the NetCDF file. More...
 

Detailed Description

Writes out model state_mod to a checkpoint NetCDF file.

Function/Subroutine Documentation

◆ define_grid_dimensions()

subroutine checkpointer_write_checkpoint_mod::define_grid_dimensions ( type(model_state_type), intent(inout)  current_state,
integer, intent(in)  ncid,
integer, intent(out)  z_dim_id,
integer, intent(out)  y_dim_id,
integer, intent(out)  x_dim_id 
)
private

Will define the grid dimensions and works for 1, 2 or 3D grids_mod.

Parameters
current_stateThe current model state_mod
ncidThe NetCDF file id
z_dim_idThe NetCDF z dimension id that is provided by this procedure
y_dim_idThe NetCDF y dimension id that is provided by this procedure
x_dim_idThe NetCDF x dimension id that is provided by this procedure

Definition at line 399 of file writecheckpoint.F90.

399  type(model_state_type), intent(inout) :: current_state
400  integer, intent(in) :: ncid
401  integer, intent(out) :: z_dim_id, y_dim_id, x_dim_id
402 
403  integer :: empty_dim_id
404 
405  call check_status(nf90_def_dim(ncid, empty_dim_key, 1, empty_dim_id))
406 
407  if (current_state%global_grid%active(z_index)) then
408  call check_status(nf90_def_dim(ncid, z_dim_key, current_state%global_grid%size(z_index), z_dim_id))
409  call check_status(nf90_def_dim(ncid, zn_dim_key, current_state%global_grid%size(z_index), z_dim_id))
410  else
411  z_dim_id = empty_dim_id
412  end if
413  if (current_state%global_grid%active(y_index)) then
414  call check_status(nf90_def_dim(ncid, y_dim_key, current_state%global_grid%size(y_index), y_dim_id))
415  else
416  y_dim_id = empty_dim_id
417  end if
418  if (current_state%global_grid%active(x_index)) then
419  call check_status(nf90_def_dim(ncid, x_dim_key, current_state%global_grid%size(x_index), x_dim_id))
420  else
421  x_dim_id = empty_dim_id
422  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_grid_variables()

subroutine checkpointer_write_checkpoint_mod::define_grid_variables ( type(model_state_type), intent(inout)  current_state,
integer, intent(in)  ncid 
)
private

Defines the NetCDF grid variables. This works for 1, 2 or 3D grids_mod.

Parameters
current_stateThe current model state_mod
ncidThe NetCDF file id
z_dim_idThe NetCDF z dimension id
y_dim_idThe NetCDF y dimension id
x_dim_idThe NetCDF x dimension id
x_idThe NetCDF x variable id provided by this procedure
y_idThe NetCDF y variable id provided by this procedure
z_idThe NetCDF z variable id provided by this procedure

Definition at line 435 of file writecheckpoint.F90.

435  type(model_state_type), intent(inout) :: current_state
436  integer, intent(in) :: ncid
437 
438  integer :: var_id, z_dim_id
439 
440  if (current_state%global_grid%active(x_index)) then
441  call check_status(nf90_def_var(ncid, x_resolution, nf90_double, var_id))
442  call check_status(nf90_put_att(ncid, var_id, "units", "m"))
443  call check_status(nf90_def_var(ncid, x_top, nf90_double, var_id))
444  call check_status(nf90_put_att(ncid, var_id, "units", "m"))
445  call check_status(nf90_def_var(ncid, x_bottom, nf90_double, var_id))
446  call check_status(nf90_put_att(ncid, var_id, "units", "m"))
447  end if
448  if (current_state%global_grid%active(y_index)) then
449  call check_status(nf90_def_var(ncid, y_resolution, nf90_double, var_id))
450  call check_status(nf90_put_att(ncid, var_id, "units", "m"))
451  call check_status(nf90_def_var(ncid, y_top, nf90_double, var_id))
452  call check_status(nf90_put_att(ncid, var_id, "units", "m"))
453  call check_status(nf90_def_var(ncid, y_bottom, nf90_double, var_id))
454  call check_status(nf90_put_att(ncid, var_id, "units", "m"))
455  end if
456  if (current_state%global_grid%active(z_index)) then
457  call check_status(nf90_inq_dimid(ncid, z_dim_key, z_dim_id))
458  call check_status(nf90_def_var(ncid, z_key, nf90_double, z_dim_id, var_id))
459  call check_status(nf90_put_att(ncid, var_id, "units", "m"))
460  call check_status(nf90_inq_dimid(ncid, zn_dim_key, z_dim_id))
461  call check_status(nf90_def_var(ncid, zn_key, nf90_double, z_dim_id, var_id))
462  call check_status(nf90_put_att(ncid, var_id, "units", "m"))
463  end if
464  call check_status(nf90_inq_dimid(ncid, z_dim_key, z_dim_id))
465  call check_status(nf90_def_var(ncid, thref, nf90_double, z_dim_id, var_id))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_mean_fields()

subroutine checkpointer_write_checkpoint_mod::define_mean_fields ( type(model_state_type), intent(inout)  current_state,
integer, intent(in)  ncid 
)
private

Definition at line 469 of file writecheckpoint.F90.

469  type(model_state_type), intent(inout) :: current_state
470  integer, intent(in) :: ncid
471 
472  integer :: var_id, z_dim_id, q_dim_id, qdimids(2)
473 
474  call check_status(nf90_inq_dimid(ncid, z_dim_key, z_dim_id))
475 
476  if (allocated(current_state%global_grid%configuration%vertical%olubar)) then
477  call check_status(nf90_def_var(ncid, olubar, nf90_double, z_dim_id, var_id))
478  end if
479  if (allocated(current_state%global_grid%configuration%vertical%olzubar)) then
480  call check_status(nf90_def_var(ncid, olzubar, nf90_double, z_dim_id, var_id))
481  end if
482  if (allocated(current_state%global_grid%configuration%vertical%olvbar)) then
483  call check_status(nf90_def_var(ncid, olvbar, nf90_double, z_dim_id, var_id))
484  end if
485  if (allocated(current_state%global_grid%configuration%vertical%olzvbar)) then
486  call check_status(nf90_def_var(ncid, olzvbar, nf90_double, z_dim_id, var_id))
487  end if
488  if (allocated(current_state%global_grid%configuration%vertical%olthbar)) then
489  call check_status(nf90_def_var(ncid, olthbar, nf90_double, z_dim_id, var_id))
490  end if
491  if (allocated(current_state%global_grid%configuration%vertical%olzthbar)) then
492  call check_status(nf90_def_var(ncid, olzthbar, nf90_double, z_dim_id, var_id))
493  end if
494  if (allocated(current_state%global_grid%configuration%vertical%olqbar) .or. &
495  allocated(current_state%global_grid%configuration%vertical%olzqbar)) then
496  call check_status(nf90_inq_dimid(ncid, q_dim_key, q_dim_id))
497  qdimids=(/ z_dim_id, q_dim_id /)
498  if (allocated(current_state%global_grid%configuration%vertical%olqbar)) then
499  call check_status(nf90_def_var(ncid, olqbar, nf90_double, qdimids, var_id))
500  end if
501  if (allocated(current_state%global_grid%configuration%vertical%olzqbar)) then
502  call check_status(nf90_def_var(ncid, olzqbar, nf90_double, qdimids, var_id))
503  end if
504  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_misc_variables()

subroutine checkpointer_write_checkpoint_mod::define_misc_variables ( integer, intent(in)  ncid,
integer, intent(out)  timestep_id,
integer, intent(out)  time_id,
integer, intent(out)  ugal_id,
integer, intent(out)  vgal_id,
integer, intent(out)  number_q_fields_id,
integer, intent(out)  dtm_id,
integer, intent(out)  dtm_new_id,
integer, intent(out)  absolute_new_dtm_id 
)
private

Defines misc variables in the NetCDF file.

Parameters
ncidThe NetCDF file id
timestep_idThe NetCDF timestep variable

Definition at line 584 of file writecheckpoint.F90.

584  integer, intent(in) :: ncid
585  integer, intent(out) :: timestep_id, time_id, ugal_id, vgal_id, number_q_fields_id, dtm_id, dtm_new_id, absolute_new_dtm_id
586 
587  call check_status(nf90_def_var(ncid, timestep, nf90_int, timestep_id))
588  call check_status(nf90_def_var(ncid, time_key, nf90_double, time_id))
589  call check_status(nf90_def_var(ncid, ugal, nf90_double, ugal_id))
590  call check_status(nf90_def_var(ncid, vgal, nf90_double, vgal_id))
591  call check_status(nf90_def_var(ncid, nqfields, nf90_int, number_q_fields_id))
592  call check_status(nf90_def_var(ncid, dtm_key, nf90_double, dtm_id))
593  call check_status(nf90_def_var(ncid, dtm_new_key, nf90_double, dtm_new_id))
594  call check_status(nf90_def_var(ncid, absolute_new_dtm_key, nf90_double, absolute_new_dtm_id))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_options_variable()

subroutine checkpointer_write_checkpoint_mod::define_options_variable ( type(model_state_type), intent(inout)  current_state,
integer, intent(in)  ncid,
integer, intent(out)  string_dim_id,
integer, intent(out)  key_value_dim_id,
integer, intent(out)  options_id 
)
private

Defines the NetCDF options variable which is basically a 3D character array to form key-value pair strings for each entry.

Parameters
current_stateThe current model state_mod
ncidThe NetCDF file id
options_idThe NetCDF options variable id that is created in this procedure

Definition at line 338 of file writecheckpoint.F90.

338  type(model_state_type), intent(inout) :: current_state
339  integer, intent(in) :: ncid
340  integer, intent(out) :: string_dim_id, key_value_dim_id, options_id
341 
342  integer :: options_dim_id, command_dimensions(3)
343 
344  call check_status(nf90_def_dim(ncid, string_dim_key, string_length, string_dim_id))
345  call check_status(nf90_def_dim(ncid, key_value_pair_key, 2, key_value_dim_id))
346  call check_status(nf90_def_dim(ncid, options_dim_key, options_size(current_state%options_database), options_dim_id))
347 
348  command_dimensions = (/ string_dim_id, key_value_dim_id, options_dim_id /)
349 
350  call check_status(nf90_def_var(ncid, options_key, nf90_char, command_dimensions, options_id))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_prognostic_variables()

subroutine checkpointer_write_checkpoint_mod::define_prognostic_variables ( type(model_state_type), intent(inout)  current_state,
logical, intent(in)  multi_process,
integer, intent(in)  ncid,
integer, intent(in)  z_dim_id,
integer, intent(in)  y_dim_id,
integer, intent(in)  x_dim_id,
integer, intent(out)  u_id,
integer, intent(out)  v_id,
integer, intent(out)  w_id,
integer, intent(out)  th_id,
integer, intent(out)  p_id,
integer, intent(out)  zu_id,
integer, intent(out)  zv_id,
integer, intent(out)  zw_id,
integer, intent(out)  zth_id 
)
private

Defines prognostic variables in the NetCDF. This handles 1, 2 and 3D grids_mod and 1, 2 and 3D fields, which most likely have the same dimensions but this is not mandatory here. All prognostic fields are 3D, if the grid is not 3D then the empty (size 1) dimension is used in that dimension.

Parameters
current_stateThe current model state_mod
ncidThe NetCDF file id
z_dim_idThe NetCDF z dimension id
y_dim_idThe NetCDF y dimension id
x_dim_idThe NetCDF x dimension id
u_idThe u prognostic field id provided by this procedure
v_idThe v prognostic field id provided by this procedure
w_idThe w prognostic field id provided by this procedure
th_idThe theta prognostic field id provided by this procedure

Definition at line 553 of file writecheckpoint.F90.

553  type(model_state_type), intent(inout) :: current_state
554  logical, intent(in) :: multi_process
555  integer, intent(in) :: ncid, z_dim_id, y_dim_id, x_dim_id
556  integer, intent(out) :: u_id, v_id, w_id, th_id, p_id, zu_id, zv_id, zw_id, zth_id
557 
558 #ifdef U_ACTIVE
559  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=u_key, field_id=u_id)
560  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=zu_key, field_id=zu_id)
561 #endif
562 #ifdef V_ACTIVE
563  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=v_key, field_id=v_id)
564  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=zv_key, field_id=zv_id)
565 #endif
566 #ifdef W_ACTIVE
567  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=w_key, field_id=w_id)
568  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=zw_key, field_id=zw_id)
569 #endif
570  if (current_state%th%active) then
571  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=th_key, field_id=th_id)
572  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=zth_key, field_id=zth_id)
573  end if
574  if (current_state%p%active) then
575  call define_velocity_variable(ncid, multi_process, z_dim_id, y_dim_id, x_dim_id, field_name=p_key, field_id=p_id)
576  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_q_field_dimension()

subroutine checkpointer_write_checkpoint_mod::define_q_field_dimension ( type(model_state_type), intent(inout)  current_state,
integer, intent(in)  ncid,
integer, intent(out)  q_dim_id 
)
private

Defines the Q field dimension in the NetCDF.

Parameters
current_stateThe current model state_mod
ncidThe NetCDF file id
q_dim_idCorresponding NetCDF Q dimension id

Definition at line 385 of file writecheckpoint.F90.

385  type(model_state_type), intent(inout) :: current_state
386  integer, intent(in) :: ncid
387  integer, intent(out) :: q_dim_id
388 
389  call check_status(nf90_def_dim(ncid, q_dim_key, current_state%number_q_fields, q_dim_id))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_q_indices_variable()

logical function checkpointer_write_checkpoint_mod::define_q_indices_variable ( integer, intent(in)  ncid,
integer, intent(in)  string_dim_id,
integer, intent(in)  key_value_dim_id,
integer, intent(out)  q_indices_id 
)
private

Defines the NetCDF Q indices variable which is, same as the options, stored as key-value pair of strings. This will only store and create these dimensions if there are any Q indicies to store.

Parameters
ncidThe NetCDF file id
string_dim_idThe id of the string dimension
key_value_dim_idThe id of the key value pair dimension
q_indices_idThe id that represents this variable in the NetCDF
Returns
Whether or not the dimensions and variable has been declared (it won't be if there are no active Q indicies)

Definition at line 361 of file writecheckpoint.F90.

361  integer, intent(in) :: ncid, string_dim_id, key_value_dim_id
362  integer, intent(out) :: q_indices_id
363 
364  integer :: q_indices_dim_id, command_dimensions(3), number_active_q
365 
366  number_active_q=get_number_active_q_indices()
367 
368  if (number_active_q == 0) then
369  define_q_indices_variable=.false.
370  else
371  call check_status(nf90_def_dim(ncid, q_indices_dim_key, number_active_q, q_indices_dim_id))
372 
373  command_dimensions = (/ string_dim_id, key_value_dim_id, q_indices_dim_id /)
374 
375  call check_status(nf90_def_var(ncid, q_indices_key, nf90_char, command_dimensions, q_indices_id))
376  define_q_indices_variable=.true.
377  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_q_variable()

subroutine checkpointer_write_checkpoint_mod::define_q_variable ( integer, intent(in)  ncid,
logical, intent(in)  multi_process,
integer, intent(in)  q_dim_id,
integer, intent(in)  z_dim_id,
integer, intent(in)  y_dim_id,
integer, intent(in)  x_dim_id,
integer, intent(out)  q_id,
integer, intent(out)  zq_id 
)
private

Defines the Q variable in the checkpoint file.

Parameters
ncidThe NetCDF file id
multi_processWhether to support parallel IO operations or not
q_dim_idThe NetCDF q dimension id
z_dim_idThe NetCDF z dimension id
y_dim_idThe NetCDF y dimension id
x_dim_idThe NetCDF x dimension id
q_idThe NetCDF q variable id provided by this procedure
zq_idThe NetCDF zq variable id provided by this procedure

Definition at line 517 of file writecheckpoint.F90.

517  logical, intent(in) :: multi_process
518  integer, intent(in) :: ncid, z_dim_id, y_dim_id, x_dim_id, q_dim_id
519  integer, intent(out) :: q_id, zq_id
520 
521  integer, dimension(:), allocatable :: dimids
522 
523  allocate(dimids(4))
524  dimids = (/ z_dim_id, y_dim_id, x_dim_id, q_dim_id /)
525 
526  call check_status(nf90_def_var(ncid, q_key, merge(nf90_double, nf90_real, &
527  default_precision == double_precision), dimids, q_id))
528  call check_status(nf90_def_var(ncid, zq_key, merge(nf90_double, nf90_real, &
529  default_precision == double_precision), dimids, zq_id))
530 
531  if (multi_process) then
532  call check_status(nf90_def_var_fill(ncid, q_id, 1, 1))
533  call check_status(nf90_def_var_fill(ncid, zq_id, 1, 1))
534  call check_status(nf90_var_par_access(ncid, q_id, nf90_collective))
535  call check_status(nf90_var_par_access(ncid, zq_id, nf90_collective))
536  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ define_velocity_variable()

subroutine checkpointer_write_checkpoint_mod::define_velocity_variable ( integer, intent(in)  ncid,
logical, intent(in)  multi_process,
integer, intent(in)  dimone,
integer, intent(in), optional  dimtwo,
integer, intent(in), optional  dimthree,
character(len=*), intent(in)  field_name,
integer, intent(out)  field_id 
)
private

Will define a single velocity variable in the NetCDF file.

Parameters
ncidThe NetCDF file id
dimoneSize in first dimension
dimtwoSize in second dimension (optional)
dimthreeSize in third dimension (optional)
field_nameThe NetCDF name of the variable
field_idThe NetCDF variable id produced by this procedure

Definition at line 626 of file writecheckpoint.F90.

626  integer, intent(in) :: ncid, dimone
627  integer, intent(in), optional :: dimtwo, dimthree
628  integer, intent(out) :: field_id
629  character(len=*), intent(in) :: field_name
630  logical, intent(in) :: multi_process
631 
632  integer, dimension(:), allocatable :: dimids
633 
634  if (present(dimtwo) .and. present(dimthree)) then
635  allocate(dimids(3))
636  dimids = (/ dimone, dimtwo, dimthree /)
637  else if (present(dimtwo) .or. present(dimthree)) then
638  allocate(dimids(2))
639  dimids = (/ dimone, merge(dimtwo, dimthree, present(dimtwo)) /)
640  else
641  allocate(dimids(1))
642  dimids = (/ dimone /)
643  end if
644 
645  call check_status(nf90_def_var(ncid, field_name, merge(nf90_double, nf90_real, default_precision == double_precision), &
646  dimids, field_id))
647  if (multi_process) then
648  call check_status(nf90_def_var_fill(ncid, field_id, 1, 1))
649  call check_status(nf90_var_par_access(ncid, field_id, nf90_collective))
650  end if
651  call check_status(nf90_put_att(ncid, field_id, "units", "m/s"))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_checkpoint_file()

subroutine, public checkpointer_write_checkpoint_mod::write_checkpoint_file ( type(model_state_type), intent(inout)  current_state,
character(len=*), intent(in)  filename 
)

Will write out the current model state_mod into a NetCDF checkpoint file.

Parameters
currentStateThe current model state_mod
filenameThe filename of the NetCDF file that will be written

Definition at line 41 of file writecheckpoint.F90.

41  type(model_state_type), intent(inout) :: current_state
42  character(len=*), intent(in) :: filename
43 
44  integer :: ncid, z_dim_id, y_dim_id, x_dim_id, q_dim_id, x_id, y_id, z_id, th_id, p_id, time_id,&
45  u_id, v_id, w_id, q_id, zu_id, zv_id, zw_id, zth_id, zq_id, timestep_id, ugal_id, &
46  vgal_id, number_q_fields_id, string_dim_id, key_value_dim_id, options_id, q_indices_id, &
47  dtm_id, dtm_new_id, absolute_new_dtm_id
48  logical :: q_indices_declared
49 
50 #ifdef SINGLE_MONC_DO_SEQUENTIAL_NETCDF
51  if (current_state%parallel%processes .gt. 1) then
52  call check_status(nf90_create(filename, ior(nf90_netcdf4, nf90_mpiio), ncid, &
53  comm = current_state%parallel%monc_communicator, info = mpi_info_null))
54  else
55  call check_status(nf90_create(filename, nf90_clobber, ncid))
56  end if
57 #else
58  call check_status(nf90_create(filename, ior(nf90_netcdf4, nf90_mpiio), ncid, &
59  comm = current_state%parallel%monc_communicator, info = mpi_info_null))
60 #endif
61  call write_out_global_attributes(ncid)
62  call define_grid_dimensions(current_state, ncid, z_dim_id, y_dim_id, x_dim_id)
63  if (current_state%number_q_fields .gt. 0) call define_q_field_dimension(current_state, ncid, q_dim_id)
64 
65  call define_options_variable(current_state, ncid, string_dim_id, key_value_dim_id, options_id)
66  q_indices_declared=define_q_indices_variable(ncid, string_dim_id, key_value_dim_id, q_indices_id)
67  call define_grid_variables(current_state, ncid)
68  call define_mean_fields(current_state, ncid)
69  if (current_state%number_q_fields .gt. 0) call define_q_variable(ncid, current_state%parallel%processes .gt. 1, &
70  q_dim_id, z_dim_id, y_dim_id, x_dim_id, q_id, zq_id)
71  call define_prognostic_variables(current_state, current_state%parallel%processes .gt. 1, ncid, z_dim_id, y_dim_id, &
72  x_dim_id, u_id, v_id, w_id, th_id, p_id, zu_id, zv_id, zw_id, zth_id)
73  call define_misc_variables(ncid, timestep_id, time_id, ugal_id, vgal_id, number_q_fields_id, &
74  dtm_id, dtm_new_id, absolute_new_dtm_id)
75 
76  call check_status(nf90_enddef(ncid))
77 
78  if (current_state%parallel%my_rank==0) call write_out_grid(ncid, current_state%global_grid)
79  if (current_state%parallel%my_rank==0) call write_out_mean_fields(ncid, current_state%global_grid)
80  call write_out_all_fields(current_state, ncid, u_id, v_id, w_id, zu_id, zv_id, zw_id, th_id, zth_id, q_id, zq_id, p_id)
81  if (current_state%parallel%my_rank==0) then
82  call write_out_options(current_state, ncid, options_id)
83  if (q_indices_declared) call write_out_q_indices(ncid, q_indices_id)
84  call write_out_misc_variables(current_state, ncid, timestep_id, time_id, &
85  ugal_id, vgal_id, number_q_fields_id, dtm_id, dtm_new_id, absolute_new_dtm_id)
86  end if
87 
88  call check_status(nf90_close(ncid))
Here is the call graph for this function:

◆ write_out_all_fields()

subroutine checkpointer_write_checkpoint_mod::write_out_all_fields ( type(model_state_type), intent(inout)  current_state,
integer, intent(in)  ncid,
integer, intent(in)  u_id,
integer, intent(in)  v_id,
integer, intent(in)  w_id,
integer, intent(in)  zu_id,
integer, intent(in)  zv_id,
integer, intent(in)  zw_id,
integer, intent(in)  th_id,
integer, intent(in)  zth_id,
integer, intent(in)  q_id,
integer, intent(in)  zq_id,
integer, intent(in)  p_id 
)
private

Will write out all prognostic model fields to the checkpoint. It will work in 1, 2 or 3D depending on the model.

Parameters
current_stateThe current model state_mod
ncidThe NetCDF file id
u_idThe NetCDF u field dimension id
v_idThe NetCDF v field dimension id
w_idThe NetCDF w field dimension id

Definition at line 166 of file writecheckpoint.F90.

166  type(model_state_type), intent(inout) :: current_state
167  integer, intent(in) :: ncid, u_id, v_id, w_id, zu_id, zv_id, zw_id, th_id, zth_id, q_id, zq_id, p_id
168 
169  integer :: i
170  logical :: multi_process
171 
172  multi_process = current_state%parallel%processes .gt. 1
173 #ifdef U_ACTIVE
174  call write_out_velocity_field(ncid, current_state%local_grid, current_state%u, u_id, multi_process)
175  call write_out_velocity_field(ncid, current_state%local_grid, current_state%zu, zu_id, multi_process)
176 #endif
177 #ifdef V_ACTIVE
178  call write_out_velocity_field(ncid, current_state%local_grid, current_state%v, v_id, multi_process)
179  call write_out_velocity_field(ncid, current_state%local_grid, current_state%zv, zv_id, multi_process)
180 #endif
181 #ifdef W_ACTIVE
182  call write_out_velocity_field(ncid, current_state%local_grid, current_state%w, w_id, multi_process)
183  call write_out_velocity_field(ncid, current_state%local_grid, current_state%zw, zw_id, multi_process)
184 #endif
185  if (current_state%th%active) then
186  call write_out_velocity_field(ncid, current_state%local_grid, current_state%th, th_id, multi_process)
187  call write_out_velocity_field(ncid, current_state%local_grid, current_state%zth, zth_id, multi_process)
188  end if
189  if (current_state%p%active) call write_out_velocity_field(ncid, current_state%local_grid, current_state%p, &
190  p_id, multi_process)
191  do i=1,current_state%number_q_fields
192  if (current_state%q(i)%active) then
193  call write_out_velocity_field(ncid, current_state%local_grid, current_state%q(i), q_id, multi_process, i)
194  call write_out_velocity_field(ncid, current_state%local_grid, current_state%zq(i), zq_id, multi_process, i)
195  end if
196  end do
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_out_global_attributes()

subroutine checkpointer_write_checkpoint_mod::write_out_global_attributes ( integer, intent(in)  ncid)
private

Writes out global attributes into the checkpoint.

Parameters
ncidNetCDF file id

Definition at line 94 of file writecheckpoint.F90.

94  integer, intent(in) :: ncid
95 
96  integer :: date_values(8)
97 
98  call date_and_time(values=date_values)
99 
100  call check_status(nf90_put_att(ncid, nf90_global, title_attribute_key, checkpoint_title))
101  call check_status(nf90_put_att(ncid, nf90_global, created_attribute_key, trim(conv_to_string(date_values(3)))//"/"//&
102  trim(conv_to_string(date_values(2)))//"/"//trim(conv_to_string(date_values(1)))//" "//trim(conv_to_string(&
103  date_values(5)))// ":"//trim(conv_to_string(date_values(6)))//":"//trim(conv_to_string(date_values(7)))))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_out_grid()

subroutine checkpointer_write_checkpoint_mod::write_out_grid ( integer, intent(in)  ncid,
type(global_grid_type), intent(in)  grid 
)
private

Will write out the grid to the checkpoint, it will work in 1, 2 or 3D depending on what is in the model.

Parameters
ncidThe NetCDF file id
gridThe model grid to write out
z_idThe NetCDF z variable id
y_idThe NetCDF y variable id
x_idThe NetCDF x variable id

Definition at line 248 of file writecheckpoint.F90.

248  integer, intent(in) :: ncid
249  type(global_grid_type), intent(in) :: grid
250 
251  integer :: var_id
252 
253  if (grid%active(z_index)) then
254  call write_z_grid_gimension(ncid, grid%configuration%vertical)
255  end if
256  if (grid%active(y_index)) then
257  call check_status(nf90_inq_varid(ncid, y_resolution, var_id))
258  call check_status(nf90_put_var(ncid, var_id, grid%resolution(y_index)))
259  call check_status(nf90_inq_varid(ncid, y_top, var_id))
260  call check_status(nf90_put_var(ncid, var_id, grid%top(y_index)))
261  call check_status(nf90_inq_varid(ncid, y_bottom, var_id))
262  call check_status(nf90_put_var(ncid, var_id, grid%bottom(y_index)))
263  end if
264  if (grid%active(x_index)) then
265  call check_status(nf90_inq_varid(ncid, x_resolution, var_id))
266  call check_status(nf90_put_var(ncid, var_id, grid%resolution(x_index)))
267  call check_status(nf90_inq_varid(ncid, x_top, var_id))
268  call check_status(nf90_put_var(ncid, var_id, grid%top(x_index)))
269  call check_status(nf90_inq_varid(ncid, x_bottom, var_id))
270  call check_status(nf90_put_var(ncid, var_id, grid%bottom(x_index)))
271  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_out_mean_fields()

subroutine checkpointer_write_checkpoint_mod::write_out_mean_fields ( integer, intent(in)  ncid,
type(global_grid_type), intent(in)  grid 
)
private

Definition at line 275 of file writecheckpoint.F90.

275  integer, intent(in) :: ncid
276  type(global_grid_type), intent(in) :: grid
277 
278  integer :: var_id
279 
280  if (allocated(grid%configuration%vertical%olubar)) then
281  call check_status(nf90_inq_varid(ncid, olubar, var_id))
282  call check_status(nf90_put_var(ncid, var_id, grid%configuration%vertical%olubar))
283  end if
284  if (allocated(grid%configuration%vertical%olzubar)) then
285  call check_status(nf90_inq_varid(ncid, olzubar, var_id))
286  call check_status(nf90_put_var(ncid, var_id, grid%configuration%vertical%olzubar))
287  end if
288  if (allocated(grid%configuration%vertical%olvbar)) then
289  call check_status(nf90_inq_varid(ncid, olvbar, var_id))
290  call check_status(nf90_put_var(ncid, var_id, grid%configuration%vertical%olvbar))
291  end if
292  if (allocated(grid%configuration%vertical%olzvbar)) then
293  call check_status(nf90_inq_varid(ncid, olzvbar, var_id))
294  call check_status(nf90_put_var(ncid, var_id, grid%configuration%vertical%olzvbar))
295  end if
296  if (allocated(grid%configuration%vertical%olthbar)) then
297  call check_status(nf90_inq_varid(ncid, olthbar, var_id))
298  call check_status(nf90_put_var(ncid, var_id, grid%configuration%vertical%olthbar))
299  end if
300  if (allocated(grid%configuration%vertical%olzthbar)) then
301  call check_status(nf90_inq_varid(ncid, olzthbar, var_id))
302  call check_status(nf90_put_var(ncid, var_id, grid%configuration%vertical%olzthbar))
303  end if
304  if (allocated(grid%configuration%vertical%olqbar)) then
305  call check_status(nf90_inq_varid(ncid, olqbar, var_id))
306  call check_status(nf90_put_var(ncid, var_id, grid%configuration%vertical%olqbar))
307  end if
308  if (allocated(grid%configuration%vertical%olzqbar)) then
309  call check_status(nf90_inq_varid(ncid, olzqbar, var_id))
310  call check_status(nf90_put_var(ncid, var_id, grid%configuration%vertical%olzqbar))
311  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_out_misc_variables()

subroutine checkpointer_write_checkpoint_mod::write_out_misc_variables ( type(model_state_type), intent(inout)  current_state,
integer, intent(in)  ncid,
integer, intent(in)  timestep_id,
integer, intent(in)  time_id,
integer, intent(in)  ugal_id,
integer, intent(in)  vgal_id,
integer, intent(in)  number_q_fields_id,
integer, intent(in)  dtm_id,
integer, intent(in)  dtm_new_id,
integer, intent(in)  absolute_new_dtm_id 
)
private

Will dump out (write) misc model data to the checkpoint.

Parameters
current_stateThe current model state_mod
ncidThe NetCDF file id
timestep_idThe NetCDF timestep variable id

Definition at line 603 of file writecheckpoint.F90.

603  type(model_state_type), intent(inout) :: current_state
604  integer, intent(in) :: ncid, timestep_id, time_id, ugal_id, vgal_id, number_q_fields_id, &
605  dtm_id, dtm_new_id, absolute_new_dtm_id
606 
607  call check_status(nf90_put_var(ncid, timestep_id, current_state%timestep))
608  ! The time is incremented with dtm as the model was about to increment for the next step and this is needed for diagnostics
609  call check_status(nf90_put_var(ncid, time_id, current_state%time+current_state%dtm))
610  call check_status(nf90_put_var(ncid, ugal_id, current_state%ugal))
611  call check_status(nf90_put_var(ncid, vgal_id, current_state%vgal))
612  call check_status(nf90_put_var(ncid, number_q_fields_id, current_state%number_q_fields))
613  call check_status(nf90_put_var(ncid, dtm_id, current_state%dtm))
614  call check_status(nf90_put_var(ncid, dtm_new_id, current_state%dtm_new))
615  call check_status(nf90_put_var(ncid, absolute_new_dtm_id, current_state%absolute_new_dtm))
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_out_options()

subroutine checkpointer_write_checkpoint_mod::write_out_options ( type(model_state_type), intent(inout)  current_state,
integer, intent(in)  ncid,
integer, intent(in)  options_id 
)
private

Writes out the options that the model was run with.

Parameters
current_stateThe current model state_mod
ncidThe NetCDF file id
options_idThe options NetCDF variable id

Definition at line 131 of file writecheckpoint.F90.

131  type(model_state_type), intent(inout) :: current_state
132  integer, intent(in) :: ncid, options_id
133 
134  integer :: i
135  character(len=STRING_LENGTH), pointer :: sized_raw_character
136  class(*), pointer :: raw_data, raw_to_string
137 
138  do i=1,options_size(current_state%options_database)
139  raw_data=> options_value_at(current_state%options_database, i)
140  raw_to_string=>raw_data
141  call check_status(nf90_put_var(ncid, options_id, trim(options_key_at(current_state%options_database, i)), (/ 1, 1, i /)))
142  select type (raw_data)
143  type is(integer)
144  call check_status(nf90_put_var(ncid, options_id, trim(conv_to_string(raw_data)), (/ 1, 2, i /)))
145  type is(real(kind=single_precision))
146  call check_status(nf90_put_var(ncid, options_id, trim(conv_to_string(raw_data)), (/ 1, 2, i /)))
147  type is(real(kind=double_precision))
148  call check_status(nf90_put_var(ncid, options_id, trim(conv_to_string(raw_data)), (/ 1, 2, i /)))
149  type is(logical)
150  call check_status(nf90_put_var(ncid, options_id, trim(conv_to_string(raw_data)), (/ 1, 2, i /)))
151  type is(character(len=*))
152  ! Done this way to give the character size information and keep the (unsafe) cast in the conversion module
153  sized_raw_character=>conv_to_string(raw_to_string, .false., string_length)
154  call check_status(nf90_put_var(ncid, options_id, trim(sized_raw_character), (/ 1, 2, i /)))
155  end select
156  end do
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_out_q_indices()

subroutine checkpointer_write_checkpoint_mod::write_out_q_indices ( integer, intent(in)  ncid,
integer, intent(in)  q_indices_id 
)
private

Writes out the specific Q indicies that are active and need writing.

Parameters
ncidThe NetCDF file id
q_indicies_idThe Q indicies NetCDF variable id

Definition at line 110 of file writecheckpoint.F90.

110  integer, intent(in) :: ncid, q_indices_id
111 
112  integer :: i, current_index
113  type(q_metadata_type) :: specific_q_data
114 
115  current_index=1
116  do i=1, get_max_number_q_indices()
117  specific_q_data=get_indices_descriptor(i)
118  if (specific_q_data%l_used) then
119  call check_status(nf90_put_var(ncid, q_indices_id, trim(specific_q_data%name), (/ 1, 1, current_index /)))
120  call check_status(nf90_put_var(ncid, q_indices_id, trim(conv_to_string(i)), (/ 1, 2, current_index /)))
121  current_index=current_index+1
122  end if
123  end do
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_out_velocity_field()

subroutine checkpointer_write_checkpoint_mod::write_out_velocity_field ( integer, intent(in)  ncid,
type(local_grid_type), intent(inout)  local_grid,
type(prognostic_field_type), intent(in)  field,
integer, intent(in)  variable_id,
logical, intent(in)  multi_process,
integer, intent(in), optional  fourth_dim_loc 
)
private

Will write out a single velocity field to the checkpoint file. If there are multiple processes then will determine the bounds, otherwise for serial just dump data field.

Parameters
ncidThe NetCDF file id
fieldThe model prognostic field to write out
variable_idThe NetCDF variable dimension id

Definition at line 205 of file writecheckpoint.F90.

205  integer, intent(in) :: ncid, variable_id
206  type(prognostic_field_type), intent(in) :: field
207  type(local_grid_type), intent(inout) :: local_grid
208  logical, intent(in) :: multi_process
209  integer, optional, intent(in) :: fourth_dim_loc
210 
211  integer :: start(4), count(4), i, map(4)
212 
213  if (multi_process .or. present(fourth_dim_loc)) then
214  do i=1,3
215  if (i==1) then
216  map(i)=1
217  else
218  map(i)=map(i-1)*local_grid%size(i-1)
219  end if
220  start(i) = local_grid%start(i)
221  count(i) = local_grid%size(i)
222  end do
223  if (present(fourth_dim_loc)) then
224  start(4) = fourth_dim_loc
225  count(4) = 1
226  map(4)=map(3)*local_grid%size(3)
227  end if
228 
229  call check_status(nf90_put_var(ncid, variable_id, field%data(local_grid%local_domain_start_index(z_index):&
230  local_grid%local_domain_end_index(z_index),local_grid%local_domain_start_index(y_index):&
231  local_grid%local_domain_end_index(y_index), local_grid%local_domain_start_index(x_index):&
232  local_grid%local_domain_end_index(x_index)), start=start, count=count))
233  else
234  call check_status(nf90_put_var(ncid, variable_id, field%data(local_grid%local_domain_start_index(z_index):&
235  local_grid%local_domain_end_index(z_index),local_grid%local_domain_start_index(y_index):&
236  local_grid%local_domain_end_index(y_index), local_grid%local_domain_start_index(x_index):&
237  local_grid%local_domain_end_index(x_index))))
238  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_z_grid_gimension()

subroutine checkpointer_write_checkpoint_mod::write_z_grid_gimension ( integer, intent(in)  ncid,
type(vertical_grid_configuration_type), intent(in)  vertical_grid 
)
private

Writes out the Z dimension of the grids_mod points which are explicitly calculated.

Parameters
ncidThe NetCDF file id
verticalGridThe vertical grid configuration
z_idThe NetCDF id of the z field

Definition at line 319 of file writecheckpoint.F90.

319  type(vertical_grid_configuration_type), intent(in) :: vertical_grid
320  integer, intent(in) :: ncid
321 
322  integer :: z_var_id, zn_var_id, thref_var_id
323 
324  call check_status(nf90_inq_varid(ncid, z_key, z_var_id))
325  call check_status(nf90_put_var(ncid, z_var_id, vertical_grid%z))
326  call check_status(nf90_inq_varid(ncid, zn_key, zn_var_id))
327  call check_status(nf90_put_var(ncid, zn_var_id, vertical_grid%zn))
328  call check_status(nf90_inq_varid(ncid, thref, thref_var_id))
329  call check_status(nf90_put_var(ncid, thref_var_id, vertical_grid%thref))
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ checkpoint_title

character(len=*), parameter checkpointer_write_checkpoint_mod::checkpoint_title = "MONC checkpoint file"
private

Title of the NetCDF file.

Definition at line 31 of file writecheckpoint.F90.

31  character(len=*), parameter :: checkpoint_title = "MONC checkpoint file"