New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
linquad.h90 in branches/dev_1784_OBS/NEMO/OPA_SRC/OBS – NEMO

source: branches/dev_1784_OBS/NEMO/OPA_SRC/OBS/linquad.h90 @ 2001

Last change on this file since 2001 was 2001, checked in by djlea, 14 years ago

Adding observation operator code

File size: 2.1 KB
Line 
1   LOGICAL FUNCTION linquad( px, py, pxv, pyv )
2      !!----------------------------------------------------------------------
3      !!                    ***  FUNCTION linquad ***
4      !!
5      !! ** Purpose : Determine whether a point P(x,y) lies within or on the
6      !!              boundary of a quadrangle (ABCD) of any shape on a plane.
7      !!
8      !! ** Method  : Check if the vectorial products PA x PC, PB x PA,
9      !!              PC x PD, and PD x PB are all negative.
10      !!
11      !! ** Action  :
12      !!
13      !! History :
14      !!        !  2001-11  (N. Daget, A. Weaver)
15      !!        !  2006-08  (A. Weaver) NEMOVAR migration
16      !!        !  2006-10  (A. Weaver) Cleanup
17      !!----------------------------------------------------------------------
18
19      !! * Arguments
20      REAL(KIND=wp), INTENT(IN) :: &
21         & px,   &                  ! (lon, lat) of the point P(x,y)
22         & py                       
23      REAL(KIND=wp), DIMENSION(4), INTENT(IN) :: &
24         & pxv,  &                  ! (lon, lat) of the surrounding cell
25         & pyv                     
26 
27      !! * Local declarations
28      REAL(KIND=wp) :: &
29         & zst1, &
30         & zst2, &
31         & zst3, &
32         & zst4
33
34      !-----------------------------------------------------------------------
35      ! Test to see if the point is within the cell
36      !-----------------------------------------------------------------------
37      linquad = .FALSE.
38      zst1 =   ( px - pxv(1) ) * ( py - pyv(4) ) &
39         &   - ( py - pyv(1) ) * ( px - pxv(4) )
40      IF ( zst1 <= 0.0 ) THEN
41         zst2 =   ( px - pxv(4) ) * ( py - pyv(3) ) &
42         &   - ( py - pyv(4) ) * ( px - pxv(3) )
43         IF ( zst2 <= 0.0 ) THEN
44            zst3 =   ( px - pxv(3) ) * ( py - pyv(2) ) &
45               &   - ( py - pyv(3) ) * ( px - pxv(2) )
46            IF ( zst3 <= 0.0) THEN
47               zst4 =   ( px - pxv(2) ) * ( py - pyv(1) ) &
48                  &   - ( py - pyv(2) ) * ( px - pxv(1) )
49               IF ( zst4 <= 0.0 ) linquad = .TRUE.
50            ENDIF
51         ENDIF
52      ENDIF
53
54   END FUNCTION linquad
55
Note: See TracBrowser for help on using the repository browser.