Skip to content

Commit 0e74a70

Browse files
committed
change check_missing to function; use is_missing_value in more places in scm_input
1 parent 403e097 commit 0e74a70

File tree

3 files changed

+45
-44
lines changed

3 files changed

+45
-44
lines changed

scm/src/scm_input.F90

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
module scm_input
66

7-
use data_qc, only: is_missing_value
7+
use missing_values, only: missing_value
8+
use data_qc, only: is_missing_value, check_missing
89
use scm_kinds, only: sp, dp, qp
910
use scm_type_defs, only: character_length
1011
use netcdf
@@ -217,7 +218,7 @@ end subroutine get_config_nml
217218
!! "processed_case_input" directory.
218219
subroutine get_case_init(scm_state, scm_input)
219220
use scm_type_defs, only : scm_state_type, scm_input_type
220-
use NetCDF_read, only: NetCDF_read_var, check, missing_value
221+
use NetCDF_read, only: NetCDF_read_var, check
221222
type(scm_state_type), intent(inout) :: scm_state
222223
type(scm_input_type), target, intent(inout) :: scm_input
223224

@@ -800,7 +801,7 @@ subroutine get_case_init(scm_state, scm_input)
800801
scm_input%input_snwdph = input_snwdph
801802
scm_input%input_snoalb = input_snoalb
802803
scm_input%input_sncovr = input_sncovr
803-
if (input_area > missing_value) then
804+
if (.not. is_missing_value(input_area)) then
804805
scm_input%input_area = input_area
805806
end if
806807
scm_input%input_tsfco = input_tsfco
@@ -949,7 +950,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
949950
!corresponds to the DEPHY-SCM specs, version 1
950951

951952
use scm_type_defs, only : scm_state_type, scm_input_type
952-
use NetCDF_read, only: NetCDF_read_var, NetCDF_read_att, NetCDF_conditionally_read_var, check, missing_value, missing_value_int
953+
use NetCDF_read, only: NetCDF_read_var, NetCDF_read_att, NetCDF_conditionally_read_var, check
953954
use scm_physical_constants, only: con_hvap, con_hfus, con_cp, con_rocp, con_rd
954955
use scm_utils, only: find_vertical_index_pressure, find_vertical_index_height
955956

@@ -1515,7 +1516,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
15151516
call NetCDF_read_var(ncid, "pa", .True., input_pres)
15161517
!zh could be defined in addition to lev, use if so
15171518
call NetCDF_read_var(ncid, "zh", .False., input_height)
1518-
if (input_height(1,1) == missing_value) then
1519+
if (is_missing_value(input_height(1,1))) then
15191520
do i=1, input_n_init_times
15201521
do k=1, input_n_lev
15211522
input_height(k,i) = input_lev(k)
@@ -1526,7 +1527,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
15261527
call NetCDF_read_var(ncid, "zh", .True., input_height)
15271528
!pa could be defined in addition to lev, use if so
15281529
call NetCDF_read_var(ncid, "pa", .False., input_pres)
1529-
if (input_pres(1,1) == missing_value) then
1530+
if (is_missing_value(input_pres(1,1))) then
15301531
do i=1, input_n_init_times
15311532
do k=1, input_n_lev
15321533
input_pres(k,i) = input_lev(k)
@@ -1653,15 +1654,15 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
16531654
call NetCDF_read_var(ncid, "ps_forc", .True., input_force_pres_surf)
16541655
!zh_forc and pa_forc should be present according to the DEPHY standard; if not, assume that zh_forc = input_height and pa_forc = input_pres
16551656
call NetCDF_read_var(ncid, "zh_forc", .False., input_force_height)
1656-
if (input_force_height(1,1) == missing_value) then
1657+
if (is_missing_value(input_force_height(1,1))) then
16571658
do i=1, input_n_forcing_times
16581659
do k=1, input_n_lev
16591660
input_force_height(k,i) = input_height(k,1)
16601661
end do
16611662
end do
16621663
end if
16631664
call NetCDF_read_var(ncid, "pa_forc", .False., input_force_pres)
1664-
if (input_force_pres(1,1) == missing_value) then
1665+
if (is_missing_value(input_force_pres(1,1))) then
16651666
do i=1, input_n_forcing_times
16661667
do k=1, input_n_lev
16671668
input_force_pres(k,i) = input_pres(k,1)
@@ -2164,7 +2165,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
21642165
end if
21652166

21662167
!kinematic surface fluxes are specified (but may need to be converted)
2167-
if (is_missing_value(maxval(input_force_wpthetap(:)))) then
2168+
if (check_missing(input_force_wpthetap(:))) then
21682169
write(*,*) 'The global attribute surfaceForcing in '//trim(adjustl(scm_state%case_name))//'.nc indicates that the variable wpthetap should be present, but it is missing. Stopping ...'
21692170
error stop "The global attribute surfaceForcing indicates that the variable wpthetap should be present, but it is missing."
21702171
else
@@ -2176,30 +2177,30 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
21762177
end if
21772178

21782179
!if mixing ratios are present, and not specific humidities, convert from mixing ratio to specific humidities
2179-
if ((is_missing_value(maxval(input_force_wpqvp(:))) .and. &
2180-
is_missing_value(maxval(input_force_wpqtp(:)))) &
2180+
if ((check_missing(input_force_wpqvp(:)) .and. &
2181+
check_missing(input_force_wpqtp(:))) &
21812182
.and. &
2182-
(.not. is_missing_value(maxval(input_force_wprvp(:))) .or. &
2183-
.not. is_missing_value(maxval(input_force_wprtp(:))))) then
2184-
if (.not. is_missing_value(maxval(input_force_wprvp(:)))) then
2183+
(.not. check_missing(input_force_wprvp(:)) .or. &
2184+
.not. check_missing(input_force_wprtp(:)))) then
2185+
if (.not. check_missing(input_force_wprvp(:))) then
21852186
do i=1, input_n_forcing_times
21862187
input_force_wpqvp(i) = input_force_wprvp(i)/&
21872188
(1.0 + input_force_wprvp(i))
21882189
end do
21892190
end if
2190-
if (.not. is_missing_value(maxval(input_force_wprtp(:)))) then
2191+
if (.not. check_missing(input_force_wprtp(:))) then
21912192
do i=1, input_n_forcing_times
21922193
input_force_wpqtp(i) = input_force_wprtp(i)/&
21932194
(1.0 + input_force_wprtp(i))
21942195
end do
21952196
end if
21962197
end if
21972198

2198-
if (is_missing_value(maxval(input_force_wpqvp(:))) .and. is_missing_value(maxval(input_force_wpqtp(:)))) then
2199+
if (check_missing(input_force_wpqvp(:)) .and. check_missing(input_force_wpqtp(:))) then
21992200
write(*,*) 'The global attribute surfaceForcing in '//trim(adjustl(scm_state%case_name))//'.nc indicates that the variable wpqvp, wpqtp, wprvp, or wprtp should be present, but all are missing. Stopping ...'
22002201
error stop "The global attribute surfaceForcing indicates that the variable wpqvp, wpqtp, wprvp, or wprtp should be present, but all are missing."
22012202
else
2202-
if (.not. is_missing_value(maxval(input_force_wpqvp(:)))) then !use wpqvp if available
2203+
if (.not. check_missing(input_force_wpqvp(:))) then !use wpqvp if available
22032204
scm_input%input_lh_flux_sfc_kin = input_force_wpqvp(:)
22042205
else
22052206
!surface total flux of water should just be vapor
@@ -2229,14 +2230,14 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
22292230
end if
22302231

22312232

2232-
if (is_missing_value(maxval(input_force_sfc_sens_flx(:)))) then
2233+
if (check_missing(input_force_sfc_sens_flx(:))) then
22332234
write(*,*) 'The global attribute surfaceForcing in '//trim(adjustl(scm_state%case_name))//'.nc indicates that the variable sfc_sens_flx should be present, but it is missing. Stopping ...'
22342235
error stop "The global attribute surfaceForcing in indicates that the variable sfc_sens_flx should be present, but it is missing."
22352236
else
22362237
scm_input%input_sh_flux_sfc = input_force_sfc_sens_flx(:)
22372238
end if
22382239

2239-
if (is_missing_value(maxval(input_force_sfc_lat_flx(:)))) then
2240+
if (check_missing(input_force_sfc_lat_flx(:))) then
22402241
write(*,*) 'The global attribute surfaceForcing in '//trim(adjustl(scm_state%case_name))//'.nc indicates that the variable sfc_lat_flx should be present, but it is missing. Stopping ...'
22412242
error stop "The global attribute surfaceForcing indicates that the variable sfc_lat_flx should be present, but it is missing."
22422243
else

scm/src/scm_type_defs.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ subroutine physics_set(physics, scm_input, scm_state)
10581058
!this should be utilized for variables that cannot be modified or "forced" by the SCM;
10591059
!most of this routine follows what is in FV3/io/FV3GFS_io.F90/sfc_prop_restart_read
10601060
use scm_physical_constants, only: con_tice
1061-
use data_qc, only: conditionally_set_var, check_missing
1061+
use data_qc, only: conditionally_set_var
10621062
use NetCDF_read, only: missing_value
10631063

10641064
class(physics_type) :: physics

scm/src/scm_utils.F90

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,53 +60,53 @@ function is_missing_value_dp(var) result(missing)
6060
end if
6161
end function is_missing_value_dp
6262

63-
subroutine check_missing_int_0d(var, missing)
63+
function check_missing_int_0d(var) result(missing)
6464
integer, intent(in) :: var
65-
logical, intent(out) :: missing
65+
logical :: missing
6666

6767
missing = .false.
6868
if (var == missing_value_int) missing = .true.
69-
end subroutine check_missing_int_0d
69+
end function check_missing_int_0d
7070

71-
subroutine check_missing_int_1d(var, missing)
71+
function check_missing_int_1d(var) result(missing)
7272
integer, dimension(:), intent(in) :: var
73-
logical, intent(out) :: missing
73+
logical :: missing
7474

7575
missing = .false.
7676
if ( ANY(var == missing_value_int)) missing = .true.
77-
end subroutine check_missing_int_1d
77+
end function check_missing_int_1d
7878

79-
subroutine check_missing_real_sp_0d(var, missing)
79+
function check_missing_real_sp_0d(var) result(missing)
8080
real(kind=sp), intent(in) :: var
81-
logical, intent(out) :: missing
81+
logical :: missing
8282

8383
missing = .false.
8484
if (var == missing_value_sp) missing = .true.
85-
end subroutine check_missing_real_sp_0d
85+
end function check_missing_real_sp_0d
8686

87-
subroutine check_missing_real_sp_1d(var, missing)
87+
function check_missing_real_sp_1d(var) result(missing)
8888
real(kind=sp), dimension(:), intent(in) :: var
89-
logical, intent(out) :: missing
89+
logical :: missing
9090

9191
missing = .false.
9292
if ( ANY(var == missing_value_sp)) missing = .true.
93-
end subroutine check_missing_real_sp_1d
93+
end function check_missing_real_sp_1d
9494

95-
subroutine check_missing_real_dp_0d(var, missing)
95+
function check_missing_real_dp_0d(var) result(missing)
9696
real(kind=kind_scm_dp), intent(in) :: var
97-
logical, intent(out) :: missing
97+
logical :: missing
9898

9999
missing = .false.
100100
if (var == missing_value_dp) missing = .true.
101-
end subroutine check_missing_real_dp_0d
101+
end function check_missing_real_dp_0d
102102

103-
subroutine check_missing_real_dp_1d(var, missing)
103+
function check_missing_real_dp_1d(var) result(missing)
104104
real(kind=kind_scm_dp), dimension(:), intent(in) :: var
105-
logical, intent(out) :: missing
105+
logical :: missing
106106

107107
missing = .false.
108108
if ( ANY(var == missing_value_dp)) missing = .true.
109-
end subroutine check_missing_real_dp_1d
109+
end function check_missing_real_dp_1d
110110

111111
subroutine conditionally_set_int_var_0d(input, set_var, input_name, req, missing)
112112
integer, intent(in) :: input
@@ -115,7 +115,7 @@ subroutine conditionally_set_int_var_0d(input, set_var, input_name, req, missing
115115
logical, intent(in) :: req
116116
logical, intent(out) :: missing
117117

118-
call check_missing(input, missing)
118+
missing = check_missing(input)
119119

120120
if (.not. missing) then
121121
set_var = input
@@ -135,7 +135,7 @@ subroutine conditionally_set_int_var_1d(input, set_var, input_name, req, missing
135135
logical, intent(in) :: req
136136
logical, intent(out) :: missing
137137

138-
call check_missing(input, missing)
138+
missing = check_missing(input)
139139

140140
if (.not. missing) then
141141
set_var = input
@@ -155,7 +155,7 @@ subroutine conditionally_set_real_sp_var_0d(input, set_var, input_name, req, mis
155155
logical, intent(in) :: req
156156
logical, intent(out) :: missing
157157

158-
call check_missing(input, missing)
158+
missing = check_missing(input)
159159

160160
if (.not. missing) then
161161
set_var = input
@@ -175,7 +175,7 @@ subroutine conditionally_set_real_sp_var_1d(input, set_var, input_name, req, mis
175175
logical, intent(in) :: req
176176
logical, intent(out) :: missing
177177

178-
call check_missing(input, missing)
178+
missing = check_missing(input)
179179

180180
if (.not. missing) then
181181
set_var = input
@@ -195,7 +195,7 @@ subroutine conditionally_set_real_dp_var_0d(input, set_var, input_name, req, mis
195195
logical, intent(in) :: req
196196
logical, intent(out) :: missing
197197

198-
call check_missing(input, missing)
198+
missing = check_missing(input)
199199

200200
if (.not. missing) then
201201
set_var = input
@@ -215,7 +215,7 @@ subroutine conditionally_set_real_dp_var_1d(input, set_var, input_name, req, mis
215215
logical, intent(in) :: req
216216
logical, intent(out) :: missing
217217

218-
call check_missing(input, missing)
218+
missing = check_missing(input)
219219

220220
if (.not. missing) then
221221
set_var = input

0 commit comments

Comments
 (0)