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 (parse_variables) #783

Merged
merged 49 commits into from
Feb 4, 2025
Merged
Changes from 1 commit
Commits
Show all changes
49 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
807cfe5
Updating the domain_type%method field to include state_type and fixin…
mjs2369 Jan 29, 2025
548190e
Reverting changes to noah model_mod back to main (original)
mjs2369 Jan 29, 2025
79ee8bf
Merge branch 'main' into get_state_variables
mjs2369 Jan 30, 2025
29ebab0
Merge branch 'main' into get_state_variables
hkershaw-brown Jan 31, 2025
3838d55
Merge branch 'main' into get_state_variables
hkershaw-brown Feb 3, 2025
a95013b
test_parse_variables is a serial program
hkershaw-brown Feb 3, 2025
57734f1
comment typo, namelist item is state_variables
hkershaw-brown Feb 3, 2025
e7bb723
chore: remove old svn info
hkershaw-brown Feb 3, 2025
d43f7ee
comment on relative size MAX_STATE_VARIABLE_FIELDS, MAX_STATE_VARIABL…
hkershaw-brown Feb 3, 2025
9e367a6
comment typo, the namelist item is called state_variables
hkershaw-brown Feb 3, 2025
120d83a
max number of state variables 1000
hkershaw-brown Feb 4, 2025
a7bf0bf
catch if number of state variables gets too big
hkershaw-brown Feb 4, 2025
9d0a17a
bump conf.py and CHANGELOG
mjs2369 Feb 4, 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
Prev Previous commit
Next Next commit
Replacing CICE version of the routine with generic in default_model_mod
mjs2369 committed Dec 17, 2024
commit 0d759f34790a607dff0ad27177e8a3f816b3cb5e
121 changes: 10 additions & 111 deletions models/cice/model_mod.f90
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
! 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
!
! $Id$

module model_mod

@@ -37,7 +35,7 @@ module model_mod
nc_write_location

use default_model_mod, only : init_time, init_conditions, adv_1step, &
nc_write_model_vars
nc_write_model_vars, get_state_variables, state_var_type

use utilities_mod, only : register_module, error_handler, &
E_ERR, E_MSG, nmlfileunit, get_unit, &
@@ -170,14 +168,7 @@ module model_mod
! DART state vector contents are specified in the input.nml:&model_nml namelist.
integer, parameter :: max_state_variables = 10
integer, parameter :: num_state_table_columns = 3
character(len=NF90_MAX_NAME) :: variable_table( max_state_variables, num_state_table_columns )
integer :: state_kinds_list( max_state_variables )
logical :: update_var_list( max_state_variables )

! identifiers for variable_table
integer, parameter :: VAR_NAME_INDEX = 1
integer, parameter :: VAR_QTY_INDEX = 2
integer, parameter :: VAR_UPDATE_INDEX = 3
type(state_var_type) :: state_vars

! things which can/should be in the model_nml
integer :: assimilation_period_days = 1
@@ -241,9 +232,6 @@ module model_mod
! is not being used.
!------------------------------------------------------------------

! Number of fields in the state vector
integer :: nfields

! Grid parameters - the values will be read from a
! standard cice namelist and filled in here.

@@ -411,9 +399,8 @@ subroutine static_init_model()
if (debug > 2) call write_grid_interptest() ! DEBUG only

! verify that the model_state_variables namelist was filled in correctly.
! returns variable_table which has variable names, kinds and update strings.
call verify_state_variables(model_state_variables, nfields, variable_table, &
state_kinds_list, update_var_list)
! returns state_vars which has netcdf variable names, kinds and update strings.
call get_state_variables(model_state_variables, MAX_STATE_VARIABLES, state_vars)

! in spite of the staggering, all grids are the same size
! and offset by half a grid cell. 4 are 3D and 2 are 2D.
@@ -431,10 +418,10 @@ subroutine static_init_model()
! Determine the shape of the variables from "cice.r.nc"
! The assimilate.csh, perfect_model.csh must ensure the cice restart file
! is linked to this filename.
domain_id = add_domain('cice.r.nc', nfields, &
var_names = variable_table(1:nfields, VAR_NAME_INDEX), &
kind_list = state_kinds_list(1:nfields), &
update_list = update_var_list(1:nfields))
domain_id = add_domain('cice.r.nc', state_vars%nvars, &
var_names = state_vars%netcdf_var_names, &
kind_list = state_vars%qtys, &
update_list = state_vars%updates)

if (debug > 2) call state_structure_info(domain_id)

@@ -1867,7 +1854,7 @@ function get_varid_from_kind(dart_kind)
integer :: i

do i = 1, get_num_variables(domain_id)
if (dart_kind == state_kinds_list(i)) then
if (dart_kind == state_vars%qtys(i)) then
get_varid_from_kind = i
return
endif
@@ -1897,7 +1884,7 @@ subroutine get_state_kind(var_ind, var_type)

if ( .not. module_initialized ) call static_init_model

var_type = state_kinds_list(var_ind)
var_type = state_vars%qtys(var_ind)

end subroutine get_state_kind

@@ -2587,94 +2574,6 @@ function read_model_time(filename)

end function read_model_time

!------------------------------------------------------------------
!> Verify that the namelist was filled in correctly, and check
!> that there are valid entries for the dart_kind.
!> Returns a table with columns:
!>
!> netcdf_variable_name ; dart_kind_string ; update_string
!>

subroutine verify_state_variables( state_variables, ngood, table, kind_list, update_var )

character(len=*), intent(inout) :: state_variables(:)
integer, intent(out) :: ngood
character(len=*), intent(out) :: table(:,:)
integer, intent(out) :: kind_list(:) ! kind number
logical, optional, intent(out) :: update_var(:) ! logical update

integer :: nrows, i
character(len=NF90_MAX_NAME) :: varname, dartstr, update

if ( .not. module_initialized ) call static_init_model

nrows = size(table,1)

ngood = 0

!>@todo deprecate. Remove a hidden 'default' set of variables.
!>@ The default is provided in the input namelist.

if ( state_variables(1) == ' ' ) then ! no model_state_variables namelist provided
call use_default_state_variables( state_variables )
string1 = 'model_nml:model_state_variables not specified using default variables'
call error_handler(E_MSG,'verify_state_variables',string1,source,revision,revdate)
endif

MyLoop : do i = 1, nrows

varname = trim(state_variables(3*i -2))
dartstr = trim(state_variables(3*i -1))
update = trim(state_variables(3*i ))

call to_upper(update)

table(i,1) = trim(varname)
table(i,2) = trim(dartstr)
table(i,3) = trim(update)

if ( table(i,1) == ' ' .and. table(i,2) == ' ' .and. table(i,3) == ' ') exit MyLoop

if ( table(i,1) == ' ' .or. table(i,2) == ' ' .or. table(i,3) == ' ' ) then
string1 = 'model_nml:model_state_variables not fully specified'
call error_handler(E_ERR,'verify_state_variables',string1,source,revision,revdate)
endif

! Make sure DART kind is valid

kind_list(i) = get_index_for_quantity(dartstr)
if( kind_list(i) < 0 ) then
write(string1,'(''there is no obs_kind <'',a,''> in obs_kind_mod.f90'')') trim(dartstr)
call error_handler(E_ERR,'verify_state_variables',string1,source,revision,revdate)
endif

! Make sure the update variable has a valid name

if ( present(update_var) )then
SELECT CASE (update)
CASE ('UPDATE')
update_var(i) = .true.
CASE ('NO_COPY_BACK')
update_var(i) = .false.
CASE DEFAULT
write(string1,'(A)') 'only UPDATE or NO_COPY_BACK supported in model_state_variable namelist'
write(string2,'(6A)') 'you provided : ', trim(varname), ', ', trim(dartstr), ', ', trim(update)
call error_handler(E_ERR,'verify_state_variables',string1,source,revision,revdate, text2=string2)
END SELECT
endif

! Record the contents of the DART state vector

if (do_output()) then
write(string1,'(A,I2,6A)') 'variable ',i,' is ',trim(varname), ', ', trim(dartstr), ', ', trim(update)
call error_handler(E_MSG,'verify_state_variables',string1,source,revision,revdate)
endif

ngood = ngood + 1
enddo MyLoop

end subroutine verify_state_variables

!------------------------------------------------------------------
!> Default state_variables from model_mod.
!>@todo DEPRECATE