From 488e3c8e18bc5899625d2255d56440e671f96238 Mon Sep 17 00:00:00 2001 From: Jessica Meixner Date: Fri, 13 Dec 2024 20:34:27 +0000 Subject: [PATCH] Update IS_IN_UNGRID to handle if grid lon defintions are mismatched (#1325) --- model/src/w3triamd.F90 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/model/src/w3triamd.F90 b/model/src/w3triamd.F90 index 9fac503b6..b7fb6aaec 100644 --- a/model/src/w3triamd.F90 +++ b/model/src/w3triamd.F90 @@ -1716,7 +1716,7 @@ SUBROUTINE IS_IN_UNGRID(IMOD, XTIN, YTIN, ITOUT, IS, JS, RW) !/ ------------------------------------------------------------------- / !local parameters - DOUBLE PRECISION :: x1, x2, x3 + DOUBLE PRECISION :: x1, x2, x3, XTINmod, xavg DOUBLE PRECISION :: y1, y2, y3 DOUBLE PRECISION :: s1, s2, s3, sg1, sg2, sg3 REAL*8 :: PT(3,2) @@ -1748,19 +1748,26 @@ SUBROUTINE IS_IN_UNGRID(IMOD, XTIN, YTIN, ITOUT, IS, JS, RW) !coordinates of the 3rd vertex C x3 = PT(3,1) y3 = PT(3,2) - !with M = (XTIN,YTIN) the target point ... + !ensure XTIN is defined with same coordinates as element + xavg=(x1+x2+x3)/3 + IF (ABS(XTIN-xavg).GT.180) THEN + XTINmod=XTIN-SIGN(360.0d0,(XTIN-xavg)) + ELSE + XTINmod=XTIN + END IF + !with M = (XTINmod,YTIN) the target point ... !vector product of AB and AC sg3=(y3-y1)*(x2-x1)-(x3-x1)*(y2-y1) !vector product of AB and AM - s3=(YTIN-y1)*(x2-x1)-(XTIN-x1)*(y2-y1) + s3=(YTIN-y1)*(x2-x1)-(XTINmod-x1)*(y2-y1) !vector product of BC and BA sg1=(y1-y2)*(x3-x2)-(x1-x2)*(y3-y2) !vector product of BC and BM - s1=(YTIN-y2)*(x3-x2)-(XTIN-x2)*(y3-y2) + s1=(YTIN-y2)*(x3-x2)-(XTINmod-x2)*(y3-y2) !vector product of CA and CB sg2=(y2-y3)*(x1-x3)-(x2-x3)*(y1-y3) !vector product of CA and CM - s2=(YTIN-y3)*(x1-x3)-(XTIN-x3)*(y1-y3) + s2=(YTIN-y3)*(x1-x3)-(XTINmod-x3)*(y1-y3) IF ((s1*sg1.GE.0).AND.(s2*sg2.GE.0).AND.(s3*sg3.GE.0)) THEN itout=ITRI nbFound=nbFound+1