MONC
checkpointnetcdfparser.F90
Go to the documentation of this file.
1 
3  use datadefn_mod, only : string_length
4  use collections_mod, only : hashmap_type
5  use netcdf, only : nf90_nowrite, nf90_netcdf4, nf90_mpiio, nf90_noerr, nf90_strerror, nf90_open, nf90_close, &
6  nf90_inq_dimid, nf90_inquire_dimension, nf90_inq_varid, nf90_get_var
11  use mpi, only : mpi_info_null
13  implicit none
14 
15 #ifndef TEST_MODE
16  private
17 #endif
18 
19  character(len=*), parameter :: options_key="options_database", & !< The options key which references the configuration
20  options_dim_key="number_options"
21 
23 contains
24 
29  subroutine parse_configuration_checkpoint_netcdf(options_database, checkpoint_name, communicator)
30  type(hashmap_type), intent(inout) :: options_database
31  character(*), intent(in) :: checkpoint_name
32  integer, intent(in) :: communicator
33 
34  integer :: ncid
35 
36  call check_netcdf_status(nf90_open(path = checkpoint_name, mode = nf90_nowrite, ncid = ncid))
37  call load_options(options_database, ncid)
38  call check_netcdf_status(nf90_close(ncid))
40 
44  subroutine load_options(options_database, ncid)
45  type(hashmap_type), intent(inout) :: options_database
46  integer, intent(in) :: ncid
47 
48  integer :: i, options_id, number_options
49  character(len=STRING_LENGTH) :: key, value
50 
51  number_options=get_number_of_options(ncid)
52  call check_netcdf_status(nf90_inq_varid(ncid, options_key, options_id))
53 
54  do i=1, number_options
55  call check_netcdf_status(nf90_get_var(ncid, options_id, key, (/ 1, 1, i /)))
56  call check_netcdf_status(nf90_get_var(ncid, options_id, value, (/ 1, 2, i /)))
57  ! NetCDF does C style null termination right at the end, need to remove this so can trim spaces etc
60  if (conv_is_integer(trim(value))) then
61  call options_add(options_database, trim(key), conv_to_integer(trim(value)))
62  else if (conv_is_real(trim(value))) then
63  call options_add(options_database, trim(key), conv_single_real_to_double(conv_to_real(trim(value))))
64  else if (conv_is_logical(trim(value))) then
65  call options_add(options_database, trim(key), conv_to_logical(trim(value)))
66  else
67  call options_add(options_database, trim(key), trim(value))
68  end if
69  end do
70  end subroutine load_options
71 
75  subroutine remove_null_terminator_from_string(net_cdf_string)
76  character(len=*), intent(inout) :: net_cdf_string
77  integer :: i
78  do i=1,len(net_cdf_string)
79  if (iachar(net_cdf_string(i:i)) == 0) then
80  net_cdf_string(i:len(net_cdf_string)) = ' '
81  exit
82  end if
83  end do
85 
89  integer function get_number_of_options(ncid)
90  integer, intent(in) :: ncid
91 
92  integer :: options_dimid, options_dim
93  call check_netcdf_status(nf90_inq_dimid(ncid, options_dim_key, options_dimid))
94  call check_netcdf_status(nf90_inquire_dimension(ncid, options_dimid, len=options_dim))
95  get_number_of_options=options_dim
96  end function get_number_of_options
logging_mod::log_error
integer, parameter, public log_error
Only log ERROR messages.
Definition: logging.F90:11
conversions_mod
Conversion between common inbuilt FORTRAN data types.
Definition: conversions.F90:5
netcdf_misc_mod
NetCDF misc functionality which can be shared between modules that work with NetCDF files.
Definition: netcdf_misc.F90:2
conversions_mod::conv_is_logical
Determines whether a data item can be represented as a logical or not.
Definition: conversions.F90:100
configuration_checkpoint_netcdf_parser_mod::options_dim_key
character(len= *), parameter options_dim_key
Options dimension key.
Definition: checkpointnetcdfparser.F90:19
conversions_mod::conv_to_integer
Converts data types to integers.
Definition: conversions.F90:49
configuration_checkpoint_netcdf_parser_mod
Loads in the configuration stored in a NetCDF checkpoint file for the model to start from.
Definition: checkpointnetcdfparser.F90:2
collections_mod
Collection data structures.
Definition: collections.F90:7
collections_mod::hashmap_type
A hashmap structure, the same as a map but uses hashing for greatly improved performance when storing...
Definition: collections.F90:94
conversions_mod::conv_to_logical
Converts data types to logical.
Definition: conversions.F90:71
optionsdatabase_mod::options_add
Generic add interface for adding different types of data to the databases.
Definition: optionsdatabase.F90:28
configuration_checkpoint_netcdf_parser_mod::parse_configuration_checkpoint_netcdf
subroutine, public parse_configuration_checkpoint_netcdf(options_database, checkpoint_name, communicator)
Will parse the NetCDF checkpoint file and loads the configuration into the options database.
Definition: checkpointnetcdfparser.F90:30
conversions_mod::conv_is_real
Determines whether a data item can be represented as a real or not.
Definition: conversions.F90:91
conversions_mod::conv_is_integer
Determines whether a data item can be represented as an integer or not.
Definition: conversions.F90:81
configuration_checkpoint_netcdf_parser_mod::get_number_of_options
integer function get_number_of_options(ncid)
Retrieves the number of option key-value pairs that are present in the checkpoint file.
Definition: checkpointnetcdfparser.F90:90
configuration_checkpoint_netcdf_parser_mod::remove_null_terminator_from_string
subroutine remove_null_terminator_from_string(net_cdf_string)
Removes NetCDF C style null termination of string. This is placed right at the end,...
Definition: checkpointnetcdfparser.F90:76
logging_mod
Logging utility.
Definition: logging.F90:2
datadefn_mod
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
datadefn_mod::string_length
integer, parameter, public string_length
Default length of strings.
Definition: datadefn.F90:10
netcdf_misc_mod::check_netcdf_status
subroutine, public check_netcdf_status(status, found_flag)
Will check a NetCDF status and write to log_log error any decoded statuses. Can be used to decode whe...
Definition: netcdf_misc.F90:19
logging_mod::log_master_log
subroutine, public log_master_log(level, message)
Will log just from the master process.
Definition: logging.F90:47
configuration_checkpoint_netcdf_parser_mod::options_key
character(len= *), parameter options_key
The options key which references the configuration.
Definition: checkpointnetcdfparser.F90:19
configuration_checkpoint_netcdf_parser_mod::load_options
subroutine load_options(options_database, ncid)
Will read in and initialise the options database from the contents of the checkpoint file.
Definition: checkpointnetcdfparser.F90:45
conversions_mod::conv_to_real
Converts data types to real.
Definition: conversions.F90:60
optionsdatabase_mod
Manages the options database. Contains administration functions and deduce runtime options from the c...
Definition: optionsdatabase.F90:7
conversions_mod::conv_single_real_to_double
real(kind=double_precision) function, public conv_single_real_to_double(input_real)
Converts from a single to double precision real. This applies some rounding to a certain number of de...
Definition: conversions.F90:114