logical function isbackscan(corner_lat, corner_lon)
  !----------------------------------------------------------
  ! Determines whether a pixel from SCIAMACHY is a backscan
  !
  ! INPUT:
  !   corner_lat    -  latitudes of pixel corners
  !   corner_lon    -  longitudes of pixel corners
  !   
  !   The corners must be listed in the same order as in the
  !   SCIA PDS files (between brackets the name in EnviView):
  !     1. first in time, first in flight (cor_coor_nad[0])
  !     2. first in time, last in flight  (cor_coor_nad[1])
  !     3. last in time, first in flight  (cor_coor_nad[2])
  !     4. last in time, last in flight   (cor_coor_nad[3])
  !
  ! RETURNS:
  !   TRUE   -  if the pixel is a backscan
  !   FALSE  -  if the pixel is a forward scan
  ! 
  ! METHOD:
  !   Use the vector product of vectors 1-->2 and 1-->3
  !    (fourth corner is actually not used)
  !
  ! PROGRAMMED BY:
  !   Jan Fokke Meirink, KNMI, Jan. 2003
  !          (idea from Marc Allaart, KNMI)
  !----------------------------------------------------------
  !
  implicit none
  !
  real, dimension(4), intent(in) :: corner_lat, corner_lon
  !
  real :: d1, d2, d3, d4, vector_prod
  !
  d1 = corner_lon(2) - corner_lon(1)
  if (d1 > 180.) d1 = d1 - 360.
  if (d1 < -180.) d1 = d1 + 360.

  d2 = corner_lon(3) - corner_lon(1)
  if (d2 > 180.) d2 = d2 - 360.
  if (d2 < -180.) d2 = d2 + 360.

  d3 = corner_lat(2) - corner_lat(1)

  d4 = corner_lat(3) - corner_lat(1)

  vector_prod = d1*d4 - d2*d3

  isbackscan = (vector_prod > 0)

end function isbackscan
