      SUBROUTINE LAMCHK (PROCES)
C
      include "lamchk.comments"
C
      include "opshin.inc"
      include "buffin.inc"
      include "bufpmf.inc"
      include "gpos.inc"
      include "params.inc"
      include "contrl.inc"
      include "discdr.inc"
      include "lmdapr.inc"
      include "scan.inc"
      include "day1cals.inc"
C                                                                 
C     LAMCHK   VERSION 1.0  CGW   BEGUN 01/15/96  COMPLETED 01/18/96 CGW 
C                                                                 
      LOGICAL*1  PROCES                                      
      LOGICAL  DEBUG                                      
      CHARACTER*2  N07, N09, N11, N14, N15, N16, N17, N18                            
      DATA N07/'07'/,N09/'09'/,N11/'11'/,N14/'14'/,N15/'15'/,
     +     N16/'16'/,N17/'17'/,N18/'18'/
C
      INTEGER*4  IAND, ISHFT
      INTEGER*4  IALLGP(12), I4BUF(180)
      REAL*4  GRTWAV(12), DW(12)
      INTEGER*4 IS(12)/1,2,4,5,6,7,12,8,9,10,11,12/
      EQUIVALENCE (IDDISC,I4BUF(1))
C
      DATA IBYT1 /$FF000000/
      DATA IBYTGP/$FFF80000/
      DATA IBIT8 /$00000001/
C
C====> INITIALIZE CONSTANTS RELATING GRATING POSITION TO WAVELENGTH
C
      if(IOPTS(20) .and. ebert(1) .ne. 0)then
        A0 = ebert(1)
        A1 = ebert(2)
        A2 = ebert(3)
      else
      IF(SCNO.EQ.N14) THEN
        A0 = 817.955
        A1 = -9.6163E-05
        A2 = -3782.56
      ELSE IF(SCNO.EQ.N09) THEN
        A0 = 818.865
        A1 = -9.5947E-05
        A2 = -4157.03
      ELSE IF(SCNO.EQ.N11) THEN
        A0 = 820.0
        A1 = -9.58251E-05
        A2 = -3760.8
      ELSE IF(SCNO.EQ.N16) THEN
        A0 = 820.069
        A1 = -9.578205E-05
        A2 = -3730.85
      ELSE IF(SCNO.EQ.N17) THEN
        A0 = 820.0
        A1 = -9.58790E-05
        A2 = -3956.8
      ELSE IF(SCNO.EQ.N18) THEN
        A0 = 820.067
        A1 = -9.583708e-05
        A2 = -3745.66
      ENDIF
      endif

      GPINDX = 39
C
      DO 200 I = 1, 12
         IALLGP(I) = 0
         GRTWAV(I) = 0.0
  200 CONTINUE
C
C====> GET GRATING POSITIONS (IOPTS(13) SET TRUE FOR ZIG-ZAG WAVELENGTHS)
C
      DO 300 J = 1, 12
        I = J
        IF(IOPTS(13)) I = IS(J)
        IALLGP(I) = ISHFT(IAND(I4BUF(GPINDX), IBYTGP), -19)
        GRATEP = IAND(ISHFT(IAND(I4BUF(GPINDX), IBYT1), -31), IBIT8)
        IF (GRATEP .EQ. 1) IALLGP(I) = IALLGP(I) - 2**13
        GRTWAV(I) = A0 * SIN( A1*(A2 + IALLGP(I)) ) * 10.0
        GPINDX = GPINDX + 6
C
C====> ADJUST COMPUTED WAVELENGTH FOR PRIMARY ENCODER ERROR ON N9
C====> (IF ENCODER SWITCHES BACK TO BACKUP AT SOME FUTURE DATE,
C====>  AN END DATE SHOULD BE ADDED TO THE LOGIC (8/9/96))
C
        IYRDAY = DYEAR * 1000.0 + DDOY
c-h        IF(SCNO.EQ.N09.AND.IYRDAY.GT.95044)GRTWAV(I)=GRTWAV(I)+0.37
        IF((SCNO.EQ.N09) .AND. ((IYRDAY.GT.95044) .or.
     1(iyrday.ge.90244.and.iyrday.le.91178)))GRTWAV(I)=GRTWAV(I)+0.37
C
C====> COMPUTE CHANGE OF ALFA IF WAVELENGTHS DIFFERENT
C
        WLENTH(I) = WLEN0(I)
cc ozone absorption used to C&Sigma Ozone
        ALFA(I) = ALFA0(I)
cc parameter used to single scattered radiance with atm temperature
        alfac(i)=alfac0(i)
        calfa1(i)=calfa10(i)
        calfa2(i)=calfa20(i)
        betac(i)=betac0(i)
        DW(I) = GRTWAV(I) - WLEN0(I)
        IF(ABS(DW(I)) .GT. 0.1 .AND. IOPTS(14)) THEN
          CALL NEWALF(WLEN0(I),ALFA0(I),GRTWAV(I),ALFA(I))
          call newalfc(wlen0(i),alfac0(i),calfa10(i),calfa20(i),
     c  betac0(i),grtwav(i),alfac(i),calfa1(i),calfa2(i),betac(i))
          WLENTH(I) = WLEN0(I) + DW(I)
          IF(ALFA(I).EQ.0.0.AND.I.GT.6) PROCES = .FALSE.
        ENDIF
        IF(IOPTS(13).AND.J.EQ.7) THEN
          WLENTH(3) = WLENTH(I)
          WLEN0(3) = WLEN0(I)
          DW(3) = DW(I)
        ENDIF
        IF(IALLGP(I).EQ.-1) PROCES = .FALSE.
c         WRITE (6,3200) GMTSC,IALLGP(i),GRTWAV(i),DW(i),
c    1      WLEN0(i),WLENTH(i),ALFA0(i),ALFA(i),proces
c3200 FORMAT(' GMTSC=',I7,' IALLGP=',I6,' GRTWAV=',F9.2,1x,
c    1      'DW=',F9.3,' WLEN0=',F9.2,' WLENTH=',F9.2,2f9.2,
c    2      4x,l1)
  300 CONTINUE
c
      IF(.NOT.PROCES) THEN
        WRITE (6,3000)
        DO 350 J=1,12
          WRITE (6,3100) GMTSC,IALLGP(J),GRTWAV(J),DW(J),
     1      WLEN0(J),WLENTH(J),ALFA0(J),ALFA(J)
  350   CONTINUE
      ENDIF
C
C  DETERMINE WAVELENGTH INDECES FOR OZONE PAIRS
C
C  STANDARD WAVELENGTHS
C
C-H N16 toms wavelength experiment uses chs 1-6
C-H The pairs are defined in the namelist. 
      IF(PROCES .and. (.not. IOPTS(18))) THEN
        LMDAL = 2
        LMDAS = 4
        LMDBL = 2
        LMDBS = 3
        LMDCL = 1
        LMDCS = 2
        LMDDL = 4
        LMDDS = 5
        LMDBPL = 1
        LMDBPS = 3
C
C  NEW TOMS WAVELENGTHS
C
        IF(WLENTH(12).LT.330.0) THEN
          LMDAL = 1
          LMDAS = 4
          LMDBL = 1
          LMDBS = 3
          LMDCL = 1
          LMDCS = 2
          LMDDL = 4
          LMDDS = 5
          LMDBPL = 2
          LMDBPS = 4
        ENDIF
      ENDIF
C
C  WORD 20 WILL CONTAIN GPOS ERROR INFO FOR CHANNELS 1-6
C
      GPOFF1=0.0
      DO 500 LX=1,6
        JX=6-LX
c-h        IF(SCNO.EQ.N09.AND.IYRDAY.GT.95044) DW(LX)=DW(LX)-0.37
        IF(SCNO.EQ.N09 .AND. ((IYRDAY.GT.95044) .or. 
     1    (iyrday.ge.90244.and.iyrday.le.91178))) DW(LX)=DW(LX)-0.37
        IPOSOF=-DW(LX)/0.75+4.5
        IF(IPOSOF.GE.0.AND.IPOSOF.LE.8)
     1     GPOFF1=GPOFF1 + 10.0**JX * IPOSOF
c-h        IF(SCNO.EQ.N09.AND.IYRDAY.GT.95044) DW(LX)=DW(LX)+0.37
        IF(SCNO.EQ.N09 .AND. ((IYRDAY.GT.95044) .or.
     1    (iyrday.ge.90244.and.iyrday.le.91178))) DW(LX)=DW(LX)+0.37
C       WRITE(6,3300) GPOFF1,DW(LX),IPOSOF,JX,LX
  500 CONTINUE
C
C  WORD 42 WILL CONTAIN GPOS ERROR INFO FOR CHANNELS 7-12
C
      GPOFF2=0.0
      DO 600 LX=7,12
        JX=12-LX
c-h        IF(SCNO.EQ.N09.AND.IYRDAY.GT.95044) DW(LX)=DW(LX)-0.37
        IF(SCNO.EQ.N09 .AND. ((IYRDAY.GT.95044) .or.
     1    (iyrday.ge.90244.and.iyrday.le.91178))) DW(LX)=DW(LX)-0.37
        IPOSOF=-DW(LX)/0.75+4.5
        IF(IPOSOF.GE.0.AND.IPOSOF.LE.8)
     1     GPOFF2=GPOFF2 + 10.0**JX * IPOSOF
c-h        IF(SCNO.EQ.N09.AND.IYRDAY.GT.95044) DW(LX)=DW(LX)+0.37
        IF(SCNO.EQ.N09 .AND. ((IYRDAY.GT.95044) .or.
     1    (iyrday.ge.90244.and.iyrday.le.91178))) DW(LX)=DW(LX)+0.37
C       WRITE(6,3300) GPOFF2,DW(LX),IPOSOF,JX,LX
  600 CONTINUE
C
 3300 FORMAT(1X,2F10.2,3I10)
C
      RETURN                                                      
C
C  FORMATS
C
 3000 FORMAT(1x,'MEASURED WAVELENGTHS OUTSIDE INTERPOLATION ',
     1      'RANGE OF INPUT ANCILLARY DATA! (SKIP SCAN)')
 3100 FORMAT(' GMTSC=',I7,' IALLGP=',I6,' GRTWAV=',F9.2,1x,
     1      'DW=',F9.3,' WLEN0=',F9.2,' WLENTH=',F9.2,2f9.2)
      END                                                         
