linquad.h90 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. !!----------------------------------------------------------------------
  2. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  3. !! $Id: linquad.h90 2287 2010-10-18 07:53:52Z smasson $
  4. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  5. !!----------------------------------------------------------------------
  6. LOGICAL FUNCTION linquad( px, py, pxv, pyv )
  7. !!----------------------------------------------------------------------
  8. !! *** FUNCTION linquad ***
  9. !!
  10. !! ** Purpose : Determine whether a point P(x,y) lies within or on the
  11. !! boundary of a quadrangle (ABCD) of any shape on a plane.
  12. !!
  13. !! ** Method : Check if the vectorial products PA x PC, PB x PA,
  14. !! PC x PD, and PD x PB are all negative.
  15. !!
  16. !! ** Action :
  17. !!
  18. !! History :
  19. !! ! 2001-11 (N. Daget, A. Weaver)
  20. !! ! 2006-08 (A. Weaver) NEMOVAR migration
  21. !! ! 2006-10 (A. Weaver) Cleanup
  22. !!----------------------------------------------------------------------
  23. !! * Arguments
  24. REAL(KIND=wp), INTENT(IN) :: px ! (lon) of the point P(x,y)
  25. REAL(KIND=wp), INTENT(IN) :: py ! (lat) of the point P(x,y)
  26. REAL(KIND=wp), DIMENSION(4), INTENT(IN) :: &
  27. & pxv, & ! (lon, lat) of the surrounding cell
  28. & pyv
  29. !! * Local declarations
  30. REAL(KIND=wp) :: zst1
  31. REAL(KIND=wp) :: zst2
  32. REAL(KIND=wp) :: zst3
  33. REAL(KIND=wp) :: zst4
  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. END FUNCTION linquad