Skip to content
Open
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
126 changes: 74 additions & 52 deletions src/Infrastructure/Grid/interface/ESMF_Grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5217,6 +5217,10 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co
integer :: count,inPos,outPos
integer :: ip1,im1

!RASF Corner checking is potentially incorrect for tripolar grids with corner at the tripole. If possible try to
! implement check on next point
integer :: offset

! make sure no dimensions are 0
if ((dim1 < 1) .or. (dim2 <1)) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG,msg="- Currently can't handle a grid of width <1 in a dim.", &
Expand Down Expand Up @@ -5261,56 +5265,74 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co

! Figure out which corner indice is the top row of corners
! It won't match any of the neighbors corners
TopCorner=-1
do i=1,4


offset=0
do

! If default offset=0 fails then try with 1 if dimension allows it.
if ((dim1 == 2 ).and. (offset == 1) ) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
msg="- Currently can't handle a grid thats width 2 in only 1st dim with offset=1", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif

TopCorner=-1
do i=1,4

! See if it matches nbr to the right
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1)-cornerX2D(j,2))<tol) .and. &
(abs(cornerY2D(i,1)-cornerY2D(j,2))<tol)) then
matches=.true.
exit
endif
enddo
if (matches) cycle
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1+offset)-cornerX2D(j,2+offset))<tol) .and. &
(abs(cornerY2D(i,1+offset)-cornerY2D(j,2+offset))<tol)) then
matches=.true.
exit
endif
enddo
if (matches) cycle

! See if it matches nbr to the below
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1+offset)-cornerX2D(j,dim1+1+offset))<tol) .and. &
(abs(cornerY2D(i,1+offset)-cornerY2D(j,dim1+1+offset))<tol)) then
matches=.true.
exit
endif
enddo
if (matches) cycle

! See if it matches nbr to the below and to the right
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1+offset)-cornerX2D(j,dim1+2+offset))<tol) .and. &
(abs(cornerY2D(i,1+offset)-cornerY2D(j,dim1+2+offset))<tol)) then
matches=.true.
exit
endif
enddo
if (matches) cycle

! See if it matches nbr to the below
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1)-cornerX2D(j,dim1+1))<tol) .and. &
(abs(cornerY2D(i,1)-cornerY2D(j,dim1+1))<tol)) then
matches=.true.
exit
endif
enddo
if (matches) cycle
! Doesn't match anyone
TopCorner=i

! See if it matches nbr to the below and to the right
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1)-cornerX2D(j,dim1+2))<tol) .and. &
(abs(cornerY2D(i,1)-cornerY2D(j,dim1+2))<tol)) then
matches=.true.
exit
endif
! Exit the loop
exit
enddo
if (matches) cycle

! Doesn't match anyone
TopCorner=i

! Exit the loop
exit
! If TopCorner is found all is good and exit loop. If offset is 1 then we will test failure outside loop
if(TopCorner/=-1 .or. offset==1) exit
offset=1
enddo

! Make sure we found a corner
if (TopCorner == -1) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
msg="- Bad corner array in SCRIP file", &
! Make sure we found a corner
if (TopCorner == -1) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
msg="- Bad Top corner array in SCRIP file", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
return
endif


! Figure out which corner indice is the top right row of corners
Expand All @@ -5321,8 +5343,8 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co
! See if it matches nbr to the right
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1)-cornerX2D(j,2))<tol) .and. &
(abs(cornerY2D(i,1)-cornerY2D(j,2))<tol)) then
if ((abs(cornerX2D(i,1+offset)-cornerX2D(j,2+offset))<tol) .and. &
(abs(cornerY2D(i,1+offset)-cornerY2D(j,2+offset))<tol)) then
matches=.true.
exit
endif
Expand All @@ -5332,8 +5354,8 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co
! See if it matches nbr to the below right
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1)-cornerX2D(j,dim1+2))<tol) .and. &
(abs(cornerY2D(i,1)-cornerY2D(j,dim1+2))<tol)) then
if ((abs(cornerX2D(i,1+offset)-cornerX2D(j,dim1+2+offset))<tol) .and. &
(abs(cornerY2D(i,1+offset)-cornerY2D(j,dim1+2+offset))<tol)) then
matches=.true.
exit
endif
Expand All @@ -5348,7 +5370,7 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co

! Make sure we found a corner
if (TopRightCorner == -1) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG,msg="- Bad corner array in SCRIP file", &
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG,msg="- Bad TopRight corner array in SCRIP file", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
Expand All @@ -5361,8 +5383,8 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co
! See if it matches nbr to the right
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1)-cornerX2D(j,2))<tol) .and. &
(abs(cornerY2D(i,1)-cornerY2D(j,2))<tol)) then
if ((abs(cornerX2D(i,1+offset)-cornerX2D(j,2+offset))<tol) .and. &
(abs(cornerY2D(i,1+offset)-cornerY2D(j,2+offset))<tol)) then
matches=.true.
exit
endif
Expand All @@ -5372,8 +5394,8 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co
! See if it matches nbr to the below
matches=.false.
do j=1,4
if ((abs(cornerX2D(i,1)-cornerX2D(j,dim1+1))<tol) .and. &
(abs(cornerY2D(i,1)-cornerY2D(j,dim1+1))<tol)) then
if ((abs(cornerX2D(i,1+offset)-cornerX2D(j,dim1+1+offset))<tol) .and. &
(abs(cornerY2D(i,1+offset)-cornerY2D(j,dim1+1+offset))<tol)) then
matches=.true.
exit
endif
Expand All @@ -5389,7 +5411,7 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co

! Make sure we found a corner
if (BtmCorner == -1) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, msg="- Bad corner array in SCRIP file", &
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, msg="- Bad Btm corner array in SCRIP file", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
Expand All @@ -5410,7 +5432,7 @@ subroutine convert_corner_arrays_to_1D(isSphere,dim1,dim2,cornerX2D,cornerY2D,co

! Make sure we found a corner
if (BtmRightCorner == -1) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG,msg="- Bad corner array in SCRIP file", &
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG,msg="- Bad BtmRight corner array in SCRIP file", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
Expand Down