C
C ***************************************************************************
C
C	IMAGE PIXEL TO LAT,LONG AND LAT,LONG TO IMAGE PIXEL
C       COORDINATE TRANSFORMATION ROUTINES.
C
C ***************************************************************************
C
	SUBROUTINE PIX2LATLON(X,Y,THELON,THELAT,ALON,ALAT,
     $     IOPT,XDEG,YDEG,ASCALE,BSCALE,A0,B0)
C
C	GIVEN AN IMAGE PIXEL LOCATION (X,Y) (AS FLOATING POINT NUMBERS)
C	COMPUTES THE X,Y TRANSFORMATION COORDINATES (THELON,THELAT) AND
C	THE LAT,LON COORDINATES (ALON,ALAT).   THE LAT,LON RETURNED 
C	CORRESPONDS TO THE LOWER-LEFT CORNER OF THE PIXEL.  IF LAT,LON
C	OF PIXEL CENTER IS DESIRED USE (X+0.5,Y+0.5) WHERE X,Y ARE INTEGER
C	VALUED.
C
C	NOTE: GIVEN INTEGER PIXEL INDICES, SET X=FLOAT(IX) Y=FLOAT(IY).
C	-- SEE LATLON2PIX.  WHILE ROUTINE WILL ATTEMPT TO CONVERT ANY (X,Y)
C	VALUES, ONLY (X,Y) VALUES WITH 1 <= X <= NSX+1 AND 1 <= Y <= NSY+1
C	ARE CONTAINED WITHIN IMAGE PIXELS.
C
C	WRITTEN BY: DGL MARCH 1997
C       REVISED BY: DGL SEPT 2005 + corrected EASE grid
C	REVISED BY: DGL 12 MAR 2014 + ADDED EASE2
C
        REAL X,Y,THELON,THELAT,ALON,ALAT,XDEG,YDEG,ASCALE,BSCALE,A0,B0
        INTEGER IOPT
C
	IF (IOPT.EQ.-1) THEN		! IMAGE ONLY (CAN'T TRANSFORM!)
		THELON=(X-1.0)/ASCALE+A0
		THELAT=(Y-1.0)/BSCALE+B0
		ALON=THELON
		ALAT=THELAT
	ELSE IF (IOPT.EQ.0) THEN	! LAT/LONG (ASCALE AND BSCALE > 0)
		THELON=(X-1.0)/ASCALE+A0
		THELAT=(Y-1.0)/BSCALE+B0
		ALON=THELON
		ALAT=THELAT
	ELSE IF (IOPT.EQ.1.OR.IOPT.EQ.2) THEN	! LAMBERT (ASCALE AND BSCALE < 0)
		THELON=(X-1.0)/ASCALE+A0
		THELAT=(Y-1.0)/BSCALE+B0
		CALL ILAMBERT1(ALAT,ALON,THELON,THELAT,YDEG,XDEG,IOPT)
	ELSE IF (IOPT.EQ.5) THEN	! POLAR STEREOGRAPHIC
		THELON=(X-1.0)*ASCALE+A0
		THELAT=(Y-1.0)*BSCALE+B0
		CALL IPOLSTER(ALON,ALAT,THELON,THELAT,XDEG,YDEG)
	ELSE IF (IOPT.EQ.8.OR.IOPT.EQ.9.OR.IOPT.EQ.10) THEN	! EASE2 GRID
		THELON=X-1.0+A0
		THELAT=Y-1.0+B0
		CALL IEASE2GRID(IOPT,ALON,ALAT,THELON,THELAT,ASCALE,BSCALE)
	ELSE IF (IOPT.EQ.11.OR.IOPT.EQ.12.OR.IOPT.EQ.13) THEN	! EASE1 GRID
		THELON=X-XDEG-1.0+(XDEG+A0)
		THELAT=Y-YDEG-1.0+(YDEG+B0)
		CALL IEASEGRID(IOPT,ALON,ALAT,THELON,THELAT,ASCALE)
	ELSE				! UNKNOWN TRANSFORM
	ENDIF
	RETURN
	END
