Skip to content

Commit a125327

Browse files
committed
Tweak verify_variables parameters NCAR#448
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.
1 parent 4f1c859 commit a125327

File tree

4 files changed

+63
-111
lines changed

4 files changed

+63
-111
lines changed

developer_tests/namelist/test_read_variable_namelist.f90

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ program test_read_variable_namelist
88

99
implicit none
1010

11-
integer, parameter :: nrows = 5 ! - Hard Coded
12-
integer, parameter :: ncols = 3 ! - Hard Coded
13-
14-
character(len=vtablenamelength) :: state_variables(nrows * ncols)
15-
11+
integer, parameter :: nrows = 3 ! - Hard Coded
12+
integer, parameter :: ncols = 5 ! - Hard Coded
13+
14+
character(len=vtablenamelength) :: state_variables(nrows, ncols)
15+
1616
integer :: iunit, io, ngood
17-
integer :: var_qtys(nrows)
18-
character(len=vtablenamelength) :: table(nrows, ncols)
19-
character(len=vtablenamelength) :: var_names(nrows)
20-
logical :: var_update(nrows)
21-
real(r8) :: var_ranges(nrows, 2)
17+
integer :: var_qtys(ncols)
18+
character(len=vtablenamelength) :: var_names(ncols)
19+
logical :: var_update(ncols)
20+
real(r8) :: var_ranges(ncols, 2)
2221

2322
namelist /model_nml/ &
2423
state_variables
@@ -31,13 +30,8 @@ program test_read_variable_namelist
3130

3231
print*, "Hello World!"
3332

34-
call verify_variables(state_variables, ngood, table, var_names, &
35-
var_qtys, var_update, var_ranges)!, .false.)
36-
37-
!print*, state_variables, ngood, table, var_names, &
38-
! var_qtys, var_update, var_ranges
39-
40-
print*, var_qtys
33+
call verify_variables(state_variables, ngood, var_names, &
34+
var_qtys, var_update, var_ranges)
4135

4236
call finalize_mpi_utilities()
4337

developer_tests/namelist/work/input.nml

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
&model_nml
2-
! 3 column working. Output good.
3-
!
4-
! state_variables = 'SALT_CUR ', 'QTY_SALINITY ', 'UPDATE',
5-
! 'TEMP_CUR ', 'QTY_POTENTIAL_TEMPERATURE', 'UPDATE',
6-
! 'UVEL_CUR ', 'QTY_U_CURRENT_COMPONENT ', 'UPDATE',
7-
! 'VVEL_CUR ', 'QTY_V_CURRENT_COMPONENT ', 'UPDATE',
8-
! 'PSURF_CUR', 'QTY_SEA_SURFACE_PRESSURE ', 'UPDATE'
9-
10-
! 2 column working. Output good.
2+
state_variables = 'SALT_CUR ', 'QTY_SALINITY ', 'UPDATE',
3+
'TEMP_CUR ', 'QTY_POTENTIAL_TEMPERATURE', 'UPDATE',
4+
'UVEL_CUR ', 'QTY_U_CURRENT_COMPONENT ', 'UPDATE',
5+
'VVEL_CUR ', 'QTY_V_CURRENT_COMPONENT ', 'UPDATE',
6+
'PSURF_CUR', 'QTY_SEA_SURFACE_PRESSURE ', 'UPDATE'
117
!
128
! state_variables = 'theta', 'QTY_POTENTIAL_TEMPERATURE',
139
! 'rho', 'QTY_DENSITY',
@@ -17,20 +13,9 @@
1713
! 'qv', 'QTY_VAPOR_MIXING_RATIO',
1814
! 'surface_pressure', 'QTY_SURFACE_PRESSURE'
1915
!
20-
21-
! 5 column working, with .false. default_vars flag? Output good, exept no default_vars, var_qtys breaks?
22-
!
23-
state_variables = 'SH2O', 'QTY_SOIL_LIQUID_WATER', '0.0', 'NA', 'NOUPDATE',
24-
'SUBSURFACE_FLUX', 'QTY_SUBSURFACE', '0.0', 'NA', 'NOUPDATE',
25-
'OVERLAND_FLUX', 'QTY_OVERLAND_FLOW', '0.0', 'NA', 'NOUPDATE'
26-
27-
28-
! Alternate 5 column not working as expected! Defult output good, everything else broken!
29-
!
30-
! state_variables = 'U', 'QTY_U_WIND_COMPONENT', 'TYPE_U', 'UPDATE', '999',
31-
! 'V', 'QTY_V_WIND_COMPONENT', 'TYPE_V', 'UPDATE', '999',
32-
! 'U10', 'QTY_U_WIND_COMPONENT', 'TYPE_U10', 'UPDATE', '999',
33-
! 'V10', 'QTY_V_WIND_COMPONENT', 'TYPE_V10', 'UPDATE', '999'
16+
! state_variables = 'SH2O', 'QTY_SOIL_LIQUID_WATER', '0.0', 'NA', 'NOUPDATE',
17+
! 'SUBSURFACE_FLUX', 'QTY_SUBSURFACE', '0.0', 'NA', 'NOUPDATE',
18+
! 'OVERLAND_FLUX', 'QTY_OVERLAND_FLOW', '0.0', 'NA', 'NOUPDATE'
3419
/
3520

3621
&utilities_nml
@@ -40,8 +25,9 @@
4025

4126
&preprocess_nml
4227
input_obs_kind_mod_file = '../../../assimilation_code/modules/observations/DEFAULT_obs_kind_mod.F90'
43-
quantity_files = '../../../assimilation_code/modules/observations/land_quantities_mod.f90',
44-
'../../../assimilation_code/modules/observations/default_quantities_mod.f90'
28+
quantity_files = '../../../assimilation_code/modules/observations/land_quantities_mod.f90',
29+
'../../../assimilation_code/modules/observations/default_quantities_mod.f90'
30+
'../../../assimilation_code/modules/observations/atmosphere_quantities_mod.f90'
4531
output_obs_kind_mod_file = '../../../assimilation_code/modules/observations/obs_kind_mod.f90'
4632
input_obs_def_mod_file = '../../../observations/forward_operators/DEFAULT_obs_def_mod.F90'
4733
output_obs_def_mod_file = '../../../observations/forward_operators/obs_def_mod.f90'
Binary file not shown.

developer_tests/namelist/work/verify_variables_mod.f90

Lines changed: 41 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ module verify_variables_mod
33
use types_mod, only : r8, MISSING_R8
44
use utilities_mod, only : error_handler, E_ERR, E_MSG, do_output, to_upper
55
use netcdf_utilities_mod, only : NF90_MAX_NAME
6-
use obs_kind_mod, only : QTY_TEMPERATURE, QTY_SALINITY, QTY_DRY_LAND, &
7-
QTY_U_CURRENT_COMPONENT,QTY_V_CURRENT_COMPONENT, &
8-
QTY_SEA_SURFACE_HEIGHT, QTY_SEA_SURFACE_PRESSURE, &
9-
QTY_POTENTIAL_TEMPERATURE, QTY_SEA_SURFACE_ANOMALY, &
10-
get_index_for_quantity, get_name_for_quantity
6+
use obs_kind_mod, only : QTY_SALINITY, QTY_POTENTIAL_TEMPERATURE, get_index_for_quantity
117

128
implicit none
139

@@ -26,122 +22,98 @@ module verify_variables_mod
2622
! Subroutine for verifying state variables.
2723
! - state_variables: list of state variables from namelist
2824
! - ngood: amount of state variable rows validated
29-
! - table: 2D string array of state variables
3025
! - var_names: array of NetCDF variable names
31-
! - var_qtys: array of DART QUANTITY
32-
! - var_update: array of UPDATE flags (optional)
26+
! - var_qtys (kind_list): array of DART QUANTITY
27+
! - var_update (update_var): array of UPDATE flags (optional,)
3328
! - var_ranges: 2D array of ranges (optional)
34-
! - default_vars: flag to check DART QUANTITY (optional, default = true)
3529
!-----------------------------------------------------------------------
36-
subroutine verify_variables(state_variables, ngood, table, var_names, &
37-
var_qtys, var_update, var_ranges, default_vars)
30+
subroutine verify_variables(state_variables, ngood, var_names, &
31+
var_qtys, var_update, var_ranges)
3832

39-
character(len=*), intent(inout) :: state_variables(:)
33+
character(len=*), intent(inout) :: state_variables(:,:)
4034
integer, intent(out) :: ngood
41-
character(len=*), intent(out) :: table(:,:)
4235
character(len=*), intent(out) :: var_names(:)
43-
integer, intent(out) :: var_qtys(:) ! - kind_list
44-
logical, optional, intent(out) :: var_update(:) ! - update_var, optional
45-
real(r8), optional, intent(out) :: var_ranges(:,:) ! - optional
46-
logical, optional, intent(in) :: default_vars ! - optional
47-
36+
integer, intent(out) :: var_qtys(:)
37+
logical, optional, intent(out) :: var_update(:)
38+
real(r8), optional, intent(out) :: var_ranges(:,:)
39+
4840
character(len=*), parameter :: routine = 'verify_variables'
4941

5042
integer :: io, i, nrows, ncols
5143
real(r8) :: minvalue, maxvalue
52-
logical :: check_obs
5344
character(len=NF90_MAX_NAME) :: varname, dartstr, minvalstring, maxvalstring, update
5445

55-
nrows = size(table,1)
56-
ncols = size(table) / size(table,1)
57-
check_obs = .true.
46+
nrows = size(state_variables,1)
47+
ncols = size(state_variables) / size(state_variables,1)
5848

5949
ngood = 0
6050

61-
MyLoop : do i = 1, nrows
51+
MyLoop : do i = 1, ncols
6252

63-
varname = trim(state_variables(ncols * i - (ncols - 1)))
64-
dartstr = trim(state_variables(ncols * i - (ncols - 2)))
53+
varname = trim(state_variables(1, i))
54+
dartstr = trim(state_variables(2, i))
6555

66-
if ( table(i,1) == ' ' .and. table(i,2) == ' ') exit MyLoop ! Found end of list.
56+
if ( state_variables(1, i) == ' ' .and. state_variables(2, i) == ' ') exit MyLoop ! Found end of list.
6757

68-
if ( table(i,1) == ' ' .or. table(i,2) == ' ') then
69-
string1 = 'model_nml:state_variables not fully specified'
70-
call error_handler(E_ERR,routine,string1,source,revision,revdate)
58+
if ( state_variables(1, i) == ' ' .or. state_variables(2, i) == ' ') then
59+
string1 = 'model_nml:state_variables not fully specified'
60+
call error_handler(E_ERR,routine,string1,source,revision,revdate)
7161
endif
7262

63+
! All good to here - fill the output variables
64+
ngood = ngood + 1
7365

74-
if (present(default_vars)) check_obs = default_vars
66+
var_names(ngood) = varname
7567

7668
! The internal DART routines check if the variable name is valid.
7769

78-
if (check_obs) then
79-
var_qtys(i) = get_index_for_quantity(dartstr)
80-
if( var_qtys(i) < 0 ) then
81-
write(string1,'(''there is no obs_kind <'',a,''> in obs_kind_mod.f90'')') trim(dartstr)
82-
write(string2,'(A)') 'Hint: set default_vars as false if using non default state_variables'
83-
call error_handler(E_ERR,routine,string1,source,revision,revdate, text2=string2)
84-
endif
70+
var_qtys(ngood) = get_index_for_quantity(dartstr)
71+
if( var_qtys(i) < 0 ) then
72+
write(string1,'(''there is no obs_kind <'',a,''> in obs_kind_mod.f90'')') trim(dartstr)
73+
call error_handler(E_ERR,routine,string1,source,revision,revdate)
8574
endif
8675

87-
! All good to here - fill the output variables
88-
ngood = ngood + 1
76+
! Records false in var_update if string is anything but "UPDATE"
8977

90-
var_names(ngood) = varname
78+
if ( present(var_update) .and. nrows <= 3 )then
79+
update = trim(state_variables(3, i))
80+
call to_upper(update)
9181

92-
table(i,1) = trim(varname)
93-
table(i,2) = trim(dartstr)
82+
var_update(ngood) = .false.
83+
if (update == 'UPDATE') var_update(ngood) = .true.
84+
endif
9485

95-
! Check to see if other columns variables are present from default
86+
! Records the min and max value range in var_ranges
9687

97-
if (ncols == 5) then
88+
if ( present(var_ranges) .and. nrows == 5 ) then
9889
var_ranges(ngood,:) = (/ MISSING_R8, MISSING_R8 /)
9990

100-
minvalstring = trim(state_variables(ncols * i - (ncols - 3)))
101-
maxvalstring = trim(state_variables(ncols * i - (ncols - 4)))
102-
update = trim(state_variables(ncols * i - (ncols - 5)))
91+
minvalstring = trim(state_variables(4, i))
92+
maxvalstring = trim(state_variables(5, i))
10393

10494
! Convert the [min,max] valstrings to numeric values if possible
10595

10696
read(minvalstring,*,iostat=io) minvalue
10797
if (io == 0) var_ranges(ngood,1) = minvalue
108-
table(i,3) = trim(minvalstring)
10998

11099
read(maxvalstring,*,iostat=io) maxvalue
111100
if (io == 0) var_ranges(ngood,2) = maxvalue
112-
table(i,4) = trim(maxvalstring)
113-
114-
call to_upper(update)
115-
table(i,5) = trim(update)
116-
117-
else if (ncols == 3) then
118-
update = trim(state_variables(ncols * i - (ncols - 3)))
119-
120-
call to_upper(update)
121-
table(i,3) = trim(update)
122101
end if
123102

124-
! Records false in var_update if string is anything but "UPDATE"
125-
126-
if ( present(var_update) )then
127-
var_update(ngood) = .false.
128-
if (update == 'UPDATE') var_update(ngood) = .true.
129-
endif
130-
131103
! Record the contents of the DART state vector
132104

133105
if (do_output()) then
134-
SELECT CASE (ncols)
106+
SELECT CASE (nrows)
135107
CASE (5)
136-
write(string1,'(A,I2,10A)') 'variable ',i,' is ',trim(varname), ', ', trim(dartstr), &
108+
write(string1,'(A,I2,10A)') 'variable',i,' is ',trim(varname), ', ', trim(dartstr), &
137109
', ', trim(minvalstring), ', ', trim(maxvalstring), ', ', trim(update)
138110
call error_handler(E_MSG,routine,string1,source,revision,revdate)
139111
CASE (3)
140-
write(string1,'(A,I2,6A)') 'variable ',i,' is ',trim(varname), ', ', trim(dartstr), &
112+
write(string1,'(A,I2,6A)') 'variable',i,' is ',trim(varname), ', ', trim(dartstr), &
141113
', ', trim(update)
142114
call error_handler(E_MSG,routine,string1,source,revision,revdate)
143115
CASE DEFAULT
144-
write(string1,'(A,I2,4A)') 'variable ',i,' is ',trim(varname), ', ', trim(dartstr)
116+
write(string1,'(A,I2,4A)') 'variable',i,' is ',trim(varname), ', ', trim(dartstr)
145117
call error_handler(E_MSG,routine,string1,source,revision,revdate)
146118
END SELECT
147119
endif

0 commit comments

Comments
 (0)