diff --git a/science/gungho/source/driver/gungho_driver_mod.F90 b/science/gungho/source/driver/gungho_driver_mod.F90 index 2c1e5a37..25111e3b 100644 --- a/science/gungho/source/driver/gungho_driver_mod.F90 +++ b/science/gungho/source/driver/gungho_driver_mod.F90 @@ -26,7 +26,8 @@ module gungho_driver_mod use gungho_model_mod, only : initialise_infrastructure, & initialise_model, & finalise_infrastructure, & - finalise_model + finalise_model, & + checksum_model use gungho_step_mod, only : gungho_step use gungho_time_axes_mod, only : gungho_time_axes_type, & get_time_axes_from_collection @@ -490,9 +491,11 @@ subroutine finalise( program_name, modeldb ) call finalise_multifile_io( modeldb) end if + ! Output model checksum + call checksum_model( modeldb, program_name ) + ! Model configuration finalisation - call finalise_model( modeldb, & - program_name ) + call finalise_model( modeldb ) ! Destroy the fields stored in model_data call finalise_model_data( modeldb ) diff --git a/science/gungho/source/driver/gungho_model_mod.F90 b/science/gungho/source/driver/gungho_model_mod.F90 index e91f0fbd..7a07ea23 100644 --- a/science/gungho/source/driver/gungho_model_mod.F90 +++ b/science/gungho/source/driver/gungho_model_mod.F90 @@ -137,7 +137,8 @@ module gungho_model_mod public initialise_infrastructure, & initialise_model, & finalise_infrastructure, & - finalise_model + finalise_model, & + checksum_model contains !> @brief Initialise processor object for persisting LFRic fields @@ -1076,64 +1077,19 @@ end subroutine finalise_infrastructure !--------------------------------------------------------------------------- !> @brief Finalise the gungho application !> - !> @param[in,out] modeldb The working data set for the model run - !> @param[in] program_name An identifier given to the model run + !> @param[in,out] modeldb The working data set for the model run !> - subroutine finalise_model( modeldb, & - program_name ) + subroutine finalise_model( modeldb ) use io_config_mod, only: write_minmax_tseries implicit none - type( modeldb_type ), target, intent(inout) :: modeldb - character(*), optional, intent(in) :: program_name - - type( field_collection_type ), pointer :: diagnostic_fields => null() - type( field_collection_type ), pointer :: moisture_fields => null() - type( field_array_type ), pointer :: mr_array - type( field_type ), pointer :: mr(:) => null() - type( field_collection_type ), pointer :: fd_fields - type( field_collection_type ), pointer :: prognostic_fields => null() - - type( field_type), pointer :: theta => null() - type( field_type), pointer :: u => null() - type( field_type), pointer :: rho => null() - type( field_type), pointer :: exner => null() + type( modeldb_type ), intent(inout) :: modeldb class(timestep_method_type), pointer :: timestep_method - ! Pointer for setting I/O handlers on fields - procedure(write_interface), pointer :: tmp_write_ptr => null() - - if ( present(program_name) ) then - ! Get pointers to field collections for use downstream - prognostic_fields => modeldb%fields%get_field_collection( & - "prognostic_fields") - diagnostic_fields => modeldb%fields%get_field_collection( & - "diagnostic_fields") - moisture_fields => modeldb%fields%get_field_collection("moisture_fields") - call moisture_fields%get_field("mr", mr_array) - mr => mr_array%bundle - fd_fields => modeldb%fields%get_field_collection("fd_fields") - - ! Get pointers to fields in the prognostic/diagnostic field collections - ! for use downstream - call prognostic_fields%get_field('theta', theta) - call prognostic_fields%get_field('u', u) - call prognostic_fields%get_field('rho', rho) - call prognostic_fields%get_field('exner', exner) - - ! Write checksums to file - if (use_moisture) then - call checksum_alg(program_name, rho, 'rho', theta, 'theta', u, 'u', & - field_bundle=mr, bundle_name='mr') - else - call checksum_alg(program_name, rho, 'rho', theta, 'theta', u, 'u') - end if - - if (write_minmax_tseries) call minmax_tseries_final() - end if + if (write_minmax_tseries) call minmax_tseries_final() ! Finalise the timestep method if ( modeldb%values%key_value_exists('timestep_method') ) then @@ -1145,4 +1101,60 @@ subroutine finalise_model( modeldb, & end subroutine finalise_model + !--------------------------------------------------------------------------- + !> @brief Write checksum from modeldb + !> + !> @param[in,out] modeldb The working data set for the model run + !> @param[in] program_name An identifier given to the model run + !> + subroutine checksum_model( modeldb, & + program_name ) + + implicit none + + type( modeldb_type ), target, intent(inout) :: modeldb + character(*), intent(in) :: program_name + + type( field_collection_type ), pointer :: diagnostic_fields + type( field_collection_type ), pointer :: moisture_fields + type( field_array_type ), pointer :: mr_array + type( field_type ), pointer :: mr(:) + type( field_collection_type ), pointer :: fd_fields + type( field_collection_type ), pointer :: prognostic_fields + + type( field_type), pointer :: theta + type( field_type), pointer :: u + type( field_type), pointer :: rho + type( field_type), pointer :: exner + + nullify(diagnostic_fields, moisture_fields, mr_array, mr, fd_fields, & + prognostic_fields, theta, u, rho, exner) + + ! Get pointers to field collections for use downstream + prognostic_fields => modeldb%fields%get_field_collection( & + "prognostic_fields") + diagnostic_fields => modeldb%fields%get_field_collection( & + "diagnostic_fields") + moisture_fields => modeldb%fields%get_field_collection("moisture_fields") + call moisture_fields%get_field("mr", mr_array) + mr => mr_array%bundle + fd_fields => modeldb%fields%get_field_collection("fd_fields") + + ! Get pointers to fields in the prognostic/diagnostic field collections + ! for use downstream + call prognostic_fields%get_field('theta', theta) + call prognostic_fields%get_field('u', u) + call prognostic_fields%get_field('rho', rho) + call prognostic_fields%get_field('exner', exner) + + ! Write checksums to file + if (use_moisture) then + call checksum_alg(program_name, rho, 'rho', theta, 'theta', u, 'u', & + field_bundle=mr, bundle_name='mr') + else + call checksum_alg(program_name, rho, 'rho', theta, 'theta', u, 'u') + end if + + end subroutine checksum_model + end module gungho_model_mod diff --git a/science/linear/source/driver/linear_driver_mod.f90 b/science/linear/source/driver/linear_driver_mod.f90 index 662faea6..22dc6672 100644 --- a/science/linear/source/driver/linear_driver_mod.f90 +++ b/science/linear/source/driver/linear_driver_mod.f90 @@ -20,7 +20,8 @@ module linear_driver_mod use gungho_model_mod, only : initialise_infrastructure, & initialise_model, & finalise_infrastructure, & - finalise_model + finalise_model, & + checksum_model use gungho_init_fields_mod, only : create_model_data, & initialise_model_data, & output_model_data, & @@ -303,9 +304,11 @@ subroutine finalise( program_name, modeldb ) ! Write out the model state call output_model_data( modeldb ) + ! Output model checksum + call checksum_model( modeldb, program_name ) + ! Model configuration finalisation - call finalise_model( modeldb, & - program_name ) + call finalise_model( modeldb ) call finalise_linear_model( )