Skip to content

Commit

Permalink
Making a generic subroutine to read model_nml:model_state_variables i…
Browse files Browse the repository at this point in the history
…nto a table and verify its contents; putting it in the default_model_mod
  • Loading branch information
mjs2369 committed Nov 12, 2024
1 parent 2d5882c commit 0764fc2
Showing 1 changed file with 77 additions and 3 deletions.
80 changes: 77 additions & 3 deletions models/utilities/default_model_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ module default_model_mod

use utilities_mod, only : error_handler, E_ERR, E_MSG, nmlfileunit, &
do_output, find_namelist_in_file, check_namelist_read, &
do_nml_file, do_nml_term
do_nml_file, do_nml_term, to_upper

use netcdf_utilities_mod, only : nc_check
use netcdf_utilities_mod, only : nc_check, NF90_MAX_NAME

use ensemble_manager_mod, only : ensemble_type

use dart_time_io_mod, only : read_model_time, write_model_time

use obs_kind_mod, only : get_index_for_quantity

implicit none
private

Expand All @@ -49,7 +51,8 @@ module default_model_mod
convert_vertical_obs, &
convert_vertical_state, &
read_model_time, & ! from the dart_time_io module
write_model_time
write_model_time, &
verify_state_variables

character(len=*), parameter :: source = 'utilities/default_model_mod.f90'

Expand Down Expand Up @@ -283,6 +286,77 @@ subroutine pert_model_copies(state_ens_handle, ens_size, pert_amp, interf_provid

end subroutine pert_model_copies

!--------------------------------------------------------------------

!> Reads in model_nml:model_state_variables and puts it in a table.
!
!> Verifies 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_qty_string ; update_string

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

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

integer :: nrows, i
character(len=NF90_MAX_NAME) :: netcdf_var_name, dart_qty_str, update
character(len=256) :: string1, string2

nrows = size(table,1)
ngood = 0

RowsLoop : do i = 1, nrows ! each row contains netcdf variable name, dart qty, update

netcdf_var_name = trim(state_variables(3*i -2))
dart_qty_str = trim(state_variables(3*i -1))
update = trim(state_variables(3*i))

call to_upper(dart_qty_str)
call to_upper(update)

table(i,1) = trim(netcdf_var_name)
table(i,2) = trim(dart_qty_str)
table(i,3) = trim(update)

if ( table(i,1) == ' ' .and. table(i,2) == ' ' .and. table(i,3) == ' ') exit RowsLoop ! Found end of list.

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)
endif

! Make sure DART qty is valid

qty_list(i) = get_index_for_quantity(dart_qty_str)
if( qty_list(i) < 0 ) then
write(string1,*) 'The quantity specified in the &model_nml "', dart_qty_str, '", is not present in obs_kind_mod.f90'
call error_handler(E_ERR,'verify_state_variables',string1)
endif

! Make sure the update variable has a valid name

select case (update)
case ('UPDATE')
update_var(i) = .true.
case ('NO_COPY_BACK')
update_var(i) = .false.
case default
write(string1,'(A)') 'Invalid update variable in &model_nml:model_state_variable - only UPDATE or NO_COPY_BACK are supported'
write(string2,'(6A)') 'Issue: ', trim(netcdf_var_name), ', ', trim(dart_qty_str), ', ', trim(update)
call error_handler(E_ERR,'verify_state_variables',string1, text2=string2)
end select

ngood = ngood + 1
enddo RowsLoop

end subroutine verify_state_variables

!===================================================================
! End of model_mod
!===================================================================
Expand Down

0 comments on commit 0764fc2

Please sign in to comment.