      MODULE GLOBALS
C
      PUBLIC
C
C     PROCESS ONE OR 20 COMMANDS
C
      LOGICAL MULTICOM
      INTEGER NUMCOM
C
C     NEUTRAL PLOT ARRAY STUFF
C
      CHARACTER*80 NEUTARRAY
      DIMENSION NEUTARRAY(:)
      ALLOCATABLE :: NEUTARRAY
C
C     RADIAL ENERGY DISTRIBUTION (REPLACES REDDAT.DAT)
C
      REAL*8 REDDAT1,REDDAT2,REDDAT3
      DIMENSION REDDAT1(:),REDDAT2(:),REDDAT3(:)
      ALLOCATABLE :: REDDAT1,REDDAT2,REDDAT3
C
C
C     DIFFRACTION ENERGY DISTRIBUTION (REPLACES SPDPSF.DAT)
C
      REAL*8 SPDPSF1,SPDPSF2,SPDPSF3
      DIMENSION SPDPSF1(:),SPDPSF2(:),SPDPSF3(:)
      ALLOCATABLE :: SPDPSF1,SPDPSF2,SPDPSF3
C
C     DIFFRACTION ENERGY DISTRIBUTION (REPLACES PSF.DAT IN RED CALCS)
C
      INTEGER IPSF1,IPSF2,IPSF3
      DIMENSION IPSF1(:),IPSF2(:),IPSF3(:)
      ALLOCATABLE :: IPSF1,IPSF2,IPSF3
C
C     BIG CAPFN SPOT DIAGRAM
      REAL*8 DSPOTT
      REAL*8 DSPOTT1
      REAL*8 DSPOTT2
      REAL*8 DSPOTT3
      REAL*8 DSPOTT4
      REAL*8 DSPOTT5
      REAL*8 DSPOTT6
      REAL*8 DSPOTT7
      REAL*8 DSPOTT8
      REAL*8 DSPOTT9
      REAL*8 DSPOTT10
      DIMENSION DSPOTT(:,:)
      DIMENSION DSPOTT1(:,:)
      DIMENSION DSPOTT2(:,:)
      DIMENSION DSPOTT3(:,:)
      DIMENSION DSPOTT4(:,:)
      DIMENSION DSPOTT5(:,:)
      DIMENSION DSPOTT6(:,:)
      DIMENSION DSPOTT7(:,:)
      DIMENSION DSPOTT8(:,:)
      DIMENSION DSPOTT9(:,:)
      DIMENSION DSPOTT10(:,:)
      ALLOCATABLE :: DSPOTT
      ALLOCATABLE :: DSPOTT1
      ALLOCATABLE :: DSPOTT2
      ALLOCATABLE :: DSPOTT3
      ALLOCATABLE :: DSPOTT4
      ALLOCATABLE :: DSPOTT5
      ALLOCATABLE :: DSPOTT6
      ALLOCATABLE :: DSPOTT7
      ALLOCATABLE :: DSPOTT8
      ALLOCATABLE :: DSPOTT9
      ALLOCATABLE :: DSPOTT10
C
C       FULL IMAGING ARRAYS
C
C       OBJECT
C
      REAL*8 IOBJECTX,IOBJECTY,IOBJECTV,IOBJECTX2,IOBJECTY2
C
      DIMENSION IOBJECTX2(:,:),IOBJECTY2(:,:),OBJTEMP(:,:,:)
      DIMENSION IOBJECTX(:,:),IOBJECTY(:,:),IOBJECTV(:,:,:)
      ALLOCATABLE :: IOBJECTX,IOBJECTY,IOBJECTV
      ALLOCATABLE :: IOBJECTX2,IOBJECTY2,OBJTEMP
C
C       OBJECTX HOLDS X COORDINATE OF ITH ROW, JTH COLUMN AS REAL*8
C       OBJECTY HOLDS Y COORDINATE OF ITH ROW, JTH COLUMN ASREAL*8
C       OBJECTV HOLDS VALUE OF ITH ROW, JTH COLUMN, KTH WAVELENGTH AS REAL*8
C
        INTEGER IOBJECTYPE
C
C       ICOLOR1,ICOLOR2,ICOLOR3
        INTEGER ICOLOR1,ICOLOR2,ICOLOR3,NCRAYS
C       NUMCOLORS
        INTEGER NUMCOLORS,IMAGETYPE
C
C       IMAGE
C
        REAL*8 IIMAGEX,IIMAGEY,IIMAGEV,XR,YR,ZR,IDELX,IDELY,ODELX,ODELY
        REAL*8 IIMAGEX2,IIMAGEY2,IMGTEMP
        REAL*8 VR
        INTEGER OBJNX,OBJNY
        INTEGER IMGNX,IMGNY
C
      DIMENSION IIMAGEX(:,:),IIMAGEY(:,:),IIMAGEV(:,:,:,:),
     1IMGTEMP(:,:,:,:)
      ALLOCATABLE :: IIMAGEX,IIMAGEY,IIMAGEV,IMGTEMP
      DIMENSION IIMAGEX2(:,:),IIMAGEY2(:,:)
      ALLOCATABLE :: IIMAGEX2,IIMAGEY2
C
C       IMAGEX HOLDS X COORDINATE OF ITH ROW, JTH COLUMN AS REAL*8
C       IMAGEY HOLDS Y COORDINATE OF ITH ROW, JTH COLUMN, AS REAL*8
C       IMAGEV HOLDS VALUE OF ITH ROW, JTH COLUMN, KTH WAVELENGTH REAL*8
C
        LOGICAL OXODD,OYODD,IXODD,IYODD
C
      CHARACTER*80 BMPREADR
C
        REAL*8 PSFWV(1:10),GRIIMG
        INTEGER NNPSF,MMMIMG,PGRIMG

      REAL*8 FIMG
      DIMENSION FIMG(:,:)
      ALLOCATABLE :: FIMG
C
      INTEGER XCENTOFF,YCENTOFF
C
      REAL*8 OBJLEVEL
C
C       11/12/2002
C       ZERNIKE REPRESENTATION OF PHASE IN A SYSTEM
C       AS DETERMINED FROM A RAY TRACE REFERENCED TO THE LAST CHIEF RAY AND THE
C       GUT CHIEF RAY
C       FIRST DIMENSION IS ZERN COUNTER
C       1-37 ARE ZERNIKE TERMS, 38 IS REFERENCE RADIUS
C       39,40,41,42,43,44,46 ARE CLAP DATA
C       47,48,49,50,51,52,53 ARE COBS DATA
C       SECOND DIMENSION IS WAVELENGTH NUMBER
C       THIRD DIMENSION IS THE SURFACE NUMBER
C       FOURTH DIMENSION IS 1 FOR GUT RAY, 2 FOR LAST CHIEF RAY
        REAL*8 ZERNSURF
        DIMENSION ZERNSURF(:,:,:,:)
        ALLOCATABLE :: ZERNSURF
C
C       FOE
        LOGICAL PUPIL_EXIST,CAPFN_EXIST,DOMAINS,DOMAINF,AIB,RTHETA
        REAL*8 FOEGRID1
        DIMENSION FOEGRID1(:,:,:,:)
        ALLOCATABLE :: FOEGRID1
C       DIM 1 IS X INDEX
C       DIM 2 IS Y INDEX
C       DIM 3 IS WAVELENGTH NUMBER
C       DIM 4 IS 1 OR 2 FOR REAL OR IMAGINARY PART
        REAL*8 GRIDSX,GRIDSY,NGRIDSX,NGRIDSY
C       GRID SPACINGS AND NUMBERS OF CELLS IN SPATIAL DOMAIN
        REAL*8 GRIDFX,GRIDFY,NGRIDFX,NGRIDFY
C       GRID SPACINGS AND NUMBERS OF CELLS IN FREQUENCY DOMAIN
        INTEGER FOEMODE
C       FOEMODE IS 1=FOCAL, 2=UFOCAL, 3-AFOCAL, 4-UAFOCAL
C
C       DEFINITIONS TO SUPPORT EITHER NSS OR GRADIENT INDEX RAY TRACING
C       MAX NUMBER OF MULTI RAYS SET BY "MRAYS" USING PM COMMAND
C       MULTIRAY DATA IS STORED INDEXED TO THE ENTRANCE PORT SURFACE NUMBER
        REAL*8 MULTIRAY_DATA
        DIMENSION MULTIRAY_DATA(:,:,:)
        ALLOCATABLE :: MULTIRAY_DATA
C
        REAL*8 MULTIREF_DATA
        DIMENSION MULTIREF_DATA(:,:,:)
        ALLOCATABLE :: MULTIREF_DATA
C
        REAL*8 MULTI_DATA
        DIMENSION MULTI_DATA(:,:,:)
        ALLOCATABLE :: MULTI_DATA
C
        REAL*8 GLOBAL_MULTIREF_DATA
        DIMENSION GLOBAL_MULTIREF_DATA(:,:,:)
        ALLOCATABLE :: GLOBAL_MULTIREF_DATA
C
        REAL*8 GLOBAL_MULTIRAY_DATA
        DIMENSION GLOBAL_MULTIRAY_DATA(:,:,:)
        ALLOCATABLE :: GLOBAL_MULTIRAY_DATA
C
        INTEGER NUMHITS
        DIMENSION NUMHITS(:)
        ALLOCATABLE :: NUMHITS
C
C       PLOTTING
        INTEGER P1ARAY
        DIMENSION P1ARAY(:,:,:)
        ALLOCATABLE :: P1ARAY
C
        LOGICAL FOBRUN
C
        REAL*8 OPLCOR
C
C       GRIDS SPECIAL SURFACE UNLOADED FLAG
        LOGICAL GRIDSUNLOADED19(0:499)
        LOGICAL GRIDSUNLOADED20(0:499)
        LOGICAL GRIDSUNLOADED22(0:499)
C
C       FRAME DRAWING FLAG
        LOGICAL FRAME
C
C
C       SEQUENTIAL RAY HISTORY ARRAY
        REAL*8 RHIST
        DIMENSION RHIST(:,:,:)
C       DIMENSION 1 GOES FROM 1 TO 86 TO HOLD THE 50 RAY PARAMETERS AND THE 36
C       POSSIBLE DIFFERENTIAL RAY DATA FROM DIFF AND RFDIFF
C       DIMENSION 2 IS A SEQUENTIAL COUNT OF THE RAYS STORED
C       DIMENSION 3 IS THE SURFACE NUMBER FROM 0 TO MAXSUR
C       RAY HISTORIES ARE STORRED FOR EVERY RAY TRACED TO THE SURFACE NUMBER
C       DESIGNATED BY THE "RHIST" COMMANDS FIRST NUMERIC WORD.
C       IF RHIST'S QUALIFIER WORD IS "YES" OR "ON", RAY DATA IS SAVED
C       AFTER EVERY CALL TO SUBROUTINE RAYTRA
        ALLOCATABLE :: RHIST
C       RAY_HIT_FLAG IS ONLY TRUE WHEN RAY HISTORIES ARE TO BE GATHERED
C       AND IS SET BY THE RHIST COMMAND
C       RAY_HIST_NUM IS THE NUMBER OF THE CURRENT RAY BEING ADDED
C       HIST1 IS TRUE IF THE 1:50 REGULAR RAY DATA HAS ALREADY BEEN SAVED
C       HIST2 IS TRUE IF CHIEF DIFFERENTIAL RAY DATA HAS BEEN SAVED
C       HIST3 IS TRUE WHEN REGULAR DIFFERENTIAL RAY DATA HAS BEEN SAVED.
        INTEGER RAY_HIST_NUM,RHIST_MAXRAYS
        LOGICAL RAY_HIST_FLAG
        LOGICAL SHORTHIST,LONGHIST
C       MTRACE STUFF
        REAL*8 RW1,RW2,RW3,RW4,RW5,FW1,FW2,FW3,FW4,FW5
        REAL*8 SCENE_ARRAY
        DIMENSION SCENE_ARRAY(:,:)
        ALLOCATABLE :: SCENE_ARRAY
C       FIRST INDEX IS 1:3 TO HANDLE AN RGB SCENE BUT ONLY 1 IS USED
C       FOR THE SD PROBLEM
C       INDEX 2 GOES FROM 1 TO FOBNUMBER WHERE THE SEQUENTIAL FOBNUMBER
C       STARTS IN THE FOB -,- CORNER OF THE SCENE AND ROW AT A TIME LEFT TO RIGHT
C       AND THEN UP TO END AT FOB +,+
        LOGICAL MRAYSSET,MFOBSSET
        INTEGER RDF1,RDF2,RDF3,RDF4,RDF5,RCACOCH,FOBNUMBER
C       MULTI-RAY INTENSITY CALCULATION
        REAL*8 TEMPHIST,TEMPINTEN,INTEN_ARRAY,INTENLENGTH_ARRAY
        REAL*8 INTENPIXDIM
        REAL*8 INTEN_XARRAY,INTEN_YARRAY
        DIMENSION TEMPHIST(:,:,:),TEMPINTEN(:,:),INTEN_ARRAY(:,:,:)
        DIMENSION INTEN_XARRAY(:,:),INTEN_YARRAY(:,:)
        ALLOCATABLE :: TEMPHIST,TEMPINTEN,INTEN_ARRAY
        ALLOCATABLE :: INTEN_XARRAY,INTEN_YARRAY
        INTEGER INTENNUM_PIXELS,MAX_INTEN_NUM,INTSURF,INTN,INTDIM
        LOGICAL INTENEXIST
        REAL*8 INTTOT,INTOT2,RTOT,IRTOT
C
C       MTRACEI GRID VARIABLES
        REAL*8 IGRID,IXARRAY,IYARRAY
        INTEGER IARRAY_DIM
        DIMENSION IGRID(:,:,:),IXARRAY(:,:),IYARRAY(:,:)
        ALLOCATABLE :: IGRID,IXARRAY,IYARRAY
C       IGRID(IX,IY,ICODE)
C       ICODE=1 IF 0, GRID CELL DOES NOT COUNT AS IT IS OUTSIDE THE ASSOCIATED CLAP
C                  1, GRID CELL COUNTS
C       ICODE=2 HOLDS IRRADIANCE VALUE
C       ICODE=3 HOLDS THE INTENSITY VALUE
C       ALLOCATABLE :: IGRID,IXARRAY,IYARRAY
C       END MULTI-RAY INTENSITY VARIABLES
C
      INTEGER WIFONT,WISIZE
C
C     GLOBAL ARRAY DARR USED WITH ITER POWL
      REAL*8 DARR
      DIMENSION DARR(:,:)
      ALLOCATABLE :: DARR
C
C     DIFFERENTIAL RAY TRACE TRACKER FOR RAYERROR
      LOGICAL DIFRAYTRACE
C
      END MODULE GLOBALS
