Skip to content

Commit

Permalink
Merge pull request #6 from billsacks/new_rawpftlai_fix_glacier_region
Browse files Browse the repository at this point in the history
Fix regridding of glacier region
  • Loading branch information
slevis-lmwg authored Aug 26, 2024
2 parents a14758b + 1e803f2 commit 8239120
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tools/mksurfdata_esmf/src/mkglacierregionMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ subroutine mkglacierregion(file_mesh_i, file_data_i, mesh_o, pioid_o, rc)
integer , allocatable :: glacier_region_i(:) ! glacier region on input grid
integer , allocatable :: glacier_region_o(:) ! glacier region on output grid
integer :: ier, rcode ! error status
integer :: max_index(1)
character(len=*), parameter :: subname = 'mkglacierregion'
!-----------------------------------------------------------------------

Expand Down Expand Up @@ -141,10 +140,29 @@ subroutine mkglacierregion(file_mesh_i, file_data_i, mesh_o, pioid_o, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! Determine glacier_region_o
!
! We take the maximum glacier region index that has > 0 coverage in the output grid
! cell. The frequency of occurrence of the different glacier regions is irrelevant.
! For example, if the value 1 appears in 99% of source cells overlapping a given
! destination cell and the value 2 appears in just 1%, we'll put 2 in the destination
! cell because it is the maximum value. (This treatment is important so that we give
! priority to non-zero indices, and more generally allow setting up the glacier region
! indices so that higher values take precedence - i.e., if a CTSM grid cell has any
! overlap with a higher-valued region, we use that region.)
glacier_region_o(:) = 0
do no = 1,ns_o
max_index = maxloc(data_o(:,no))
glacier_region_o(no) = max_index(1) - 1
! Note that we loop starting at the highest index so we give priority to higher
! indices. Also note that we stop looking at index 1 (i.e., we don't explicitly
! look at index 0): if we haven't found a region with greater than 0 coverage from
! looking at the indices greater than 0, then we'll default to assigning this to
! glacier region 0, regardless of the coverage of glacier region 0 (though, in
! practice, glacier region 0 should have 100% coverage in this case).
do l = nglacier_regions, 1, -1
if (data_o(l,no) > 0._r8) then
glacier_region_o(no) = l
exit
end if
end do
end do

! Write output data
Expand Down

0 comments on commit 8239120

Please sign in to comment.