Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion interface/model/eclm/enkf_clm_mod_5.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,8 @@ subroutine domain_def_clm(lon_clmobs, lat_clmobs, dim_obs, &
integer :: ncols, counter
integer :: npatches, ncohorts
real :: minlon, minlat, maxlon, maxlat
real(r8) :: dlon_span, dlat_span
real(r8), parameter :: tol_degen = 1.0e-6_r8
real(r8), pointer :: lon(:)
real(r8), pointer :: lat(:)
integer :: begg, endg ! per-proc gridcell ending gridcell indices
Expand Down Expand Up @@ -1371,14 +1373,28 @@ subroutine domain_def_clm(lon_clmobs, lat_clmobs, dim_obs, &
maxlon = MAXVAL(lon(:) + 180)
minlat = MINVAL(lat(:) + 90)
maxlat = MAXVAL(lat(:) + 90)

! Degenerate horizontal domain (e.g. 1x1 grid): min==max => zero span;
! Avoid dividing by (maxlon-minlon) or (maxlat-minlat).
dlon_span = maxval(lon(:) + 180._r8) - minval(lon(:) + 180._r8)
dlat_span = maxval(lat(:) + 90._r8) - minval(lat(:) + 90._r8)

if(allocated(longxy_obs)) deallocate(longxy_obs)
allocate(longxy_obs(dim_obs), stat=ier)
if(allocated(latixy_obs)) deallocate(latixy_obs)
allocate(latixy_obs(dim_obs), stat=ier)

do i = 1, dim_obs
if(((lon_clmobs(i) + 180) - minlon) /= 0 .and. &
if (dlon_span <= tol_degen .and. dlat_span <= tol_degen) then
longxy_obs(i) = 1
latixy_obs(i) = 1
else if (dlon_span <= tol_degen) then
longxy_obs(i) = 1
latixy_obs(i) = ceiling(((lat_clmobs(i) + 90) - minlat) * nj / (maxlat - minlat))
else if (dlat_span <= tol_degen) then
longxy_obs(i) = ceiling(((lon_clmobs(i) + 180) - minlon) * ni / (maxlon - minlon))
latixy_obs(i) = 1
else if(((lon_clmobs(i) + 180) - minlon) /= 0 .and. &
((lat_clmobs(i) + 90) - minlat) /= 0) then
longxy_obs(i) = ceiling(((lon_clmobs(i) + 180) - minlon) * ni / (maxlon - minlon)) !+ 1
latixy_obs(i) = ceiling(((lat_clmobs(i) + 90) - minlat) * nj / (maxlat - minlat)) !+ 1
Expand All @@ -1395,6 +1411,7 @@ subroutine domain_def_clm(lon_clmobs, lat_clmobs, dim_obs, &
latixy_obs(i) = 1
endif
end do

! deallocate temporary arrays
!deallocate(longxy)
!deallocate(latixy)
Expand Down