4 use netcdf
, only : nf90_double, nf90_real, nf90_int, nf90_char, nf90_global, nf90_clobber, nf90_netcdf4, nf90_mpiio, &
5 nf90_collective, nf90_def_var, nf90_var_par_access, nf90_def_var_fill, nf90_put_att, nf90_create, nf90_put_var, &
6 nf90_def_dim, nf90_enddef, nf90_close, nf90_inq_dimid, nf90_inq_varid
17 x_dim_key,
y_dim_key,
z_dim_key,
zn_dim_key,
q_dim_key,
q_key,
zq_key,
th_key,
zth_key,
p_key,
u_key,
v_key,
w_key, &
18 zu_key,
zv_key,
zw_key,
x_key,
y_key,
z_key,
zn_key,
nqfields,
ugal,
vgal,
time_key,
timestep,
max_string_length, &
20 q_indices_dim_key,
x_resolution,
y_resolution,
x_top,
y_top,
x_bottom,
y_bottom,
thref,
olubar,
olzubar,
olvbar, &
24 use mpi
, only : mpi_info_null
42 character(len=*),
intent(in) :: filename
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
50 #ifdef SINGLE_MONC_DO_SEQUENTIAL_NETCDF 51 if (current_state%parallel%processes .gt. 1)
then 53 comm = current_state%parallel%monc_communicator, info = mpi_info_null))
59 comm = current_state%parallel%monc_communicator, info = mpi_info_null))
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)
72 x_dim_id, u_id, v_id, w_id, th_id, p_id, zu_id, zv_id, zw_id, zth_id)
74 dtm_id, dtm_new_id, absolute_new_dtm_id)
78 if (current_state%parallel%my_rank==0)
call write_out_grid(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 85 ugal_id, vgal_id, number_q_fields_id, dtm_id, dtm_new_id, absolute_new_dtm_id)
94 integer,
intent(in) :: ncid
96 integer :: date_values(8)
98 call date_and_time(values=date_values)
110 integer,
intent(in) :: ncid, q_indices_id
112 integer :: i, current_index
118 if (specific_q_data%l_used)
then 121 current_index=current_index+1
132 integer,
intent(in) :: ncid, options_id
135 character(len=STRING_LENGTH),
pointer :: sized_raw_character
136 class(*),
pointer :: raw_data, raw_to_string
140 raw_to_string=>raw_data
142 select type (raw_data)
151 type is(
character(len=*))
165 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)
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
170 logical :: multi_process
172 multi_process = current_state%parallel%processes .gt. 1
185 if (current_state%th%active)
then 191 do i=1,current_state%number_q_fields
192 if (current_state%q(i)%active)
then 205 integer,
intent(in) :: ncid, variable_id
208 logical,
intent(in) :: multi_process
209 integer,
optional,
intent(in) :: fourth_dim_loc
211 integer :: start(4), count(4), i, map(4)
213 if (multi_process .or.
present(fourth_dim_loc))
then 218 map(i)=map(i-1)*local_grid%size(i-1)
220 start(i) = local_grid%start(i)
221 count(i) = local_grid%size(i)
223 if (
present(fourth_dim_loc))
then 224 start(4) = fourth_dim_loc
226 map(4)=map(3)*local_grid%size(3)
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))
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))))
248 integer,
intent(in) :: ncid
275 integer,
intent(in) :: ncid
280 if (
allocated(grid%configuration%vertical%olubar))
then 284 if (
allocated(grid%configuration%vertical%olzubar))
then 288 if (
allocated(grid%configuration%vertical%olvbar))
then 292 if (
allocated(grid%configuration%vertical%olzvbar))
then 296 if (
allocated(grid%configuration%vertical%olthbar))
then 300 if (
allocated(grid%configuration%vertical%olzthbar))
then 304 if (
allocated(grid%configuration%vertical%olqbar))
then 308 if (
allocated(grid%configuration%vertical%olzqbar))
then 320 integer,
intent(in) :: ncid
322 integer :: z_var_id, zn_var_id, thref_var_id
339 integer,
intent(in) :: ncid
340 integer,
intent(out) :: string_dim_id, key_value_dim_id, options_id
342 integer :: options_dim_id, command_dimensions(3)
348 command_dimensions = (/ string_dim_id, key_value_dim_id, options_dim_id /)
361 integer,
intent(in) :: ncid, string_dim_id, key_value_dim_id
362 integer,
intent(out) :: q_indices_id
364 integer :: q_indices_dim_id, command_dimensions(3), number_active_q
368 if (number_active_q == 0)
then 373 command_dimensions = (/ string_dim_id, key_value_dim_id, q_indices_dim_id /)
386 integer,
intent(in) :: ncid
387 integer,
intent(out) :: q_dim_id
400 integer,
intent(in) :: ncid
401 integer,
intent(out) :: z_dim_id, y_dim_id, x_dim_id
403 integer :: empty_dim_id
407 if (current_state%global_grid%active(
z_index))
then 411 z_dim_id = empty_dim_id
413 if (current_state%global_grid%active(
y_index))
then 416 y_dim_id = empty_dim_id
418 if (current_state%global_grid%active(
x_index))
then 421 x_dim_id = empty_dim_id
436 integer,
intent(in) :: ncid
438 integer :: var_id, z_dim_id
440 if (current_state%global_grid%active(
x_index))
then 448 if (current_state%global_grid%active(
y_index))
then 456 if (current_state%global_grid%active(
z_index))
then 470 integer,
intent(in) :: ncid
472 integer :: var_id, z_dim_id, q_dim_id, qdimids(2)
476 if (
allocated(current_state%global_grid%configuration%vertical%olubar))
then 479 if (
allocated(current_state%global_grid%configuration%vertical%olzubar))
then 482 if (
allocated(current_state%global_grid%configuration%vertical%olvbar))
then 485 if (
allocated(current_state%global_grid%configuration%vertical%olzvbar))
then 488 if (
allocated(current_state%global_grid%configuration%vertical%olthbar))
then 491 if (
allocated(current_state%global_grid%configuration%vertical%olzthbar))
then 494 if (
allocated(current_state%global_grid%configuration%vertical%olqbar) .or. &
495 allocated(current_state%global_grid%configuration%vertical%olzqbar))
then 497 qdimids=(/ z_dim_id, q_dim_id /)
498 if (
allocated(current_state%global_grid%configuration%vertical%olqbar))
then 501 if (
allocated(current_state%global_grid%configuration%vertical%olzqbar))
then 516 subroutine define_q_variable(ncid, multi_process, q_dim_id, z_dim_id, y_dim_id, x_dim_id, q_id, zq_id)
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
521 integer,
dimension(:),
allocatable :: dimids
524 dimids = (/ z_dim_id, y_dim_id, x_dim_id, q_dim_id /)
531 if (multi_process)
then 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))
552 y_dim_id, x_dim_id, u_id, v_id, w_id, th_id, p_id, zu_id, zv_id, zw_id, zth_id)
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
570 if (current_state%th%active)
then 574 if (current_state%p%active)
then 583 dtm_id, dtm_new_id, absolute_new_dtm_id)
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
602 vgal_id, number_q_fields_id, dtm_id, dtm_new_id, absolute_new_dtm_id)
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
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
632 integer,
dimension(:),
allocatable :: dimids
634 if (
present(dimtwo) .and.
present(dimthree))
then 636 dimids = (/ dimone, dimtwo, dimthree /)
637 else if (
present(dimtwo) .or.
present(dimthree))
then 639 dimids = (/ dimone, merge(dimtwo, dimthree,
present(dimtwo)) /)
642 dimids = (/ dimone /)
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))
character(len= *), parameter olubar
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 w...
character(len= *), parameter p_key
Pressure variable NetCDF key.
character(len= *), parameter zn_key
character(len= *), parameter olzthbar
character(len= *), parameter y_key
character(len= *), parameter u_key
U variable NetCDF key.
subroutine, public write_checkpoint_file(current_state, filename)
Will write out the current model state_mod into a NetCDF checkpoint file.
character(len= *), parameter key_value_pair_key
Key-value pair dimension key.
subroutine write_z_grid_gimension(ncid, vertical_grid)
Writes out the Z dimension of the grids_mod points which are explicitly calculated.
character(len= *), parameter thref
subroutine define_grid_variables(current_state, ncid)
Defines the NetCDF grid variables. This works for 1, 2 or 3D grids_mod.
integer, parameter nf90_int
integer, parameter nf90_double
character(len= *), parameter q_key
Q variable NetCDF key.
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.
character(len= *), parameter empty_dim_key
Empty dimension key.
integer, parameter nf90_real
character(len= *), parameter y_dim_key
Y dimension/variable key.
integer function, public get_max_number_q_indices()
Gets the maximum number of Q indicies.
subroutine write_out_q_indices(ncid, q_indices_id)
Writes out the specific Q indicies that are active and need writing.
Contains prognostic field definitions and functions.
character(len= *), parameter y_top
character(len= *), parameter zv_key
A prognostic field which is assumed to be 3D.
Common checkpoint functionality which is used by reader and writers to NetCDF checkpoints.
character(len= *), parameter created_attribute_key
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
character(len= *), parameter zth_key
integer, parameter, public z_index
Grid index parameters.
integer, parameter nf90_global
character(len= *), parameter x_key
subroutine write_out_options(current_state, ncid, options_id)
Writes out the options that the model was run with.
integer, parameter max_string_length
Maximum string length (stored size)
character(len= *), parameter timestep
Timestep NetCDF key.
character(len= *), parameter time_key
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.
character(len= *), parameter zu_key
character(len= *), parameter z_dim_key
Z dimension/variable key.
character(len= *), parameter options_dim_key
Options dimension key.
Contains common definitions for the data and datatypes used by MONC.
subroutine write_out_mean_fields(ncid, grid)
character(len= *), parameter olzvbar
character(len= *), parameter v_key
V variable NetCDF key.
The ModelState which represents the current state of a run.
character(len=string_length) function, public options_key_at(options_database, i)
Returns the ith key in the options database.
subroutine define_mean_fields(current_state, ncid)
Conversion between common inbuilt FORTRAN data types.
Converts data types to strings.
character(len= *), parameter olvbar
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...
integer, parameter, public single_precision
Single precision (32 bit) kind.
character(len= *), parameter absolute_new_dtm_key
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 mod...
character(len= *), parameter q_indices_key
The configuration of the grid vertically.
integer function nf90_enddef(ncid)
type(q_metadata_type) function, public get_indices_descriptor(i)
Retrieves the indicies descriptor at a specific location.
character(len= *), parameter z_key
integer, parameter, public double_precision
Double precision (64 bit) kind.
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 stri...
character(len= *), parameter x_bottom
subroutine define_velocity_variable(ncid, multi_process, dimone, dimtwo, dimthree, field_name, field_id)
Will define a single velocity variable in the NetCDF file.
integer, parameter nf90_clobber
This manages the Q variables and specifically the mapping between names and the index that they are s...
integer function nf90_put_att(ncid, attribute, key, value)
character(len= *), parameter string_dim_key
String dimension key.
integer function, public get_number_active_q_indices()
Gets the number of active Q indicies (i.e. those allocated to specific uses)
character(len= *), parameter w_key
W variable NetCDF key.
character(len= *), parameter title_attribute_key
character(len= *), parameter dtm_key
subroutine check_status(status, found_flag)
Will check a NetCDF status and write to log_log error any decoded statuses. Can be used to decode whe...
Defined the local grid, i.e. the grid held on this process after decomposition.
Writes out model state_mod to a checkpoint NetCDF file.
character(len= *), parameter q_dim_key
integer function nf90_create(path, mode, ncid, comm, info)
character(len= *), parameter olzubar
integer function nf90_close(ncid)
character(len= *), parameter y_bottom
character(len= *), parameter dtm_new_key
subroutine write_out_global_attributes(ncid)
Writes out global attributes into the checkpoint.
integer, parameter, public string_length
Default length of strings.
character(len= *), parameter olzqbar
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 st...
class(*) function, pointer, public options_value_at(options_database, i)
Returns the value at index in the database.
character(len= *), parameter zn_dim_key
integer function, public options_size(options_database)
Returns the number of entries in the options database.
character(len= *), parameter olthbar
Functionality to support the different types of grid and abstraction between global grids and local o...
integer function nf90_def_dim(ncid, key, length, dimension_id)
character(len= *), parameter x_resolution
integer, parameter nf90_netcdf4
Manages the options database. Contains administration functions and deduce runtime options from the c...
character(len= *), parameter q_indices_dim_key
character(len= *), parameter x_dim_key
X dimension/variable key.
integer, parameter nf90_mpiio
character(len= *), parameter th_key
Theta variable NetCDF key.
character(len= *), parameter olqbar
character(len= *), parameter zq_key
character(len= *), parameter vgal
character(len= *), parameter zw_key
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...
character(len= *), parameter ugal
integer, parameter nf90_char
character(len= *), parameter x_top
The model state which represents the current state of a run.
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.
integer, parameter, public y_index
character(len= *), parameter options_key
Options variable key.
character(len= *), parameter nqfields
subroutine define_q_field_dimension(current_state, ncid, q_dim_id)
Defines the Q field dimension in the NetCDF.
integer, parameter, public x_index
character(len= *), parameter y_resolution
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.
character(len= *), parameter checkpoint_title
Title of the NetCDF file.