Skip to content

Commit 488e3c8

Browse files
Update IS_IN_UNGRID to handle if grid lon defintions are mismatched (#1325)
1 parent d82913b commit 488e3c8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

model/src/w3triamd.F90

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ SUBROUTINE IS_IN_UNGRID(IMOD, XTIN, YTIN, ITOUT, IS, JS, RW)
17161716
!/ ------------------------------------------------------------------- /
17171717
!local parameters
17181718

1719-
DOUBLE PRECISION :: x1, x2, x3
1719+
DOUBLE PRECISION :: x1, x2, x3, XTINmod, xavg
17201720
DOUBLE PRECISION :: y1, y2, y3
17211721
DOUBLE PRECISION :: s1, s2, s3, sg1, sg2, sg3
17221722
REAL*8 :: PT(3,2)
@@ -1748,19 +1748,26 @@ SUBROUTINE IS_IN_UNGRID(IMOD, XTIN, YTIN, ITOUT, IS, JS, RW)
17481748
!coordinates of the 3rd vertex C
17491749
x3 = PT(3,1)
17501750
y3 = PT(3,2)
1751-
!with M = (XTIN,YTIN) the target point ...
1751+
!ensure XTIN is defined with same coordinates as element
1752+
xavg=(x1+x2+x3)/3
1753+
IF (ABS(XTIN-xavg).GT.180) THEN
1754+
XTINmod=XTIN-SIGN(360.0d0,(XTIN-xavg))
1755+
ELSE
1756+
XTINmod=XTIN
1757+
END IF
1758+
!with M = (XTINmod,YTIN) the target point ...
17521759
!vector product of AB and AC
17531760
sg3=(y3-y1)*(x2-x1)-(x3-x1)*(y2-y1)
17541761
!vector product of AB and AM
1755-
s3=(YTIN-y1)*(x2-x1)-(XTIN-x1)*(y2-y1)
1762+
s3=(YTIN-y1)*(x2-x1)-(XTINmod-x1)*(y2-y1)
17561763
!vector product of BC and BA
17571764
sg1=(y1-y2)*(x3-x2)-(x1-x2)*(y3-y2)
17581765
!vector product of BC and BM
1759-
s1=(YTIN-y2)*(x3-x2)-(XTIN-x2)*(y3-y2)
1766+
s1=(YTIN-y2)*(x3-x2)-(XTINmod-x2)*(y3-y2)
17601767
!vector product of CA and CB
17611768
sg2=(y2-y3)*(x1-x3)-(x2-x3)*(y1-y3)
17621769
!vector product of CA and CM
1763-
s2=(YTIN-y3)*(x1-x3)-(XTIN-x3)*(y1-y3)
1770+
s2=(YTIN-y3)*(x1-x3)-(XTINmod-x3)*(y1-y3)
17641771
IF ((s1*sg1.GE.0).AND.(s2*sg2.GE.0).AND.(s3*sg3.GE.0)) THEN
17651772
itout=ITRI
17661773
nbFound=nbFound+1

0 commit comments

Comments
 (0)