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

Feature request: routine to read a table of state variables from namelist #448

Open
hkershaw-brown opened this issue Jan 31, 2023 · 10 comments · May be fixed by #783
Open

Feature request: routine to read a table of state variables from namelist #448

hkershaw-brown opened this issue Jan 31, 2023 · 10 comments · May be fixed by #783
Assignees
Labels
pmp possible Marlee project psi possible student issue

Comments

@hkershaw-brown
Copy link
Member

hkershaw-brown commented Jan 31, 2023

Use case

reading a table of state variables from a namelist, there are several of these in various model_mods (not including Lanai only models):

parse_variable_table
verify_variables verify_variables
vertify_variables
verify_state_variables
verify_state_variables
verify_state_variables
verify_state_variables
fill_dart_kinds_table

Every time a new model is added to DART, we get a variation on one of these routines.

Is your feature request related to a problem?

Code repetition and all the associated problems that come with that.

vtablenamelength is in types_mod. This is one of several non-types in types_mod

!----------------------------------------------------------------------------
! constants that need to be shared - really has nothing to do with types ...
!----------------------------------------------------------------------------

Describe your preferred solution

Generalize the routine:
netcdf variable name, dart qty, update

Describe any alternatives you have considered

Define the state outside the model_mod

@hkershaw-brown hkershaw-brown added the pmp possible Marlee project label Mar 30, 2023
@hkershaw-brown hkershaw-brown added the psi possible student issue label Jun 13, 2023
Benjamin-Gunn added a commit to Benjamin-Gunn/DART that referenced this issue Aug 15, 2023
Hardcoded verify_variable_mod that works with state_variables in a list
Benjamin-Gunn added a commit to Benjamin-Gunn/DART that referenced this issue Sep 17, 2023
Changed verify_variables to not read state_variables as a list, then output a table. Instead, it reads state_variables as a table. Also simplified structure and removed logic for alternate 5 row input.
@hkershaw-brown
Copy link
Member Author

hkershaw-brown commented Sep 26, 2023

@hkershaw-brown
Copy link
Member Author

Ben J. has a pull request on this also

@mjs2369
Copy link
Contributor

mjs2369 commented Nov 12, 2024

Generic routine now available in default_model_mod.f90 on the state_vars_namelist branch -

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

Initial questions:

  • Is this the best location for this routine?
  • Some versions of this routine allow for more columns to present in the table than just netcdf variable name, dart qty, update. Do we want to remove these fields and only allow for the three listed above?

EX (tiegcm):

variable_table(i,VT_VARNAMEINDX) = trim(varname)
variable_table(i,VT_KINDINDX) = trim(dartstr)
variable_table(i,VT_MINVALINDX) = trim(minvalstring)
variable_table(i,VT_MAXVALINDX) = trim(maxvalstring)
variable_table(i,VT_ORIGININDX) = trim(filename)
variable_table(i,VT_STATEINDX) = trim(state_or_aux)

@hkershaw-brown
Copy link
Member Author

hkershaw-brown commented Nov 13, 2024

I believe the default_model_mod is the best location for this routine. Here is why:

  • It nudges people to use the off-the-shelf version, if the template model_mod.90 use this vertify_state_variables routine. People who need more, can write their own version (e.g. in the same way as way pert_model_copies in the default_model_mod can be used or you can write your own)

removing the extra fields:
I do want to remove these fields, however, we have taken the cautious (maybe cowardly) approach to leaving model_mod namelist options alone to miminize breaking whatever scripting/setup people have for dart

  • I think it is worth looking at these variations on a theme and why they have the extra columns, for example, TIEGCM (I think) is because it is reading from two files, so could you replace
verify_state_variables(big list which applies to 2 fies)

with

verify_state_variables(for file1)
verify_state_variables(for file2)

?

Also this routine is ripe for a unit test, can you throw a unit test in
https://github.com/NCAR/DART-tests/tree/main/unit (I'll give you write permission on main - with great power comes great responsibly, yada yada)

@mjs2369
Copy link
Contributor

mjs2369 commented Nov 13, 2024

Also this routine is ripe for a unit test, can you throw a unit test in https://github.com/NCAR/DART-tests/tree/main/unit (I'll give you write permission on main - with great power comes great responsibly, yada yada)

@hkershaw-brown Added a basic unit test to the DART-tests repo on the main branch and to the state_vars_namelist branch on the DART repo

@hkershaw-brown
Copy link
Member Author

ok next question, what do you think of the name 'verify_state_variables'?

@hkershaw-brown
Copy link
Member Author

and next next question, unit test,
how about using fotran-test anything and testing some namelist reads against some known values?

@mjs2369
Copy link
Contributor

mjs2369 commented Nov 13, 2024

ok next question, what do you think of the name 'verify_state_variables'?

This was actually something I was going to ask you. It's not horrible, but I feel the subroutine is more about reading the namelist item into a table than it is about the verifying. Maybe a name that says both? Like read_and_verify_state_vars

I think it could be good to mention the namelist in the subroutine name as well, but read_and_verify_state_vars_namelist is maybe too long?

@mjs2369
Copy link
Contributor

mjs2369 commented Nov 13, 2024

and next next question, unit test, how about using fotran-test anything and testing some namelist reads against some known values?

Yep this is on my to-do list

@mjs2369
Copy link
Contributor

mjs2369 commented Dec 10, 2024

@hkershaw-brown

On branch state_vars_namelist:

  • Generic subroutine renamed get_state_variables
  • Updating the generic routine by including the type state_vars_type and storing the contents of the nml entry here
  • Including a conditional use_clamping that tells whether or not the model's nml entry includes clamping values; executing a separate do loop over the rows if true to allow for reading in these values
  • Developer test updated as suggested
  • Removing MOM6 version of subroutine and making necessary adjustments (serves as an example for future model_mods that will use this routine and existing model_mods that can be converted to use this routine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pmp possible Marlee project psi possible student issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants