      MODULE NSSMOD
C
      PUBLIC
C
C     NON-SEQUENTIAL STUFF
C
      LOGICAL NEXISTN
C
      CHARACTER*80 NSSDIR
C
      INTEGER SFID,MAXS
C
      REAL*8 NSSSYSTEM,NSSALENS,LVECTOR,VECTORL,VECTORM,VECTORN
      DIMENSION NSSSYSTEM(:),NSSALENS(:,:),LVECTOR(:)
      DIMENSION VECTORL(:),VECTORM(:),VECTORN(:)
      ALLOCATABLE :: NSSSYSTEM,NSSALENS,LVECTOR,VECTORL,VECTORM,VECTORN
C
      REAL*8    NSSVERTEX
      DIMENSION NSSVERTEX(:,:)
      ALLOCATABLE :: NSSVERTEX
C
      REAL*8    NSSBOUNDS
      DIMENSION NSSBOUNDS(:,:)
      ALLOCATABLE :: NSSBOUNDS
C
      CHARACTER*80 NSSSNAM,NSSONAM
      DIMENSION NSSSNAM(:)
      ALLOCATABLE :: NSSSNAM
C
      CHARACTER NSSOGLASS(1:2)*13,CURGLASS(1:2)*13
      CHARACTER FROM_MEDIA(1:2)*13
      CHARACTER TO_MEDIA(1:2)*13
      CHARACTER NSSGLASS1*13,NSSGLASS2*13
      DIMENSION NSSGLASS1(:,:),NSSGLASS2(:,:)
      ALLOCATABLE :: NSSGLASS1,NSSGLASS2
C
      REAL*8 OBJINDEX(1:20),CURINDEX(1:20)

C     NSS RAY STUFF
C
      INTEGER SNUM
C
      INTEGER DETONUM,DETSNUM,LASTSUR
C
      REAL*8 OLD_LTEST
C
      REAL*8 NSSRAY_ENERGY,NSSRAY_RPOL(1:20),
     1 NSSRAY_IPOL(1:20)
C
      INTEGER NSSRAY_HITS
C
      LOGICAL NSSRAY_EXIST
C
C       SET TO 50 BUT ONLY USE 16 AS OF 4/2004
C       START IS THE ORIGINAL STARTING RAY DATA
      REAL*8 START(1:50)
C
C     GRAY IS THE RAY DATA IN GLOBAL COORDINATES BEFORE SURFACE INTERACTION
      REAL*8 NSS_GRAY(1:50)
C     LRAY IS THE RAY DATA IN LOCAL COORDINATES BEFORE SURFACE INTERACTION
      REAL*8 NSS_LRAY(1:50)
C     GRAYP IS THE RAY DATA IN GLOBAL COORDINATES AFTER SURFACE INTERACTION
      REAL*8 NSS_GRAYP(1:50)
C     LRAYP IS THE RAY DATA IN LOCAL COORDINATES AFTER SURFACE INTERACTION
      REAL*8 NSS_LRAYP(1:50)
C
C     OGRAY IS THE PREVIOUS RAY DATA IN GLOBAL COORDINATES BEFORE SURFACE INTERACTION
      REAL*8 NSS_OGRAY(1:50)
C     OLRAY IS THE PREVIOUS RAY DATA IN LOCAL COORDINATES BEFORE SURFACE INTERACTION
      REAL*8 NSS_OLRAY(1:50)
C     OGRAYP IS THE PREVIOUS RAY DATA IN GLOBAL COORDINATES AFTER SURFACE INTERACTION
      REAL*8 NSS_OGRAYP(1:50)
C     OLRAYP IS THE PREVIOUS RAY DATA IN LOCAL COORDINATES AFTER SURFACE INTERACTION
      REAL*8 NSS_OLRAYP(1:50)
C
      CHARACTER*13, TO_MEDA,TO_MEDB,FROM_MEDA,FROM_MEDB
C
      LOGICAL NSS_INTERSECT
C
      REAL*8 NSSWAVL,NSSWVWT,REALINDEX1,REALINDEX2,IMAGINDEX1
      REAL*8 IMAGINDEX2
      INTEGER NSSWAVNUM
C
      REAL*8 RRX0,RRY0,RRZ0,RRL0,RRM0,RRN0
      REAL*8 XRRL0,XRRM0,XRRN0
      REAL*8 YRRL0,YRRM0,YRRN0
C
      REAL*8 RRX,RRY,RRZ,RRL,RRM,RRN,NSSLN,NSSMN,NSSNN
      REAL*8 NLN,NMN,NNN
      REAL*8 XRRL,XRRM,XRRN
      REAL*8 YRRL,YRRM,YRRN
      LOGICAL NSSRAYFAIL
      INTEGER NSSRAYFAILCODE(1:2)
C       1 IS THE FAILED SURFACE
C       2 IS FAILURE CODE
C               1. INTERACTION FAILURE
C
C     GLOBAL RAY DATA BEFORE SURFACE SEARCH
      REAL*8 GRRX,GRRY,GRRZ,GRRL,GRRM,GRRN
      REAL*8 GXRRL,GXRRM,GXRRN
      REAL*8 GYRRL,GYRRM,GYRRN
C     LOCAL RAY DATA BEFORE SURFACE SEARCH
      REAL*8 LRRX,LRRY,LRRZ,LRRL,LRRM,LRRN
      REAL*8 LXRRL,LXRRM,LXRRN
      REAL*8 LYRRL,LYRRM,LYRRN
C
      REAL*8 CURWAVELENGTH,CURINDEXR,CURINDEXI,PREVINDEXR,PREVINDEXI
C
C       RAY TRAVEL DIRECTION 1= FROM MEDIA1 TO 2, 2= MEDIA2 TO 1
        INTEGER TRAVEL
C
C       EVEN OR ODD GRIDS
        LOGICAL OBJODD,REFODD
C
C       SAG ERROR FLAG
        LOGICAL NSSSAGERR
C
C       NSS SCALE FACTOR
        REAL*8 NSSSCFA,NSSPSIZP
        REAL*8 NSSSCFAP,NSSPSIZ
        LOGICAL NSSPLSZ,NSSPLSC
C
C       MEM ARRAYS
        REAL*8 MEMX,MEMY,MEMXERROR,MEMYERROR
        INTEGER MEMXSTATE,MEMYSTATE
        DIMENSION MEMX(:,:),MEMY(:,:),MEMXERROR(:,:),
     1  MEMYERROR(:,:)
        DIMENSION MEMXSTATE(:,:),MEMYSTATE(:,:)
        ALLOCATABLE :: MEMX,MEMY,MEMXSTATE,MEMYSTATE
        ALLOCATABLE :: MEMXERROR,MEMYERROR
C
C       NSS SPOT DIAGRAM TYPES
C       0=NO SPOT
C       1=SPOT
C       2_SPOTADD
        INTEGER NSSSPOTTYPE
        INTEGER NSSSPOTSURF,NSPOT,NSSSPOTHITS
        LOGICAL NSSSPOTEXIST
C
C       CURRENT REAL INDEX VALUES
        REAL*8 NSS_N,NSS_NP
C
C       OPL AND RAYLENGTH
        REAL*8 NSS_OPL,NSS_RAYLENGTH
C
C       RAY HISTORY NUMBER TAG
        INTEGER RHISTN
C
C       STATS
        REAL*8 NSSMEANX
        REAL*8 NSSMEANY
        REAL*8 NSSMEANR
        REAL*8 NSSRMSX
        REAL*8 NSSRMSY
        REAL*8 NSSRMSR
C
C       SUPPORT FOR LINE CONNECTING OBJ CENTER AND REF CENTER
        REAL*8 OMAG,OBJL,OBJM,OBJN,OALPHA,OBETA,OGAMMA
C
C       SUPPORT 200 LEVEL SURFACE POSITION NESTING
        INTEGER NSSNEST(0:200),INEST
C
        REAL*8 XMEMCOR(1:4),YMEMCOR(1:4)
C
      END MODULE NSSMOD
