Skip to content

Commit 7e39421

Browse files
committed
+Add runtime parameter WRITE_TRACER_MIN_MAX
Added the new runtime parameters WRITE_TRACER_MIN_MAX and WRITE_TRACER_MIN_MAX_LOC to the MOM_sum_output module to control whether the maximum and minimum values of temperature, salinity and some tracers are periodically written to stdout, perhaps with their locations, as determined by array_global_min_max. These can be expensive global reductions, so by default these are set to false. All solutions are bitwise identical, but there can be some changes to the output to stdout and there will be new entries in the MOM_parameter_doc.debugging files.
1 parent 8658edf commit 7e39421

File tree

1 file changed

+94
-14
lines changed

1 file changed

+94
-14
lines changed

src/diagnostics/MOM_sum_output.F90

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module MOM_sum_output
2020
use MOM_io, only : axis_info, set_axis_info, delete_axis_info, get_filename_appendix
2121
use MOM_io, only : attribute_info, set_attribute_info, delete_attribute_info
2222
use MOM_io, only : APPEND_FILE, SINGLE_FILE, WRITEONLY_FILE
23+
use MOM_spatial_means, only : array_global_min_max
2324
use MOM_time_manager, only : time_type, get_time, get_date, set_time, operator(>)
2425
use MOM_time_manager, only : operator(+), operator(-), operator(*), operator(/)
2526
use MOM_time_manager, only : operator(/=), operator(<=), operator(>=), operator(<)
@@ -124,6 +125,12 @@ module MOM_sum_output
124125
!! interval at which the run is stopped.
125126
logical :: write_stocks !< If true, write the integrated tracer amounts
126127
!! to stdout when the energy files are written.
128+
logical :: write_min_max !< If true, write the maximum and minimum values of temperature,
129+
!! salinity and some tracer concentrations to stdout when the energy
130+
!! files are written.
131+
logical :: write_min_max_loc !< If true, write the locations of the maximum and minimum values
132+
!! of temperature, salinity and some tracer concentrations to stdout
133+
!! when the energy files are written.
127134
integer :: previous_calls = 0 !< The number of times write_energy has been called.
128135
integer :: prev_n = 0 !< The value of n from the last call.
129136
type(MOM_netcdf_file) :: fileenergy_nc !< The file handle for the netCDF version of the energy file.
@@ -179,6 +186,15 @@ subroutine MOM_sum_output_init(G, GV, US, param_file, directory, ntrnc, &
179186
call get_param(param_file, mdl, "ENABLE_THERMODYNAMICS", CS%use_temperature, &
180187
"If true, Temperature and salinity are used as state "//&
181188
"variables.", default=.true.)
189+
call get_param(param_file, mdl, "WRITE_TRACER_MIN_MAX", CS%write_min_max, &
190+
"If true, write the maximum and minimum values of temperature, salinity and "//&
191+
"some tracer concentrations to stdout when the energy files are written.", &
192+
default=.false., do_not_log=.not.CS%write_stocks, debuggingParam=.true.)
193+
call get_param(param_file, mdl, "WRITE_TRACER_MIN_MAX_LOC", CS%write_min_max_loc, &
194+
"If true, write the locations of the maximum and minimum values of "//&
195+
"temperature, salinity and some tracer concentrations to stdout when the "//&
196+
"energy files are written.", &
197+
default=.false., do_not_log=.not.CS%write_min_max, debuggingParam=.true.)
182198
call get_param(param_file, mdl, "DT", CS%dt_in_T, &
183199
"The (baroclinic) dynamics time step.", &
184200
units="s", scale=US%s_to_T, fail_if_missing=.true.)
@@ -404,6 +420,34 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
404420
character(len=32) :: mesg_intro, time_units, day_str, n_str, date_str
405421
logical :: date_stamped
406422
type(time_type) :: dt_force ! A time_type version of the forcing timestep.
423+
424+
real :: S_min ! The global minimum unmasked value of the salinity [ppt]
425+
real :: S_max ! The global maximum unmasked value of the salinity [ppt]
426+
real :: S_min_x ! The x-positions of the global salinity minima
427+
! in the units of G%geoLonT, often [degrees_E] or [km]
428+
real :: S_min_y ! The y-positions of the global salinity minima
429+
! in the units of G%geoLatT, often [degrees_N] or [km]
430+
real :: S_min_z ! The z-positions of the global salinity minima [layer]
431+
real :: S_max_x ! The x-positions of the global salinity maxima
432+
! in the units of G%geoLonT, often [degrees_E] or [km]
433+
real :: S_max_y ! The y-positions of the global salinity maxima
434+
! in the units of G%geoLatT, often [degrees_N] or [km]
435+
real :: S_max_z ! The z-positions of the global salinity maxima [layer]
436+
437+
real :: T_min ! The global minimum unmasked value of the temperature [degC]
438+
real :: T_max ! The global maximum unmasked value of the temperature [degC]
439+
real :: T_min_x ! The x-positions of the global temperature minima
440+
! in the units of G%geoLonT, often [degreeT_E] or [km]
441+
real :: T_min_y ! The y-positions of the global temperature minima
442+
! in the units of G%geoLatT, often [degreeT_N] or [km]
443+
real :: T_min_z ! The z-positions of the global temperature minima [layer]
444+
real :: T_max_x ! The x-positions of the global temperature maxima
445+
! in the units of G%geoLonT, often [degreeT_E] or [km]
446+
real :: T_max_y ! The y-positions of the global temperature maxima
447+
! in the units of G%geoLatT, often [degreeT_N] or [km]
448+
real :: T_max_z ! The z-positions of the global temperature maxima [layer]
449+
450+
407451
! The units of the tracer stock vary between tracers, with [conc] given explicitly by Tr_units.
408452
real :: Tr_stocks(MAX_FIELDS_) ! The total amounts of each of the registered tracers [kg conc]
409453
real :: Tr_min(MAX_FIELDS_) ! The global minimum unmasked value of the tracers [conc]
@@ -527,11 +571,20 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
527571

528572
nTr_stocks = 0
529573
Tr_minmax_avail(:) = .false.
530-
call call_tracer_stocks(h, Tr_stocks, G, GV, US, tracer_CSp, stock_names=Tr_names, &
531-
stock_units=Tr_units, num_stocks=nTr_stocks,&
532-
got_min_max=Tr_minmax_avail, global_min=Tr_min, global_max=Tr_max, &
533-
xgmin=Tr_min_x, ygmin=Tr_min_y, zgmin=Tr_min_z,&
534-
xgmax=Tr_max_x, ygmax=Tr_max_y, zgmax=Tr_max_z)
574+
if (CS%write_min_max .and. CS%write_min_max_loc) then
575+
call call_tracer_stocks(h, Tr_stocks, G, GV, US, tracer_CSp, stock_names=Tr_names, &
576+
stock_units=Tr_units, num_stocks=nTr_stocks,&
577+
got_min_max=Tr_minmax_avail, global_min=Tr_min, global_max=Tr_max, &
578+
xgmin=Tr_min_x, ygmin=Tr_min_y, zgmin=Tr_min_z,&
579+
xgmax=Tr_max_x, ygmax=Tr_max_y, zgmax=Tr_max_z)
580+
elseif (CS%write_min_max) then
581+
call call_tracer_stocks(h, Tr_stocks, G, GV, US, tracer_CSp, stock_names=Tr_names, &
582+
stock_units=Tr_units, num_stocks=nTr_stocks,&
583+
got_min_max=Tr_minmax_avail, global_min=Tr_min, global_max=Tr_max)
584+
else
585+
call call_tracer_stocks(h, Tr_stocks, G, GV, US, tracer_CSp, stock_names=Tr_names, &
586+
stock_units=Tr_units, num_stocks=nTr_stocks)
587+
endif
535588
if (nTr_stocks > 0) then
536589
do m=1,nTr_stocks
537590
vars(num_nc_fields+m) = var_desc(Tr_names(m), units=Tr_units(m), &
@@ -540,6 +593,13 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
540593
num_nc_fields = num_nc_fields + nTr_stocks
541594
endif
542595

596+
if (CS%use_temperature .and. CS%write_stocks) then
597+
call array_global_min_max(tv%T, G, nz, T_min, T_max, &
598+
T_min_x, T_min_y, T_min_z, T_max_x, T_max_y, T_max_z, unscale=US%C_to_degC)
599+
call array_global_min_max(tv%S, G, nz, S_min, S_max, &
600+
S_min_x, S_min_y, S_min_z, S_max_x, S_max_y, S_max_z, unscale=US%S_to_ppt)
601+
endif
602+
543603
if (CS%previous_calls == 0) then
544604

545605
CS%mass_prev_EFP = mass_EFP
@@ -847,24 +907,44 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
847907
write(stdout,'(" Total Salt: ",ES24.16,", Change: ",ES24.16," Error: ",ES12.5," (",ES8.1,")")') &
848908
Salt*0.001, Salt_chg*0.001, Salt_anom*0.001, Salt_anom/Salt
849909
endif
910+
if (CS%write_min_max .and. CS%write_min_max_loc) then
911+
write(stdout,'(16X,"Salinity Global Min:",ES24.16,1X,"at: (",f7.2,",",f7.2,",",f8.2,")" )') &
912+
S_min, S_min_x, S_min_y, S_min_z
913+
write(stdout,'(16X,"Salinity Global Max:",ES24.16,1X,"at: (",f7.2,",",f7.2,",",f8.2,")" )') &
914+
S_max, S_max_x, S_max_y, S_max_z
915+
elseif (CS%write_min_max) then
916+
write(stdout,'(16X,"Salinity Global Min & Max:",ES24.16,1X,ES24.16)') S_min, S_max
917+
endif
918+
850919
if (Heat == 0.) then
851920
write(stdout,'(" Total Heat: ",ES24.16,", Change: ",ES24.16," Error: ",ES12.5)') &
852921
Heat, Heat_chg, Heat_anom
853922
else
854923
write(stdout,'(" Total Heat: ",ES24.16,", Change: ",ES24.16," Error: ",ES12.5," (",ES8.1,")")') &
855924
Heat, Heat_chg, Heat_anom, Heat_anom/Heat
856925
endif
926+
if (CS%write_min_max .and. CS%write_min_max_loc) then
927+
write(stdout,'(16X,"Temperature Global Min:",ES24.16,1X,"at: (",f7.2,",",f7.2,",",f8.2,")" )') &
928+
T_min, T_min_x, T_min_y, T_min_z
929+
write(stdout,'(16X,"Temperature Global Max:",ES24.16,1X,"at: (",f7.2,",",f7.2,",",f8.2,")" )') &
930+
T_max, T_max_x, T_max_y, T_max_z
931+
elseif (CS%write_min_max) then
932+
write(stdout,'(16X,"Temperature Global Min & Max:",ES24.16,1X,ES24.16)') T_min, T_max
933+
endif
857934
endif
858935
do m=1,nTr_stocks
859936

860-
write(stdout,'(" Total ",a,": ",ES24.16,1X,a)') &
937+
write(stdout,'(" Total ",a,": ",ES24.16,1X,a)') &
861938
trim(Tr_names(m)), Tr_stocks(m), trim(Tr_units(m))
862939

863-
if (Tr_minmax_avail(m)) then
864-
write(stdout,'(64X,"Global Min:",ES24.16,1X,"at: (",f7.2,",",f7.2,",",f8.2,")" )') &
865-
Tr_min(m),Tr_min_x(m),Tr_min_y(m),Tr_min_z(m)
866-
write(stdout,'(64X,"Global Max:",ES24.16,1X,"at: (",f7.2,",",f7.2,",",f8.2,")" )') &
867-
Tr_max(m),Tr_max_x(m),Tr_max_y(m),Tr_max_z(m)
940+
if (CS%write_min_max .and. CS%write_min_max_loc .and. Tr_minmax_avail(m)) then
941+
write(stdout,'(18X,a," Global Min:",ES24.16,1X,"at: (",f7.2,",",f7.2,",",f8.2,")" )') &
942+
trim(Tr_names(m)), Tr_min(m), Tr_min_x(m), Tr_min_y(m), Tr_min_z(m)
943+
write(stdout,'(18X,a," Global Max:",ES24.16,1X,"at: (",f7.2,",",f7.2,",",f8.2,")" )') &
944+
trim(Tr_names(m)), Tr_max(m), Tr_max_x(m), Tr_max_y(m), Tr_max_z(m)
945+
elseif (CS%write_min_max .and. Tr_minmax_avail(m)) then
946+
write(stdout,'(18X,a," Global Min & Max:",ES24.16,1X,ES24.16)') &
947+
trim(Tr_names(m)), Tr_min(m), Tr_max(m)
868948
endif
869949

870950
enddo
@@ -1269,9 +1349,9 @@ subroutine write_depth_list(G, US, DL, filename)
12691349

12701350
call create_MOM_file(IO_handle, filename, vars, 3, fields, SINGLE_FILE, &
12711351
extra_axes=extra_axes, global_atts=global_atts)
1272-
call MOM_write_field(IO_handle, fields(1), DL%depth, unscale=US%Z_to_m)
1273-
call MOM_write_field(IO_handle, fields(2), DL%area, unscale=US%L_to_m**2)
1274-
call MOM_write_field(IO_handle, fields(3), DL%vol_below, unscale=US%Z_to_m*US%L_to_m**2)
1352+
call MOM_write_field(IO_handle, fields(1), DL%depth, scale=US%Z_to_m)
1353+
call MOM_write_field(IO_handle, fields(2), DL%area, scale=US%L_to_m**2)
1354+
call MOM_write_field(IO_handle, fields(3), DL%vol_below, scale=US%Z_to_m*US%L_to_m**2)
12751355

12761356
call delete_axis_info(extra_axes)
12771357
call delete_attribute_info(global_atts)

0 commit comments

Comments
 (0)