      SUBROUTINE init_l2(success)
c============================================================================
c PROCEDURE NAME: 	_init_l2
c PROCEDURE TYPE: 	_subroutine
c VERSION DATE:		_23.II.98
c
c PURPOSE:
c
c CALLING PARAMETERS:
c   Name	Type	i/o	units	Description
c   --------	----	---	-----	--------------
c   success      l4      o              successful completion flag
c
c EXTERNAL ROUTINES REQUIRED:
c
c NOTES & CAVEATS:
c
c REVISION HISTORY:
c   22.VII.98 - Modified for y2k compliant date codes.
c   23.II.98  - Original written (eac)
c
c============================================================================
      IMPLICIT NONE
c----------------------------------------------------------------------------
c Compile parameters
c
      INCLUDE "ovpindex.prm"

c----------------------------------------------------------------------------
c Calling parameters
c
      LOGICAL success

c----------------------------------------------------------------------------
c Common blocks
c
      INCLUDE "ovpindex.cmn"
      INCLUDE "tomsframe.cmn"

c----------------------------------------------------------------------------
c Local variables
c
      CHARACTER*80 f1,f2, lvl2file
      LOGICAL extant
      INTEGER*4 istate

c============================================================================

      IF(debuglevel .GT. 3) WRITE(6,*)'> SUBROUTINE init_l2'


c--Get the lun number we'll use for all the level-2 reads

      CALL get_lun(lun_l2)

c--Compose the first file name and last file names, and make sure the 
c  files exist.

c---first

      f1= lvl2file(yeardoy_init)

      INQUIRE(file=f1, exist=extant)
      IF(.NOT. extant) THEN
        WRITE(6,*)'could not find the first level-2 file:'
        WRITE(6,1) f1
        success= .FALSE.
        RETURN
      END IF

c---last

      f2= lvl2file(yeardoy_final)

      INQUIRE(file=f2, exist=extant)
      IF(.NOT. extant) THEN
        WRITE(6,*)'could not find the last level-2 file:'
        WRITE(6,1) f2
        success= .FALSE.
        RETURN
      END IF


c--Open the first file, skip the header, and read in the first data record

      yeardoy= yeardoy_init
      file_l2= f1
      
      OPEN(unit=lun_l2, 
     &     file=file_l2, 
     &     form='unformatted',
     &     status='old',
     &     READONLY,
     &     ERR=901)

      recno=0
      CALL rdrec7(lun_l2)
      CALL rdrec7(lun_l2)

c--Make sure the record appears to be valid.

      IF(seq .NE. 1) THEN
        WRITE(6,*) 'From subroutine init_l2: unexpected sequence number'
        WRITE(6,*) '   for first data record: seq=',seq
        success=.FALSE.
        RETURN
      END IF

      istate= 1
      success= .TRUE.

      IF(debuglevel .GT. 3) WRITE(6,*)'< SUBROUTINE init_l2'

      RETURN

  901 CONTINUE
      WRITE(6,91) lun_l2, file_l2

    1 FORMAT(A)
    2 FORMAT(I2.2,I3.3)
   91 FORMAT('*** ERROR opening Level-2 file.  UNIT=',i3/
     &  '***    FILE= ',A60)


      END
