Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalized subroutine to read the state variables from the namelist (get_state_variables) #783

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
17f26ab
Making a generic subroutine to read model_nml:model_state_variables i…
mjs2369 Nov 12, 2024
179d34f
Adding a unit test for the state var table read
mjs2369 Nov 13, 2024
f18942e
Fixing file name for dev test
mjs2369 Nov 13, 2024
c0bb758
Changing the name of the subroutine to get_state_variables
mjs2369 Dec 10, 2024
1914a42
Changing the name of the dev test to better fit the subroutine name and
mjs2369 Dec 10, 2024
c168bbe
Removing MOM6 version of subroutine and making necessary adjustments
mjs2369 Dec 10, 2024
e82df2e
including other needed input.nml file for test
mjs2369 Dec 10, 2024
f177c69
Removing MPI from dev test
mjs2369 Dec 12, 2024
ccf37db
Adding an interface to create 2 distinct subroutines for get_state_va…
mjs2369 Dec 12, 2024
7381c2b
Updating MOM6 model_mod to use new interface
mjs2369 Dec 12, 2024
914468f
Replacing CAM-FV version of the routine with generic in default_model…
mjs2369 Dec 12, 2024
15e984f
Replacing CAM-SE version of the routine with generic in default_model…
mjs2369 Dec 12, 2024
6ed2022
Removing forgotten print statements from ca-fv model_mod
mjs2369 Dec 12, 2024
7336795
Using separate namelist groups in a single input.nml as opposed to us…
mjs2369 Dec 12, 2024
14352e1
Replacing WRF_HYDRO version of the routine with generic in default_mo…
mjs2369 Dec 12, 2024
4d996bd
WRF_HYDRO: Removing varibles that are no longer used due to changes
mjs2369 Dec 16, 2024
b1f0878
MOM6: Removing varibles that are no longer used due to changes
mjs2369 Dec 16, 2024
80a63e1
Replacing POP version of the routine with generic in default_model_mod
mjs2369 Dec 16, 2024
d76f1cb
Replacing aether_lat-lon version of the routine with generic in defau…
mjs2369 Dec 16, 2024
979a9cf
Replacing NOAH version of the routine with generic in default_model_mod
mjs2369 Dec 16, 2024
3e629cf
Replacing MITgcm_ocean version of the routine with generic in default…
mjs2369 Dec 16, 2024
0d759f3
Replacing CICE version of the routine with generic in default_model_mod
mjs2369 Dec 16, 2024
4d790b5
Fixing print statement in default_model_mod
mjs2369 Dec 17, 2024
83ad490
- Make function instead of subroutine
mjs2369 Jan 9, 2025
4da5986
Updating dev test; remove prints and test all components of the state…
mjs2369 Jan 9, 2025
022e6ba
Use parse_variables in the 3d template model_mod
mjs2369 Jan 9, 2025
87e21ba
Merge branch 'main' into get_state_variables
mjs2369 Jan 9, 2025
23c8d84
Fix typo in state_structure_mod.f90
mjs2369 Jan 9, 2025
ceeb76d
standard: .eqv. for logicals
hkershaw-brown Jan 13, 2025
e5057da
fix: use QTY_NAME rather than hardcoded number
hkershaw-brown Jan 13, 2025
b0c2a00
chore: add test_parse_variables program to gitignore
hkershaw-brown Jan 13, 2025
a4b10d6
Fix state_var_type%netcdf_var_names character length in default_model…
mjs2369 Jan 13, 2025
79cd8ea
Add needed trim to default_model_mod.f90
mjs2369 Jan 13, 2025
b66ee82
Making final adjustments and fixes to the dev test
mjs2369 Jan 13, 2025
d6bebae
Reverting the MITgcm_ocean model_mod to the original (cannot use the new
mjs2369 Jan 13, 2025
e78fbda
Adding the logic to use the default state variables if model_state_va…
mjs2369 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions assimilation_code/modules/io/state_structure_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ module state_structure_mod

use sort_mod, only : index_sort

use default_model_mod, only : state_var_type

use netcdf

implicit none
Expand Down Expand Up @@ -281,6 +283,7 @@ module state_structure_mod
module procedure add_domain_blank
module procedure add_domain_from_file
module procedure add_domain_from_spec
module procedure add_domain_from_state_type
end interface

interface get_index_start
Expand Down Expand Up @@ -313,8 +316,6 @@ module state_structure_mod
!> into the state_strucutre.
!>
!> Returns a dom_id that can be used to harvest information of a particular domain
!>
!> Does this need to be a function or a subroutine?


function add_domain_from_file(info_file, num_vars, var_names, kind_list, clamp_vals, update_list) result(dom_id)
Expand Down Expand Up @@ -365,6 +366,58 @@ function add_domain_from_file(info_file, num_vars, var_names, kind_list, clamp_v
end function add_domain_from_file


!-------------------------------------------------------------------------------
!> Given an info_file, reads in a state_var_type including nvars, netcdf
!> variable names, qtys (kinds), clamp values (optional), and updates into the
!> state_structure
!>
!> Returns a dom_id that can be used to harvest information of a particular domain


function add_domain_from_state_type(info_file, vars) result(dom_id)

character(len=*), intent(in) :: info_file
type(state_var_type), intent(in) :: vars
integer :: dom_id

integer :: ivar

! add to domains
call assert_below_max_num_domains('add_domain_from_file')
mjs2369 marked this conversation as resolved.
Show resolved Hide resolved
state%num_domains = state%num_domains + 1
!>@todo dom_id should be a handle.
dom_id = state%num_domains

! save information about the information file
state%domain(dom_id)%info_file = info_file
state%domain(dom_id)%method = 'file'

! set number of variables in this domain
state%domain(dom_id)%num_variables = vars%nvars

! load up the variable names
allocate(state%domain(dom_id)%variable(vars%nvars))

do ivar = 1, vars%nvars
state%domain(dom_id)%variable(ivar)%varname = vars%netcdf_var_names(ivar)
enddo

! load up variable id's and sizes
call load_state_variable_info(state%domain(dom_id),dom_id)

! load up the domain unique dimension info
call load_unique_dim_info(dom_id)

! load up any cf-conventions if they exist
call load_common_cf_conventions(state%domain(dom_id))

call set_dart_kinds(dom_id, vars%nvars, vars%qtys)
if (allocated(vars%clamp_values)) call set_clamping(dom_id, vars%nvars, vars%clamp_values)
call set_update_list(dom_id, vars%nvars, vars%updates)

end function add_domain_from_state_type


!-------------------------------------------------------------------------------
!> Defines a skeleton structure for the state structure. Dimension can be
!> added to variables with add_dimension_to_variable.
Expand Down
81 changes: 81 additions & 0 deletions developer_tests/namelist/test_parse_variables.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
! DART software - Copyright UCAR. This open source software is provided
! by UCAR, "as is", without charge, subject to all terms of use at
! http://www.image.ucar.edu/DAReS/DART/DART_download

program test_parse_variables

use utilities_mod, only : find_namelist_in_file, check_namelist_read
use mpi_utilities_mod, only : initialize_mpi_utilities, finalize_mpi_utilities
use types_mod, only : vtablenamelength, MISSING_R8
use default_model_mod, only : parse_variables_clamp, parse_variables, &
state_var_type, &
MAX_STATE_VARIABLE_FIELDS_CLAMP, &
MAX_STATE_VARIABLE_FIELDS

use test ! fortran-testanything

implicit none

integer :: iunit, io
type(state_var_type) :: state_vars, state_vars_clamp

character(len=vtablenamelength) :: state_variables(MAX_STATE_VARIABLE_FIELDS) = ' '
character(len=vtablenamelength) :: state_variables_clamp(MAX_STATE_VARIABLE_FIELDS_CLAMP) = ' '

namelist /model_nml/ &
state_variables

namelist /model_nml_clamp/ &
state_variables_clamp

call initialize_mpi_utilities('test_parse_variables')

call plan(26)

! Using namelist entry WITHOUT clamping values

call find_namelist_in_file('input.nml', 'model_nml', iunit)
read(iunit, nml = model_nml, iostat = io)
call check_namelist_read(iunit, io, 'model_nml')

state_vars = parse_variables(state_variables)

call ok(state_vars%nvars == 3)
call ok(state_vars%netcdf_var_names(1) == 'SALT_CUR')
call ok(state_vars%netcdf_var_names(2) == 'TEMP_CUR')
call ok(state_vars%netcdf_var_names(3) == 'UVEL_CUR')
call ok(state_vars%qtys(1) == 263)
call ok(state_vars%qtys(2) == 254)
call ok(state_vars%qtys(3) == 356)
hkershaw-brown marked this conversation as resolved.
Show resolved Hide resolved
call ok(state_vars%updates(1) == .true.)
mjs2369 marked this conversation as resolved.
Show resolved Hide resolved
call ok(state_vars%updates(2) == .true.)
call ok(state_vars%updates(3) == .true.)

! Using namelist entry WITH clamping values

call find_namelist_in_file('input.nml', 'model_nml_clamp', iunit)
read(iunit, nml = model_nml_clamp, iostat = io)
call check_namelist_read(iunit, io, 'model_nml_clamp')

state_vars_clamp = parse_variables_clamp(state_variables_clamp)

call ok(state_vars_clamp%nvars == 3)
call ok(state_vars_clamp%netcdf_var_names(1) == 'SALT_CUR')
call ok(state_vars_clamp%netcdf_var_names(2) == 'TEMP_CUR')
call ok(state_vars_clamp%netcdf_var_names(3) == 'UVEL_CUR')
call ok(state_vars_clamp%qtys(1) == 263)
call ok(state_vars_clamp%qtys(2) == 254)
call ok(state_vars_clamp%qtys(3) == 356)
call ok(state_vars_clamp%clamp_values(1,1) == 0.0)
mjs2369 marked this conversation as resolved.
Show resolved Hide resolved
call ok(state_vars_clamp%clamp_values(1,2) == 0.0)
call ok(state_vars_clamp%clamp_values(2,1) == 0.0)
call ok(state_vars_clamp%clamp_values(2,2) == 0.0)
call ok(state_vars_clamp%clamp_values(3,1) == 0.0)
call ok(state_vars_clamp%clamp_values(3,2) == 0.0)
call ok(state_vars_clamp%updates(1) == .true.)
call ok(state_vars_clamp%updates(2) == .true.)
call ok(state_vars_clamp%updates(3) == .true.)

call finalize_mpi_utilities()

end program test_parse_variables
67 changes: 67 additions & 0 deletions developer_tests/namelist/work/input.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
&model_nml_clamp
state_variables_clamp = 'SALT_CUR ', 'QTY_SALINITY', '0.0', '0.0', 'UPDATE',
'TEMP_CUR ', 'QTY_POTENTIAL_TEMPERATURE', '0.0', '0.0', 'UPDATE',
'UVEL_CUR ', 'QTY_U_CURRENT_COMPONENT ', '0', '0.0', 'UPDATE',
/

&model_nml
state_variables = 'SALT_CUR ', 'QTY_SALINITY', 'UPDATE',
'TEMP_CUR ', 'QTY_POTENTIAL_TEMPERATURE', 'UPDATE',
'UVEL_CUR ', 'QTY_U_CURRENT_COMPONENT ', 'update'
mjs2369 marked this conversation as resolved.
Show resolved Hide resolved
/

&utilities_nml
module_details = .false.
write_nml = 'none'
/

&preprocess_nml
input_obs_kind_mod_file = '../../../assimilation_code/modules/observations/DEFAULT_obs_kind_mod.F90'
quantity_files = '../../../assimilation_code/modules/observations/land_quantities_mod.f90',
'../../../assimilation_code/modules/observations/default_quantities_mod.f90'
'../../../assimilation_code/modules/observations/atmosphere_quantities_mod.f90'
'../../../assimilation_code/modules/observations/ocean_quantities_mod.f90'
output_obs_kind_mod_file = '../../../assimilation_code/modules/observations/obs_kind_mod.f90'
input_obs_def_mod_file = '../../../observations/forward_operators/DEFAULT_obs_def_mod.F90'
output_obs_def_mod_file = '../../../observations/forward_operators/obs_def_mod.f90'
input_files = '../../../observations/forward_operators/obs_def_AIRS_mod.f90',
'../../../observations/forward_operators/obs_def_AOD_mod.f90',
'../../../observations/forward_operators/obs_def_AURA_mod.f90',
'../../../observations/forward_operators/obs_def_COSMOS_mod.f90',
'../../../observations/forward_operators/obs_def_CO_Nadir_mod.f90',
'../../../observations/forward_operators/obs_def_GWD_mod.f90',
'../../../observations/forward_operators/obs_def_QuikSCAT_mod.f90',
'../../../observations/forward_operators/obs_def_SABER_mod.f90',
'../../../observations/forward_operators/obs_def_altimeter_mod.f90',
'../../../observations/forward_operators/obs_def_cloud_mod.f90',
'../../../observations/forward_operators/obs_def_dew_point_mod.f90',
'../../../observations/forward_operators/obs_def_dwl_mod.f90',
'../../../observations/forward_operators/obs_def_eval_mod.f90',
'../../../observations/forward_operators/obs_def_gps_mod.f90',
'../../../observations/forward_operators/obs_def_gts_mod.f90',
'../../../observations/forward_operators/obs_def_land_mod.f90',
'../../../observations/forward_operators/obs_def_metar_mod.f90',
'../../../observations/forward_operators/obs_def_ocean_mod.f90',
'../../../observations/forward_operators/obs_def_pe2lyr_mod.f90',
'../../../observations/forward_operators/obs_def_radar_mod.f90',
'../../../observations/forward_operators/obs_def_reanalysis_bufr_mod.f90',
'../../../observations/forward_operators/obs_def_rel_humidity_mod.f90',
'../../../observations/forward_operators/obs_def_sqg_mod.f90',
'../../../observations/forward_operators/obs_def_tower_mod.f90',
'../../../observations/forward_operators/obs_def_tpw_mod.f90',
'../../../observations/forward_operators/obs_def_upper_atm_mod.f90',
'../../../observations/forward_operators/obs_def_vortex_mod.f90',
'../../../observations/forward_operators/obs_def_wind_speed_mod.f90'
/

&mpi_utilities_nml
/

&obs_kind_nml
/

&ensemble_manager_nml
/

&state_vector_io_nml
/
43 changes: 43 additions & 0 deletions developer_tests/namelist/work/quickbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# DART software - Copyright UCAR. This open source software is provided
# by UCAR, "as is", without charge, subject to all terms of use at
# http://www.image.ucar.edu/DAReS/DART/DART_download

main() {

export DART=$(git rev-parse --show-toplevel)
source "$DART"/build_templates/buildfunctions.sh

MODEL="none"
EXTRA="$DART"/models/template/threed_model_mod.f90
dev_test=1
TEST="namelist"
LOCATION="threed_sphere"

programs=(
test_parse_variables
)


# quickbuild arguments
arguments "$@"

# clean the directory
\rm -f -- *.o *.mod Makefile .cppdefs

# build any NetCDF files from .cdl files
cdl_to_netcdf

# build and run preprocess before making any other DART executables
buildpreprocess

# build
buildit

# clean up
\rm -f -- *.o *.mod

}

main "$@"
Loading
Loading