C*************************************************************
C  PROGRAM TO CONVERT UTM COORDINATES TO OWENS VALLEYWIDE
C  MODEL GRID ROW/COL.  FOR EXAMPLE, USED TO LOCATE WELLS
C  WITHIN MODEL CELLS.
C  NOTE: THE ORIGIN USED IN THIS PROGRAM IS THE CENTER OF THE
C  MODEL (90,20), NOT O,O
C        WRITTEN BY WRDANSKIN@DCASCR
C        LAST REVISION     4/12/88
C*************************************************************
      IMPLICIT DOUBLE PRECISION (A-Z)
C  DEFINE CONSTANTS
      SCALE=2000.*12.*2.54/100.
      SCALE=1.0/SCALE
      THETA=-1.0*(-73.0317)
      THETA=THETA*0.017453
      XOFF=388774.7
      YOFF=4095402.0
      XCOS=DCOS(THETA)
      XSIN=DSIN(THETA)
C  READ IN NUMBER OF X,Y PAIRS
      READ(5,*)NCOUNT
      WRITE(6,900)
      DO 100 I=1,NCOUNT
C  READ IN UTM X,Y
      READ(5,*)XUTM,YUTM
C  CALCULATE MODEL COORDINATES (ROW AND COLUMN)
      CALL UTMMOD(XUTM,YUTM,XMOD,YMOD)
      IROW=INT(XMOD)+1
      ICOL=INT(YMOD)+1
C  PRINT RESULTS
      WRITE(6,901)XUTM,YUTM,XMOD,YMOD
C      WRITE(6,902)XUTM,YUTM,IROW,ICOL
  100 CONTINUE
C  FORMAT STATEMENTS
  900 FORMAT('   XUTM     YUTM      XMODEL    YMODEL  ')
  901 FORMAT(2F10.0,2F10.4)
  902 FORMAT(2F10.0,2I5)
      STOP
      END
C********************************************************************
C  CONVERT UTM COORDINATES TO OWENS VALLEYWIDE MODEL GRID ROW/COL
C        WRITTEN BY WRDANSKIN@DCASCR
C        LAST REVISION     4/12/88
C
      SUBROUTINE UTMMOD(XUTM,YUTM,XMOD,YMOD)
      IMPLICIT DOUBLE PRECISION (A-Z)
C  DEFINE CONSTANTS
      SCALE=2000.*12.*2.54/100.
      SCALE=1.0/SCALE
      THETA=-1.0*(-73.0317)
      THETA=THETA*0.017453
      XOFF=388774.7
      YOFF=4095402.0
      XCOS=DCOS(THETA)
      XSIN=DSIN(THETA)
C  CALCULATE MODEL GRID ROW AND COLUMN
      X=XUTM-XOFF
      Y=YUTM-YOFF
      XROT=X*XCOS-Y*XSIN
      YROT=X*XSIN+Y*XCOS
      X=XROT*SCALE
      Y=YROT*SCALE
      XMOD=X+90.
      YMOD=Y+20.
      RETURN
      END
