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
type(map_type), save variable_ids
program test_checkpointer_driver
Common checkpoint functionality which is used by reader and writers to NetCDF checkpoints.
character(len= *), parameter created_attribute_key
Converts a data type into the generic (class *) form.
Definition: conversions.F90:23
The ModelState which represents the current state of a run.
Definition: state.F90:39
subroutine test_define_velocity_variable()
Conversion between common inbuilt FORTRAN data types.
Definition: conversions.F90:5
Converts data types to strings.
Definition: conversions.F90:36
integer function nf90_get_var_integer(ncid, varid, target, indexes, start, count, map)
subroutine define_velocity_variable(ncid, multi_process, dimone, dimtwo, dimthree, field_name, field_id)
Will define a single velocity variable in the NetCDF file.
character(len= *), parameter title_attribute_key
subroutine test_does_field_exist()
Collection data structures.
Definition: collections.F90:7
Writes out model state_mod to a checkpoint NetCDF file.
logical function does_field_exist(ncid, variable_key)
Determines whether a variable (field) exists within the NetCDF checkpoint file The NetCDF file id T...
type(map_type), save global_attributes
subroutine write_out_global_attributes(ncid)
Writes out global attributes into the checkpoint.
Will read in a NetCDF checkpoint file and initialise the model state_mod based upon this...
subroutine dummy_netcdf_reset()
subroutine test_write_out_misc_variables()
type(map_type), save variable_data
Converts data types to integers.
Definition: conversions.F90:47
Determines whether or not a map contains a specific key.
The model state which represents the current state of a run.
Definition: state.F90:2
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.
subroutine test_write_out_global_attributes()