MONC
test_checkpointer.F90
Go to the documentation of this file.
1 ! Tests the checkpointing functionality. Uses a dummy NetCDF implementation for unit testing
9  use collections_mod, only : c_get, c_contains, c_put
11  use fruit, only : assert_equals, assert_true, assert_false
12  use state_mod, only : model_state_type
13  implicit none
14 
15 contains
16 
17  ! Tests the writing of global attributes
19  class(*), pointer :: raw_data
20 
21  call dummy_netcdf_reset()
23 
24  call assert_true(c_contains(global_attributes, title_attribute_key), "Checkpoint title exists")
25  raw_data=>c_get(global_attributes, title_attribute_key)
26  call assert_equals(checkpoint_title, trim(conv_to_string(raw_data, .true., 20)), "Checkpoint title correct")
27  call assert_true(c_contains(global_attributes, created_attribute_key), "Created attribute exists")
29 
30  ! Tests writing out misc variables
32  type(model_state_type) :: state_mod
33  integer, dimension(1) :: test_int
34  integer :: ret
35 
36  call dummy_netcdf_reset()
37  state_mod%timestep=100
38  call write_out_misc_variables(state_mod, 1, 1, 2, 3, 4, 5)
39 
40  ret = nf90_get_var_integer(1, 1, test_int)
41  call assert_equals(test_int(1), state_mod%timestep, "Timestep correct")
42  end subroutine test_write_out_misc_variables
43 
44  ! Tests defining of velocity variables of different dimensions
46  integer :: id
47  class(*), pointer :: raw_data, raw_id
48 
49  call dummy_netcdf_reset()
50  call define_velocity_variable(1, 10, field_name="A",field_id=id)
51  call assert_equals(1, id)
52  raw_data => c_get(variable_data, "A")
53  raw_id => c_get(variable_ids, "A")
54  select type(raw_data)
56  call assert_equals(id, conv_to_integer(raw_id, .false.))
57  call assert_equals(1, raw_data%size, "Size expected")
58  call assert_equals(10, raw_data%data(1), "Dimension correct")
59  end select
60  call define_velocity_variable(1, 11, 20, field_name="B",field_id=id)
61  call assert_equals(2, id)
62  raw_data => c_get(variable_data, "B")
63  raw_id => c_get(variable_ids, "B")
64  select type(raw_data)
66  call assert_equals(id, conv_to_integer(raw_id, .false.))
67  call assert_equals(2, raw_data%size, "Size expected")
68  call assert_equals(11, raw_data%data(1), "Dimension correct")
69  call assert_equals(20, raw_data%data(2), "Dimension correct")
70  end select
71  call define_velocity_variable(1, 11, 21, 30, field_name="C",field_id=id)
72  call assert_equals(3, id)
73  raw_data => c_get(variable_data, "C")
74  raw_id => c_get(variable_ids, "C")
75  select type(raw_data)
77  call assert_equals(id, conv_to_integer(raw_id, .false.))
78  call assert_equals(3, raw_data%size, "Size expected")
79  call assert_equals(11, raw_data%data(1), "Dimension correct")
80  call assert_equals(21, raw_data%data(2), "Dimension correct")
81  call assert_equals(30, raw_data%data(3), "Dimension correct")
82  end select
83  end subroutine test_define_velocity_variable
84 
85  ! Tests the field exists subroutine
86  subroutine test_does_field_exist()
87  logical :: exists
88  integer :: dummy=1
89 
90  class(*), pointer :: raw_data
91 
92  raw_data=>conv_to_generic(dummy, .true.)
93  call c_put(variable_ids, "BCD", raw_data)
94 
95  exists = does_field_exist(1, "ABC")
96  call assert_false(exists, "Field does not exist")
97  exists = does_field_exist(1, "BCD")
98  call assert_true(exists, "Field does exist")
99  end subroutine test_does_field_exist
100 
101 end module test_checkpointer_mod
102 
103 ! Driver for checkpoint tests
105  use fruit, only : init_fruit, run_test_case, fruit_summary
108 
109  implicit none
110 
111  call init_fruit
112  call run_test_case(test_write_out_global_attributes, "Test writing of global attributes")
113  call run_test_case(test_write_out_misc_variables, "Test writing of misc variables")
114  call run_test_case(test_define_velocity_variable, "Test writing of velocity variables")
115  call run_test_case(test_does_field_exist, "Test whether field exists or not")
116  call fruit_summary
117 end program test_checkpointer_driver
test_checkpointer_mod::test_define_velocity_variable
subroutine test_define_velocity_variable()
Definition: test_checkpointer.F90:46
conversions_mod
Conversion between common inbuilt FORTRAN data types.
Definition: conversions.F90:5
conversions_mod::conv_to_integer
Converts data types to integers.
Definition: conversions.F90:49
checkpointer_write_checkpoint_mod::write_out_misc_variables
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.
Definition: writecheckpoint.F90:607
dummy_netcdf_mod::global_attributes
type(map_type), save global_attributes
Definition: dummy_netcdf.F90:21
collections_mod
Collection data structures.
Definition: collections.F90:7
checkpointer_common_mod::created_attribute_key
character(len= *), parameter created_attribute_key
Definition: checkpointcommon.F90:11
conversions_mod::conv_to_generic
Converts a data type into the generic (class *) form.
Definition: conversions.F90:25
dummy_netcdf_mod::dummy_netcdf_reset
subroutine dummy_netcdf_reset()
Definition: dummy_netcdf.F90:51
dummy_netcdf_mod::variable_data
type(map_type), save variable_data
Definition: dummy_netcdf.F90:21
test_checkpointer_mod::test_write_out_global_attributes
subroutine test_write_out_global_attributes()
Definition: test_checkpointer.F90:19
dummy_netcdf_mod::integer_array_wrapper_type
Definition: dummy_netcdf.F90:15
collections_mod::c_contains
Determines whether or not a map contains a specific key.
Definition: collections.F90:447
checkpointer_write_checkpoint_mod::define_velocity_variable
subroutine define_velocity_variable(ncid, multi_process, dimone, dimtwo, dimthree, field_name, field_id)
Will define a single velocity variable in the NetCDF file.
Definition: writecheckpoint.F90:630
dummy_netcdf_mod
Definition: dummy_netcdf.F90:4
checkpointer_common_mod::title_attribute_key
character(len= *), parameter title_attribute_key
Definition: checkpointcommon.F90:11
conversions_mod::conv_to_string
Converts data types to strings.
Definition: conversions.F90:38
test_checkpointer_driver
program test_checkpointer_driver
Definition: test_checkpointer.F90:104
checkpointer_write_checkpoint_mod
Writes out model state_mod to a checkpoint NetCDF file.
Definition: writecheckpoint.F90:2
test_checkpointer_mod::test_does_field_exist
subroutine test_does_field_exist()
Definition: test_checkpointer.F90:87
dummy_netcdf_mod::variable_ids
type(map_type), save variable_ids
Definition: dummy_netcdf.F90:21
state_mod::model_state_type
The ModelState which represents the current state of a run.
Definition: state.F90:39
checkpointer_common_mod
Common checkpoint functionality which is used by reader and writers to NetCDF checkpoints.
Definition: checkpointcommon.F90:2
test_checkpointer_mod::test_write_out_misc_variables
subroutine test_write_out_misc_variables()
Definition: test_checkpointer.F90:32
checkpointer_read_checkpoint_mod::does_field_exist
logical function does_field_exist(ncid, variable_key)
Determines whether a variable (field) exists within the NetCDF checkpoint file @ncid The NetCDF file ...
Definition: readcheckpoint.F90:275
checkpointer_write_checkpoint_mod::checkpoint_title
character(len= *), parameter checkpoint_title
Title of the NetCDF file.
Definition: writecheckpoint.F90:31
checkpointer_write_checkpoint_mod::write_out_global_attributes
subroutine write_out_global_attributes(ncid)
Writes out global attributes into the checkpoint.
Definition: writecheckpoint.F90:98
checkpointer_read_checkpoint_mod
Will read in a NetCDF checkpoint file and initialise the model state_mod based upon this.
Definition: readcheckpoint.F90:2
dummy_netcdf_mod::nf90_get_var_integer
integer function nf90_get_var_integer(ncid, varid, target, indexes, start, count, map)
Definition: dummy_netcdf.F90:171
test_checkpointer_mod
Definition: test_checkpointer.F90:2
state_mod
The model state which represents the current state of a run.
Definition: state.F90:2