@@ -8,16 +8,18 @@ module MOM_debugging
8
8
9
9
! This file is part of MOM6. See LICENSE.md for the license.
10
10
11
- use MOM_checksums, only : hchksum, Bchksum, qchksum, uvchksum, hchksum_pair
12
- use MOM_checksums, only : is_NaN, chksum, MOM_checksums_init
13
- use MOM_coms, only : PE_here, root_PE, num_PEs
14
- use MOM_coms, only : min_across_PEs, max_across_PEs, reproducing_sum
15
- use MOM_domains, only : pass_vector, pass_var, pe_here
16
- use MOM_domains, only : BGRID_NE, AGRID, To_All, Scalar_Pair
11
+ use MOM_checksums, only : hchksum, Bchksum, qchksum, uvchksum, hchksum_pair
12
+ use MOM_checksums, only : is_NaN, chksum, MOM_checksums_init
13
+ use MOM_coms, only : PE_here, root_PE, num_PEs
14
+ use MOM_coms, only : min_across_PEs, max_across_PEs, reproducing_sum
15
+ use MOM_domains, only : pass_vector, pass_var, pe_here
16
+ use MOM_domains, only : BGRID_NE, AGRID, To_All, Scalar_Pair
17
17
use MOM_error_handler, only : MOM_error, FATAL, WARNING, is_root_pe
18
- use MOM_file_parser, only : log_version, param_file_type, get_param
19
- use MOM_grid, only : ocean_grid_type
20
- use MOM_hor_index, only : hor_index_type
18
+ use MOM_file_parser, only : log_version, param_file_type, get_param
19
+ use MOM_grid, only : ocean_grid_type
20
+ use MOM_hor_index, only : hor_index_type
21
+ use MOM_io, only : stdout
22
+ use MOM_unit_scaling, only : unit_scale_type
21
23
22
24
implicit none ; private
23
25
@@ -837,67 +839,101 @@ end subroutine chksum_vec_A2d
837
839
838
840
! > This function returns the sum over computational domain of all
839
841
! ! processors of hThick*stuff, where stuff is a 3-d array at tracer points.
840
- function totalStuff (HI , hThick , areaT , stuff )
842
+ function totalStuff (HI , hThick , areaT , stuff , unscale )
841
843
type (hor_index_type), intent (in ) :: HI ! < A horizontal index type
842
- real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: hThick ! < The array of thicknesses to use as weights [m]
843
- real , dimension (HI% isd:,HI% jsd:), intent (in ) :: areaT ! < The array of cell areas [m2]
844
- real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: stuff ! < The array of stuff to be summed in arbitrary units [a]
845
- real :: totalStuff ! < the globally integrated amount of stuff [a m3]
844
+ real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: hThick ! < The array of thicknesses to use as weights
845
+ ! ! [H ~> m or kg m-2] or [m] or [kg m-2]
846
+ real , dimension (HI% isd:,HI% jsd:), intent (in ) :: areaT ! < The array of cell areas [L2 ~> m2] or [m2]
847
+ real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: stuff ! < The array of stuff to be summed in arbitrary
848
+ ! ! units [A ~> a] or [a]
849
+ real , optional , intent (in ) :: unscale ! < A factor that is used to undo scaling of the array
850
+ ! ! and the cell mass or volume before it is summed in
851
+ ! ! [a m3 A-1 H-1 L-2 ~> 1] or [a kg A-1 H-1 L-2 ~> 1]
852
+ real :: totalStuff ! < the globally integrated amount of stuff
853
+ ! ! [A H L2 ~> a m3 or a kg] or [a m3]
846
854
! Local variables
847
- real , dimension (HI% isc:HI% iec, HI% jsc:HI% jec) :: tmp_for_sum ! The column integrated amount of stuff in a cell [a m3]
855
+ real :: tmp_for_sum(HI% isc:HI% iec, HI% jsc:HI% jec) ! The column integrated amount of stuff in a
856
+ ! cell [A H L2 ~> a m3 or a kg] or [a m3]
848
857
integer :: i, j, k, nz
849
858
850
859
nz = size (hThick,3 )
851
860
tmp_for_sum(:,:) = 0.0
852
861
do k= 1 ,nz ; do j= HI% jsc,HI% jec ; do i= HI% isc,HI% iec
853
862
tmp_for_sum(i,j) = tmp_for_sum(i,j) + hThick(i,j,k) * stuff(i,j,k) * areaT(i,j)
854
863
enddo ; enddo ; enddo
855
- totalStuff = reproducing_sum(tmp_for_sum)
864
+ totalStuff = reproducing_sum(tmp_for_sum, unscale = unscale )
856
865
857
866
end function totalStuff
858
867
859
868
! > This subroutine display the total thickness, temperature and salinity
860
869
! ! as well as the change since the last call.
861
- subroutine totalTandS (HI , hThick , areaT , temperature , salinity , mesg )
870
+ subroutine totalTandS (HI , hThick , areaT , temperature , salinity , mesg , US , H_to_mks )
862
871
type (hor_index_type), intent (in ) :: HI ! < A horizontal index type
863
- real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: hThick ! < The array of thicknesses to use as weights [m]
864
- real , dimension (HI% isd:,HI% jsd:), intent (in ) :: areaT ! < The array of cell areas [m2]
865
- real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: temperature ! < The temperature field to sum [degC]
866
- real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: salinity ! < The salinity field to sum [ppt]
872
+ real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: hThick ! < The array of thicknesses to use as weights
873
+ ! ! [H ~> m or kg m-2] or [m] or [kg m-2]
874
+ real , dimension (HI% isd:,HI% jsd:), intent (in ) :: areaT ! < The array of cell areas [L2 ~> m2] or [m2]
875
+ real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: temperature ! < The temperature field to sum [C ~> degC] or [degC]
876
+ real , dimension (HI% isd:,HI% jsd:,:), intent (in ) :: salinity ! < The salinity field to sum [S ~> ppt] or [ppt]
867
877
character (len=* ), intent (in ) :: mesg ! < An identifying message
878
+ type (unit_scale_type), optional , intent (in ) :: US ! < A dimensional unit scaling type
879
+ real , optional , intent (in ) :: H_to_MKS ! < A constant that translates thickness units to its
880
+ ! ! MKS units (m or kg m-2) based on whether the model is
881
+ ! ! Boussinesq [m H-1 ~> 1] or not [kg m-2 H-1 ~> 1]
868
882
! NOTE: This subroutine uses "save" data which is not thread safe and is purely for
869
883
! extreme debugging without a proper debugger.
870
- real , save :: totalH = 0 . ! The total ocean volume, saved for the next call [m3]
871
- real , save :: totalT = 0 . ! The total volume integrated ocean temperature, saved for the next call [degC m3]
872
- real , save :: totalS = 0 . ! The total volume integrated ocean salinity, saved for the next call [ppt m3]
884
+ real , save :: totalH = 0 . ! The total ocean volume or mass, saved for the next
885
+ ! call [H L2 ~> m3 or kg] or [m3] or [kg]
886
+ real , save :: totalT = 0 . ! The total volume integrated ocean temperature, saved for the next
887
+ ! call [C H L2 ~> degC m3 or degC kg] or [degC m3] or [degC kg]
888
+ real , save :: totalS = 0 . ! The total volume integrated ocean salinity, saved for the next
889
+ ! call [S H L2 ~> ppt m3 or ppt kg] or [ppt m3] or [ppt kg]
873
890
! Local variables
874
891
logical , save :: firstCall = .true.
875
- real , dimension (HI% isc:HI% iec, HI% jsc:HI% jec) :: tmp_for_sum ! The volume of each column [m3]
876
- real :: thisH, delH ! The total ocean volume and the change from the last call [m3]
877
- real :: thisT, delT ! The current total volume integrated temperature and the change from the last call [degC m3]
878
- real :: thisS, delS ! The current total volume integrated salinity and the change from the last call [ppt m3]
892
+ real :: tmp_for_sum(HI% isc:HI% iec, HI% jsc:HI% jec) ! The volume of each column [H L2 ~> m3 or kg] or [m3] or [kg]
893
+ real :: thisH, delH ! The total ocean volume and the change from the last call [H L2 ~> m3 or kg] or [m3] or [kg]
894
+ real :: thisT, delT ! The current total volume integrated temperature and the change from the last
895
+ ! call [C H L2 ~> degC m3 or degC kg] or [degC m3] or [degC kg]
896
+ real :: thisS, delS ! The current total volume integrated salinity and the change from the last
897
+ ! call [S H L2 ~> ppt m3 or ppt kg] or [ppt m3] or [ppt kg]
898
+ real :: H_unscale ! A constant that translates thickness units to its MKS units (m or kg m-2) based on
899
+ ! whether the model is Boussinesq [m H-1 ~> 1] or non-Boussinesq [kg m-2 H-1 ~> 1]
900
+ real :: HL2_unscale ! An overall unscaling factor for cell mass or volume [m3 H-1 L-2 ~> 1] or [kg H-1 L-2 ~> 1]
901
+ real :: T_unscale ! An overall unscaling factor for cell-integrated temperature [degC m3 C-1 H-1 L-2 ~> 1] or
902
+ ! [degC kg C-1 H-1 L-2 ~> 1]
903
+ real :: S_unscale ! An overall unscaling factor for cell-integrated salinity [ppt m3 S-1 H-1 L-2 ~> 1] or
904
+ ! [ppt kg S-1 H-1 L-2 ~> 1]
879
905
integer :: i, j, k, nz
880
906
907
+ H_unscale = 1.0 ; if (present (H_to_mks)) H_unscale = H_to_mks
908
+ if (present (US)) then
909
+ HL2_unscale = US% L_to_m** 2 * H_unscale
910
+ T_unscale = US% C_to_degC * HL2_unscale ; S_unscale = US% S_to_ppt * HL2_unscale
911
+ else
912
+ HL2_unscale = H_unscale
913
+ T_unscale = HL2_unscale ; S_unscale = HL2_unscale
914
+ endif
915
+
881
916
nz = size (hThick,3 )
882
917
tmp_for_sum(:,:) = 0.0
883
918
do k= 1 ,nz ; do j= HI% jsc,HI% jec ; do i= HI% isc,HI% iec
884
919
tmp_for_sum(i,j) = tmp_for_sum(i,j) + hThick(i,j,k) * areaT(i,j)
885
920
enddo ; enddo ; enddo
886
- thisH = reproducing_sum(tmp_for_sum)
887
- thisT = totalStuff(HI, hThick, areaT, temperature)
888
- thisS = totalStuff(HI, hThick, areaT, salinity)
921
+ thisH = reproducing_sum(tmp_for_sum, unscale = HL2_unscale )
922
+ thisT = totalStuff(HI, hThick, areaT, temperature, unscale = T_unscale )
923
+ thisS = totalStuff(HI, hThick, areaT, salinity, unscale = S_unscale )
889
924
890
925
if (is_root_pe()) then
891
926
if (firstCall) then
892
927
totalH = thisH ; totalT = thisT ; totalS = thisS
893
- write (0 ,* ) ' Totals H,T,S:' ,thisH, thisT, thisS, ' ' ,mesg
928
+ write (stdout ,* ) ' Totals H,T,S:' , thisH* HL2_unscale, thisT* T_unscale, thisS* S_unscale, ' ' , mesg
894
929
firstCall = .false.
895
930
else
896
931
delH = thisH - totalH
897
932
delT = thisT - totalT
898
933
delS = thisS - totalS
899
934
totalH = thisH ; totalT = thisT ; totalS = thisS
900
- write (0 ,* ) ' Tot/del H,T,S:' ,thisH,thisT,thisS,delH,delT,delS,' ' ,mesg
935
+ write (0 ,* ) ' Tot/del H,T,S:' , thisH* HL2_unscale, thisT* T_unscale, thisS* S_unscale, &
936
+ delH* HL2_unscale, delT* T_unscale, delS* S_unscale, ' ' , mesg
901
937
endif
902
938
endif
903
939
0 commit comments