Skip to content

Commit 77b5b08

Browse files
committed
Using modern Fortran practices by using error_unit when writing output that is a warning or error. The python scripts capture this as stderr output
1 parent 1bcc7c8 commit 77b5b08

File tree

8 files changed

+85
-74
lines changed

8 files changed

+85
-74
lines changed

scm/src/scm.F90

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module scm_main
66

77
subroutine scm_main_sub()
88

9+
use iso_fortran_env, only: error_unit
910
use scm_kinds, only: sp, dp, qp
1011
use scm_input
1112
use scm_utils
@@ -44,7 +45,7 @@ subroutine scm_main_sub()
4445

4546
call MPI_INIT(ierr)
4647
if (ierr/=0) then
47-
write(*,*) 'An error occurred in MPI_INIT: ', ierr
48+
write(error_unit,*) 'An error occurred in MPI_INIT: ', ierr
4849
error stop
4950
end if
5051
fcst_mpi_comm = MPI_COMM_WORLD
@@ -59,7 +60,7 @@ subroutine scm_main_sub()
5960
case(1)
6061
call get_case_init_DEPHY(scm_state, scm_input_instance)
6162
case default
62-
write(*,*) 'An unrecognized specification of the input_type namelist variable is being used. Exiting...'
63+
write(error_unit,*) 'An unrecognized specification of the input_type namelist variable is being used. Exiting...'
6364
error stop
6465
end select
6566

@@ -153,10 +154,10 @@ subroutine scm_main_sub()
153154

154155
!check for problematic diagnostic and radiation periods
155156
if (mod(physics%Model%nszero,scm_state%n_itt_out) /= 0) then
156-
write(*,*) "***ERROR***: The diagnostic output period must be a multiple of the output period."
157-
write(*,*) "From ", adjustl(trim(scm_state%physics_nml)), ", fhzero = ",physics%Model%fhzero
158-
write(*,*) "implying a diagnostic output period of ", physics%Model%nszero*scm_state%dt, "seconds."
159-
write(*,*) "The given output period in the case configuration namelist is ", scm_state%output_period,"seconds."
157+
write(error_unit,*) "***ERROR***: The diagnostic output period must be a multiple of the output period."
158+
write(error_unit,*) "From ", adjustl(trim(scm_state%physics_nml)), ", fhzero = ",physics%Model%fhzero
159+
write(error_unit,*) "implying a diagnostic output period of ", physics%Model%nszero*scm_state%dt, "seconds."
160+
write(error_unit,*) "The given output period in the case configuration namelist is ", scm_state%output_period,"seconds."
160161
error stop
161162
end if
162163

@@ -195,11 +196,11 @@ subroutine scm_main_sub()
195196

196197
!initialize the column's physics
197198

198-
write(0,'(a,i0,a)') "Calling ccpp_physics_init with suite '" // trim(trim(adjustl(scm_state%physics_suite_name))) // "'"
199+
write(*,'(a,i0,a)') "Calling ccpp_physics_init with suite '" // trim(trim(adjustl(scm_state%physics_suite_name))) // "'"
199200
call ccpp_physics_init(cdata, suite_name=trim(trim(adjustl(scm_state%physics_suite_name))), ierr=ierr)
200-
write(0,'(a,i0,a,i0)') "Called ccpp_physics_init with suite '" // trim(trim(adjustl(scm_state%physics_suite_name))) // "', ierr=", ierr
201+
write(*,'(a,i0,a,i0)') "Called ccpp_physics_init with suite '" // trim(trim(adjustl(scm_state%physics_suite_name))) // "', ierr=", ierr
201202
if (ierr/=0) then
202-
write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_init: ' // trim(cdata%errmsg) // '. Exiting...'
203+
write(error_unit,'(a,i0,a)') 'An error occurred in ccpp_physics_init: ' // trim(cdata%errmsg) // '. Exiting...'
203204
error stop
204205
end if
205206

@@ -289,7 +290,7 @@ subroutine scm_main_sub()
289290

290291
call ccpp_physics_timestep_init(cdata, suite_name=trim(adjustl(scm_state%physics_suite_name)), ierr=ierr)
291292
if (ierr/=0) then
292-
write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_timestep_init: ' // trim(cdata%errmsg) // '. Exiting...'
293+
write(error_unit,'(a,i0,a)') 'An error occurred in ccpp_physics_timestep_init: ' // trim(cdata%errmsg) // '. Exiting...'
293294
error stop
294295
end if
295296

@@ -309,33 +310,33 @@ subroutine scm_main_sub()
309310
if (mod(physics%Model%kdt,physics%Model%nszero) == 1 .or. physics%Model%nszero == 1) then
310311
call physics%Diag%phys_zero (physics%Model)
311312
endif
312-
313+
313314
!CCPP run phase
314315
! time_vary group doesn't have any run phase (omitted)
315316
! radiation group
316317
call physics%Interstitial(1)%rad_reset(physics%Model)
317318
call ccpp_physics_run(cdata, suite_name=trim(adjustl(scm_state%physics_suite_name)), group_name="radiation", ierr=ierr)
318319
if (ierr/=0) then
319-
write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_run for group radiation: ' // trim(cdata%errmsg) // '. Exiting...'
320+
write(error_unit,'(a,i0,a)') 'An error occurred in ccpp_physics_run for group radiation: ' // trim(cdata%errmsg) // '. Exiting...'
320321
error stop
321322
end if
322323
! process-split physics
323324
call physics%Interstitial(1)%phys_reset(physics%Model)
324325
call ccpp_physics_run(cdata, suite_name=trim(adjustl(scm_state%physics_suite_name)), group_name="phys_ps", ierr=ierr)
325326
if (ierr/=0) then
326-
write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_run for group phys_ps: ' // trim(cdata%errmsg) // '. Exiting...'
327+
write(error_unit,'(a,i0,a)') 'An error occurred in ccpp_physics_run for group phys_ps: ' // trim(cdata%errmsg) // '. Exiting...'
327328
error stop
328329
end if
329330
! time-split physics
330331
call ccpp_physics_run(cdata, suite_name=trim(adjustl(scm_state%physics_suite_name)), group_name="phys_ts", ierr=ierr)
331332
if (ierr/=0) then
332-
write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_run for group phys_ts: ' // trim(cdata%errmsg) // '. Exiting...'
333+
write(error_unit,'(a,i0,a)') 'An error occurred in ccpp_physics_run for group phys_ts: ' // trim(cdata%errmsg) // '. Exiting...'
333334
error stop
334335
end if
335336

336337
call ccpp_physics_timestep_finalize(cdata, suite_name=trim(adjustl(scm_state%physics_suite_name)), ierr=ierr)
337338
if (ierr/=0) then
338-
write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_timestep_finalize: ' // trim(cdata%errmsg) // '. Exiting...'
339+
write(error_unit,'(a,i0,a)') 'An error occurred in ccpp_physics_timestep_finalize: ' // trim(cdata%errmsg) // '. Exiting...'
339340
error stop
340341
end if
341342

@@ -447,13 +448,13 @@ subroutine scm_main_sub()
447448
call ccpp_physics_finalize(cdata, suite_name=trim(trim(adjustl(scm_state%physics_suite_name))), ierr=ierr)
448449

449450
if (ierr/=0) then
450-
write(*,'(a,i0,a)') 'An error occurred in ccpp_physics_finalize: ' // trim(cdata%errmsg) // '. Exiting...'
451+
write(error_unit,'(a,i0,a)') 'An error occurred in ccpp_physics_finalize: ' // trim(cdata%errmsg) // '. Exiting...'
451452
error stop
452453
end if
453454

454455
call MPI_FINALIZE(ierr)
455456
if (ierr/=0) then
456-
write(*,*) 'An error occurred in MPI_FINALIZE: ', ierr
457+
write(error_unit,*) 'An error occurred in MPI_FINALIZE: ', ierr
457458
error stop
458459
end if
459460

scm/src/scm_forcing.F90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
module scm_forcing
55

6+
use iso_fortran_env, only: error_unit
67
use scm_kinds, only: sp, dp, qp
78
use scm_utils, only: interpolate_to_grid_centers, find_vertical_index_pressure
89

@@ -795,7 +796,7 @@ subroutine apply_forcing_leapfrog(scm_state)
795796

796797
select case(scm_state%mom_forcing_type)
797798
case (1)
798-
write(*,*) 'momentum forcing type = 1 is not implemented. Pick 2 or 3. Stopping...'
799+
write(error_unit,*) 'momentum forcing type = 1 is not implemented. Pick 2 or 3. Stopping...'
799800
error stop
800801
case (2)
801802
!> - Calculate change in state momentum variables due to vertical advection (subsidence).
@@ -994,7 +995,7 @@ subroutine apply_forcing_forward_Euler(scm_state, in_spinup)
994995
else
995996
select case(scm_state%mom_forcing_type)
996997
case (1)
997-
write(*,*) 'momentum forcing type = 1 is not implemented. Pick 2 or 3. Stopping...'
998+
write(error_unit,*) 'momentum forcing type = 1 is not implemented. Pick 2 or 3. Stopping...'
998999
error stop
9991000
case (2)
10001001
!> - Calculate change in state momentum variables due to vertical advection (subsidence).

scm/src/scm_input.F90

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module scm_input
66

7+
use iso_fortran_env, only: error_unit
78
use scm_kinds, only : sp, dp, qp
89
use netcdf
910
use scm_type_defs, only: character_length
@@ -128,15 +129,15 @@ subroutine get_config_nml(scm_state)
128129

129130
open(unit=10, file=experiment_namelist, status='old', action='read', iostat=ioerror)
130131
if(ioerror /= 0) then
131-
write(*,'(a,i0)') 'There was an error opening the file ' // experiment_namelist // &
132+
write(error_unit,'(a,i0)') 'There was an error opening the file ' // experiment_namelist // &
132133
'; error code = ', ioerror
133134
error stop "error opening namelist"
134135
else
135136
read(10, NML=case_config, iostat=ioerror)
136137
end if
137138

138139
if(ioerror /= 0) then
139-
write(*,'(a,i0)') 'There was an error reading the namelist case_config in the file '&
140+
write(error_unit,'(a,i0)') 'There was an error reading the namelist case_config in the file '&
140141
// experiment_namelist // '; error code = ',ioerror
141142
error stop "error opening namelist"
142143
end if
@@ -502,7 +503,7 @@ subroutine get_case_init(scm_state, scm_input)
502503
call NetCDF_read_var(grp_ncid, "thetail", .False., input_thetail)
503504
call NetCDF_read_var(grp_ncid, "temp", .False., input_temp)
504505
if (maxval(input_thetail) < 0 .and. maxval(input_temp) < 0) then
505-
write(*,*) "One of thetail or temp variables must be present in ",trim(adjustl(scm_state%case_name))//'.nc',". Stopping..."
506+
write(error_unit,*) "One of thetail or temp variables must be present in ",trim(adjustl(scm_state%case_name))//'.nc',". Stopping..."
506507
error stop "One of thetail or temp variables"
507508
end if
508509
call NetCDF_read_var(grp_ncid, "qt", .True., input_qt )
@@ -1215,8 +1216,8 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
12151216
else if (adjustl(trim(tmpUnits)) == 'm') then
12161217
lev_in_altitude = .true.
12171218
else
1218-
write(0,'(a,i0,a)') "The variable 'lev' in the case data file had units different than 'm', 'pa', or 'Pa', but it is expected to be altitude in m or pressure in Pa. Stopping..."
1219-
STOP
1219+
write(error_unit,'(a,i0,a)') "The variable 'lev' in the case data file had units different than 'm', 'pa', or 'Pa', but it is expected to be altitude in m or pressure in Pa. Stopping..."
1220+
error stop
12201221
end if
12211222

12221223
!### TO BE USED IF DEPHY-SCM can be extended to include model ICs ###
@@ -2035,7 +2036,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
20352036
end if !ql test
20362037
else
20372038
!no qv or qt
2038-
write(*,*) 'When reading '//trim(adjustl(scm_state%case_name))//'.nc, all of the supported moisture variables (qv, qt, rv, rt) were missing. Stopping...'
2039+
write(error_unit,*) 'When reading '//trim(adjustl(scm_state%case_name))//'.nc, all of the supported moisture variables (qv, qt, rv, rt) were missing. Stopping...'
20392040
error stop "Aall of the supported moisture variables (qv, qt, rv, rt) were missing"
20402041
end if
20412042

@@ -2065,7 +2066,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
20652066
!since thetail is present, choose to use it, and set the alternative temperature to missing, even if it is also present in the file
20662067
scm_input%input_temp = missing_value
20672068
else
2068-
write(*,*) 'When reading '//trim(adjustl(scm_state%case_name))//'.nc, all of the supported temperature variables (temp, theta, thetal) were missing. Stopping...'
2069+
write(error_unit,*) 'When reading '//trim(adjustl(scm_state%case_name))//'.nc, all of the supported temperature variables (temp, theta, thetal) were missing. Stopping...'
20692070
error stop "All of the supported temperature variables (temp, theta, thetal) were missing"
20702071
end if
20712072

@@ -2134,7 +2135,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
21342135

21352136
if (input_surfaceForcingTemp == 'ts') then
21362137
if (maxval(input_force_ts) < 0) then
2137-
write(*,*) 'The global attribute surfaceForcing in '//trim(adjustl(scm_state%case_name))//'.nc indicates that the variable ts should be present, but it is missing. Stopping ...'
2138+
write(error_unit,*) 'The global attribute surfaceForcing in '//trim(adjustl(scm_state%case_name))//'.nc indicates that the variable ts should be present, but it is missing. Stopping ...'
21382139
error stop "The global attribute surfaceForcing indicates that the variable ts should be present, but it is missing"
21392140
else
21402141
!overwrite sfc_flux_spec
@@ -2166,7 +2167,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
21662167

21672168
!kinematic surface fluxes are specified (but may need to be converted)
21682169
if (maxval(input_force_wpthetap(:)) < missing_value_eps) then
2169-
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 ...'
2170+
write(error_unit,*) '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 ...'
21702171
error stop "The global attribute surfaceForcing indicates that the variable wpthetap should be present, but it is missing."
21712172
else
21722173
!convert from theta to T
@@ -2196,7 +2197,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
21962197
end if
21972198

21982199
if (maxval(input_force_wpqvp(:)) < missing_value_eps .and. maxval(input_force_wpqtp(:)) < missing_value_eps) then
2199-
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 ...'
2200+
write(error_unit,*) '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
22022203
if (maxval(input_force_wpqvp(:)) > missing_value_eps) then !use wpqvp if available
@@ -2230,14 +2231,14 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
22302231

22312232

22322233
if (maxval(input_force_sfc_sens_flx(:)) < missing_value_eps) then
2233-
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 ...'
2234+
write(error_unit,*) '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

22392240
if (maxval(input_force_sfc_lat_flx(:)) < missing_value_eps) then
2240-
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 ...'
2241+
write(error_unit,*) '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
22432244
scm_input%input_lh_flux_sfc = input_force_sfc_lat_flx(:)
@@ -2352,7 +2353,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
23522353
else if (input_surfaceForcingWind == 'ustar') then
23532354
!not supported
23542355
scm_state%surface_momentum_control = 1
2355-
write(*,*) 'The global attribute surfaceForcingWind in '//trim(adjustl(scm_state%case_name))//'.nc indicates that surface wind is controlled by a specified time-series of ustar. This is currently not supported. Stopping ...'
2356+
write(error_unit,*) 'The global attribute surfaceForcingWind in '//trim(adjustl(scm_state%case_name))//'.nc indicates that surface wind is controlled by a specified time-series of ustar. This is currently not supported. Stopping ...'
23562357
error stop "The global attribute surfaceForcingWind indicates that surface wind is controlled by a specified time-series of ustar. This is currently not supported."
23572358
end if
23582359

@@ -2454,7 +2455,7 @@ subroutine get_case_init_DEPHY(scm_state, scm_input)
24542455
if (char_rad_temp == 'adv' .or. char_rad_theta == 'adv' .or. char_rad_thetal == 'adv') then
24552456
scm_state%force_rad_T = 4
24562457
if (scm_state%force_adv_T == 0) then
2457-
write(*,*) 'The global attribute rad_temp, rad_theta, or rad_thetal in '//trim(adjustl(scm_state%case_name))//'.nc indicates that radiative forcing is included in the advection term, but there is no advection term. Stopping ...'
2458+
write(error_unit,*) 'The global attribute rad_temp, rad_theta, or rad_thetal in '//trim(adjustl(scm_state%case_name))//'.nc indicates that radiative forcing is included in the advection term, but there is no advection term. Stopping ...'
24582459
error stop "The global attribute rad_temp, rad_theta, or rad_thetal indicates that radiative forcing is included in the advection term, but there is no advection term."
24592460
end if
24602461
else if (rad_temp > 0) then
@@ -2750,7 +2751,7 @@ subroutine get_reference_profile(scm_state, scm_reference)
27502751
case (1)
27512752
open(unit=1, file='McCProfiles.dat', status='old', action='read', iostat=ioerror)
27522753
if(ioerror /= 0) then
2753-
write(*,*) 'There was an error opening the file McCprofiles.dat in the processed_case_input directory. &
2754+
write(error_unit,*) 'There was an error opening the file McCprofiles.dat in the processed_case_input directory. &
27542755
&Error code = ',ioerror
27552756
error stop "There was an error opening the file McCprofiles.dat in the processed_case_input directory."
27562757
endif
@@ -2860,7 +2861,7 @@ subroutine get_tracers(tracer_names, tracer_types)
28602861
tracer_types(i) = 0 ! temporary until SCM is configured to work with GOCART
28612862
end do
28622863
else
2863-
write(*,'(a,i0)') 'There was an error opening the file ' // FILE_NAME // &
2864+
write(error_unit,'(a,i0)') 'There was an error opening the file ' // FILE_NAME // &
28642865
'; error code = ', rc
28652866
error stop "Error opening tracers file"
28662867
end if

scm/src/scm_setup.F90

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module scm_setup
66

7+
use iso_fortran_env, only: error_unit
78
use scm_kinds, only: sp, dp, qp
89
use scm_physical_constants, only: con_hvap, con_hfus, con_cp, con_rocp, con_pi
910
use scm_utils, only: interpolate_to_grid_centers
@@ -354,7 +355,7 @@ subroutine GFS_suite_setup (Model, Statein, Stateout, Sfcprop,
354355
if (nthreads == 1) then
355356
call Interstitial(1)%create(n_cols, Model)
356357
else
357-
print *,' CCPP SCM is only set up to use one thread - shutting down'
358+
write(error_unit,*) ' CCPP SCM is only set up to use one thread - shutting down'
358359
error stop
359360
end if
360361

@@ -384,15 +385,15 @@ subroutine GFS_suite_setup (Model, Statein, Stateout, Sfcprop,
384385

385386
!--- lsidea initialization
386387
if (Model%lsidea) then
387-
print *,' LSIDEA is active but needs to be reworked for FV3 - shutting down'
388+
write(error_unit,*) ' LSIDEA is active but needs to be reworked for FV3 - shutting down'
388389
error stop
389390
!--- NEED TO get the logic from the old phys/gloopb.f initialization area
390391
endif
391392

392393
if(Model%do_ca)then
393-
print *,'Cellular automata cannot be used when CCPP is turned on until'
394-
print *,'the stochastic physics pattern generation code has been pulled'
395-
print *,'out of the FV3 repository and updated with the CCPP version.'
394+
write(error_unit,*) 'Cellular automata cannot be used when CCPP is turned on until'
395+
write(error_unit,*) 'the stochastic physics pattern generation code has been pulled'
396+
write(error_unit,*) 'out of the FV3 repository and updated with the CCPP version.'
396397
error stop
397398
endif
398399

0 commit comments

Comments
 (0)