@@ -4139,8 +4139,8 @@ end subroutine downsample_diag_masks_set
41394139! > Get the diagnostics-compute indices (to be passed to send_data) based on the shape of
41404140! ! the diag field (the same way they are deduced for non-downsampled fields)
41414141subroutine downsample_diag_indices_get (fo1 , fo2 , dl , diag_cs , isv , iev , jsv , jev )
4142- integer , intent (in ) :: fo1 ! < The size of the diag field in x
4143- integer , intent (in ) :: fo2 ! < The size of the diag field in y
4142+ integer , intent (in ) :: fo1 ! < The size of the original diag field in x on data domain including halos
4143+ integer , intent (in ) :: fo2 ! < The size of the original diag field in y on data domain including halos
41444144 integer , intent (in ) :: dl ! < Integer downsample level
41454145 type (diag_ctrl), intent (in ) :: diag_CS ! < Structure used to regulate diagnostic output
41464146 integer , intent (out ) :: isv ! < i-start index for diagnostics
@@ -4168,48 +4168,42 @@ subroutine downsample_diag_indices_get(fo1, fo2, dl, diag_cs, isv, iev, jsv, jev
41684168 first_check = .false.
41694169 endif
41704170
4171- cszi = diag_cs% dsamp(dl)% iec- diag_cs% dsamp(dl)% isc + 1 ; dszi = diag_cs% dsamp(dl)% ied- diag_cs% dsamp(dl)% isd + 1
4172- cszj = diag_cs% dsamp(dl)% jec- diag_cs% dsamp(dl)% jsc + 1 ; dszj = diag_cs% dsamp(dl)% jed- diag_cs% dsamp(dl)% jsd + 1
4173- isv = diag_cs% dsamp(dl)% isc ; iev = diag_cs% dsamp(dl)% iec
4174- jsv = diag_cs% dsamp(dl)% jsc ; jev = diag_cs% dsamp(dl)% jec
4175- f1 = fo1/ dl
4176- f2 = fo2/ dl
4177- ! Correction for the symmetric case
4178- if (diag_cs% G% symmetric) then
4179- f1 = f1 + mod (fo1,dl)
4180- f2 = f2 + mod (fo2,dl)
4181- endif
4182- if ( f1 == dszi ) then
4171+ ! The diagnostics field is defined on the original (non-downsampled) data domain.
4172+ ! The size of the original diag field in each direction is used to deduce the indices to be used for downsampled domain.
4173+ ! The sizes of the original compute and data domains
4174+ cszi = diag_cs% ie- diag_cs% is + 1 ; dszi = diag_cs% ied- diag_cs% isd + 1
4175+ cszj = diag_cs% je- diag_cs% js + 1 ; dszj = diag_cs% jed- diag_cs% jsd + 1
4176+
4177+ if ( fo1 == dszi ) then
41834178 isv = diag_cs% dsamp(dl)% isc ; iev = diag_cs% dsamp(dl)% iec ! field on Data domain, take compute domain indcies
4184- ! The rest is not taken with the full MOM6 diag_table
4185- elseif ( f1 == dszi + 1 ) then
4179+ elseif ( fo1 == dszi + 1 ) then
41864180 isv = diag_cs% dsamp(dl)% isc ; iev = diag_cs% dsamp(dl)% iec+1 ! Symmetric data domain
4187- elseif ( f1 == cszi) then
4181+ elseif ( fo1 == cszi) then
41884182 isv = 1 ; iev = (diag_cs% dsamp(dl)% iec- diag_cs% dsamp(dl)% isc) + 1 ! Computational domain
4189- elseif ( f1 == cszi + 1 ) then
4183+ elseif ( fo1 == cszi + 1 ) then
41904184 isv = 1 ; iev = (diag_cs% dsamp(dl)% iec- diag_cs% dsamp(dl)% isc) + 2 ! Symmetric computational domain
41914185 else
4192- write (mesg,* ) " peculiar size " ,f1, " in i-direction\n" // &
4186+ write (mesg,* ) " dl = " ,dl, " fo1 = " ,fo1, " peculiar size for diag field in i-direction\n" // &
41934187 " does not match one of " , cszi, cszi+1 , dszi, dszi+1
41944188 call MOM_error(FATAL," downsample_diag_indices_get: " // trim (mesg))
41954189 endif
4196- if ( f2 == dszj ) then
4190+ if ( fo2 == dszj ) then
41974191 jsv = diag_cs% dsamp(dl)% jsc ; jev = diag_cs% dsamp(dl)% jec ! Data domain
4198- elseif ( f2 == dszj + 1 ) then
4192+ elseif ( fo2 == dszj + 1 ) then
41994193 jsv = diag_cs% dsamp(dl)% jsc ; jev = diag_cs% dsamp(dl)% jec+1 ! Symmetric data domain
4200- elseif ( f2 == cszj) then
4194+ elseif ( fo2 == cszj) then
42014195 jsv = 1 ; jev = (diag_cs% dsamp(dl)% jec- diag_cs% dsamp(dl)% jsc) + 1 ! Computational domain
4202- elseif ( f2 == cszj + 1 ) then
4196+ elseif ( fo2 == cszj + 1 ) then
42034197 jsv = 1 ; jev = (diag_cs% dsamp(dl)% jec- diag_cs% dsamp(dl)% jsc) + 2 ! Symmetric computational domain
42044198 else
4205- write (mesg,* ) " peculiar size " ,f2, " in j-direction\n" // &
4199+ write (mesg,* ) " dl = " ,dl, " fo2 = " ,fo2, " peculiar size for diag field in j-direction\n" // &
42064200 " does not match one of " , cszj, cszj+1 , dszj, dszj+1
42074201 call MOM_error(FATAL," downsample_diag_indices_get: " // trim (mesg))
42084202 endif
42094203end subroutine downsample_diag_indices_get
42104204
42114205! > This subroutine allocates and computes a downsampled array from an input array
4212- ! ! It also determines the diagnostics-compurte indices for the downsampled array
4206+ ! ! It also determines the diagnostics-compute indices for the downsampled array
42134207! ! 3d interface
42144208subroutine downsample_diag_field_3d (locfield , locfield_dsamp , dl , diag_cs , diag , isv , iev , jsv , jev , mask )
42154209 real , dimension (:,:,:), pointer :: locfield ! < Input array pointer in arbitrary units [A ~> a]
@@ -4360,19 +4354,8 @@ subroutine downsample_field_3d(field_in, field_out, dl, method, mask, diag_cs, d
43604354 eps_area = 1.0e-20 * diag_cs% G% US% m_to_L** 2
43614355 eps_vol = 1.0e-20 * diag_cs% G% US% m_to_L** 2 * diag_cs% GV% m_to_H
43624356
4363- ! Allocate the down sampled field on the down sampled data domain
4364- ! allocate(field_out(diag_cs%dsamp(dl)%isd:diag_cs%dsamp(dl)%ied,diag_cs%dsamp(dl)%jsd:diag_cs%dsamp(dl)%jed,ks:ke))
4365- ! allocate(field_out(1:size(field_in,1)/dl,1:size(field_in,2)/dl,ks:ke))
4366- f_in1 = size (field_in,1 )
4367- f_in2 = size (field_in,2 )
4368- f1 = f_in1/ dl
4369- f2 = f_in2/ dl
4370- ! Correction for the symmetric case
4371- if (diag_cs% G% symmetric) then
4372- f1 = f1 + mod (f_in1,dl)
4373- f2 = f2 + mod (f_in2,dl)
4374- endif
4375- allocate (field_out(1 :f1,1 :f2,ks:ke))
4357+ ! Allocate the down sampled field on the down sampled compute domain
4358+ allocate (field_out(isv_d:iev_d,jsv_d:jev_d,ks:ke))
43764359
43774360 ! Fill the down sampled field on the down sampled diagnostics (almost always compuate) domain
43784361 ! ### The averaging used here is not rotationally invariant.
@@ -4515,20 +4498,8 @@ subroutine downsample_field_2d(field_in, field_out, dl, method, mask, diag_cs, d
45154498 eps_len = 1.0e-20 * diag_cs% G% US% m_to_L
45164499 eps_area = 1.0e-20 * diag_cs% G% US% m_to_L** 2
45174500
4518- ! Allocate the down sampled field on the down sampled data domain
4519- ! allocate(field_out(diag_cs%dsamp(dl)%isd:diag_cs%dsamp(dl)%ied,diag_cs%dsamp(dl)%jsd:diag_cs%dsamp(dl)%jed))
4520- ! allocate(field_out(1:size(field_in,1)/dl,1:size(field_in,2)/dl))
4521- ! Fill the down sampled field on the down sampled diagnostics (almost always compuate) domain
4522- f_in1 = size (field_in,1 )
4523- f_in2 = size (field_in,2 )
4524- f1 = f_in1/ dl
4525- f2 = f_in2/ dl
4526- ! Correction for the symmetric case
4527- if (diag_cs% G% symmetric) then
4528- f1 = f1 + mod (f_in1,dl)
4529- f2 = f2 + mod (f_in2,dl)
4530- endif
4531- allocate (field_out(1 :f1,1 :f2))
4501+ ! Allocate the down sampled field on the down sampled compute domain
4502+ allocate (field_out(isv_d:iev_d,jsv_d:jev_d))
45324503
45334504 if (method == MMP) then
45344505 do j= jsv_d,jev_d ; do i= isv_d,iev_d
@@ -4537,7 +4508,6 @@ subroutine downsample_field_2d(field_in, field_out, dl, method, mask, diag_cs, d
45374508 ave = 0.0
45384509 total_weight = 0.0
45394510 do jj= j0,j0+ dl-1 ; do ii= i0,i0+ dl-1
4540- ! do ii=i0,i0+dl-1 ; do jj=j0,j0+dl-1
45414511 weight = mask(ii,jj)* diag_cs% G% areaT(ii,jj)
45424512 total_weight = total_weight + weight
45434513 ave = ave+ field_in(ii,jj)* weight
@@ -4550,7 +4520,6 @@ subroutine downsample_field_2d(field_in, field_out, dl, method, mask, diag_cs, d
45504520 j0 = jsv_o+ dl* (j- jsv_d)
45514521 ave = 0.0
45524522 do jj= j0,j0+ dl-1 ; do ii= i0,i0+ dl-1
4553- ! do ii=i0,i0+dl-1 ; do jj=j0,j0+dl-1
45544523 weight = mask(ii,jj)
45554524 ave = ave+ field_in(ii,jj)* weight
45564525 enddo ; enddo
0 commit comments