      PROGRAM POUTLOOK_DOS

      USE POUTLOOK_MAIN

      IMPLICIT  NONE

      INTEGER :: Err, Hndl, I, J, ArgC
      CHARACTER (LEN=3)  :: Lake3
      CHARACTER (LEN=10) :: TimeInt, LevMix, QuietStr
      CHARACTER (LEN=20) :: File11
      CHARACTER (LEN=80) :: CmdLine, S, ArgS(9)
      CHARACTER (LEN=20), DIMENSION(5) :: ParmStrings

      !
      !  Initialize to empty
      !
      ParmStrings(1) = ' '       !  "DAILY", "MONTHLY", etc.
      ParmStrings(2) = ' '       !  "LEVEL", "MIXED", or blank
      ParmStrings(3) = ' '       !  "CMS" or blank
      ParmStrings(4) = ' '       !  3-char lake name
      ParmStrings(5) = ' '       !  "QUIET" or blank

      !
      !  Which lake are we doing?
      !
      File11 = 'BSNNM'
      OPEN(UNIT=11, FILE='BSNNM', STATUS='OLD', RECL=12,        &
     &     ACCESS='DIRECT', FORM='FORMATTED', ERR=811)
      READ(11, 1101, REC=1, ERR=812) Lake3
      CLOSE(11)

      !
      !  Fortran 2003 style command line handling
      !  It includes the program name (Lahey did not), so I need to strip
      !  that off before any further processing.
      !
      CALL GET_COMMAND(CmdLine)
      CALL ParseCmdLine(CmdLine, Args, ArgC)
      DO I=2, ArgC
         S = Args(I)
         CALL CAPS(S)
         Args(I-1) = S
      END DO
      ArgC = ArgC-1

      !
      !  Look for time interval string
      !
      DO J = 1, ArgC
         S = ArgS(J)
         I = INDEX(S, 'ANNUAL')
             IF (I .NE. 0) ParmStrings(1) = 'YEAR'
         I = INDEX(S, 'YEAR')
             IF (I .NE. 0) ParmStrings(1) = 'YEAR'

         I = INDEX(S, 'MONTH')
             IF (I .NE. 0) ParmStrings(1) = 'MONTH'

         I = INDEX(S, 'QUARTER')
             IF (I .NE. 0) ParmStrings(1) = 'QTRMONTH'
         I = INDEX(S, 'QTRMONTH')
             IF (I .NE. 0) ParmStrings(1) = 'QTRMONTH'

         I = INDEX(S, 'WEEK')
             IF (I .NE. 0) ParmStrings(1) = 'WEEK'

         I = INDEX(S, 'DAILY')
             IF (I .NE. 0) ParmStrings(1) = 'DAY'
         I = INDEX(S, 'DAY')
             IF (I .NE. 0) ParmStrings(1) = 'DAY'
      END DO
      
      !
      !     Did the user ask for level output?
      !
      DO J = 1, ArgC
         S = ArgS(J)
         I = INDEX(S, 'LEVEL')
             IF (I .NE. 0) ParmStrings(2) = 'LEVEL'
         I = INDEX(S, 'MIXED')
             IF (I .NE. 0) ParmStrings(2) = 'LEVEL'
      END DO
             
      !
      !     Did the user ask for the NBS components to be in CMS?
      !
      DO J = 1, ArgC
         S = ArgS(J)
         I = INDEX(S, 'CMS')
            IF (I .NE. 0) ParmStrings(3) = 'CMS'
      END DO

      !
      !     3-character lake name
      !
      ParmStrings(4) = Lake3

      !
      !     Did the user ask for "QUIET" operation?
      !
      DO J = 1, ArgC
         S = ArgS(J)
         I = INDEX(S, 'QUIET')
            IF (I .NE. 0) ParmStrings(5) = 'QUIET'
      END DO


      CALL DO_POUTLOOK(Err, Hndl, ParmStrings)
      GOTO 999

!
  811 ErrorMessage = 'POUTLOOK: Error opening file ' // TRIM(File11)
      CALL PassMsg; GOTO 898
  812 ErrorMessage = 'POUTLOOK: Error reading file ' // TRIM(File11)
      CALL PassMsg; GOTO 898

  898 ErrorLevel = 1
  899 CALL MakeErrorInt
      ErrorMessage = '[traceback] : POutlook_DOS...'
      CALL PassMsg
      GOTO 999

!  -----------------------
  999 CALL CloseAllFiles

 1101 FORMAT(A3)

      END PROGRAM


      
