      SUBROUTINE init_out(success)
c============================================================================
c PROCEDURE NAME: 	_init_out
c PROCEDURE TYPE: 	_subroutine
c VERSION DATE:		_28.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
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"

c----------------------------------------------------------------------------
c Local variables
c
      INTEGER*4 lun, siteno, luno, l1, str_1st_blank
      INTEGER*4 sl_len
      CHARACTER*1 dum
      CHARACTER*80 siterec
      CHARACTER*60 filename
      CHARACTER*3 stid
      CHARACTER*9 dato
      CHARACTER*30 sitename, blnkname
      CHARACTER*60 basename

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

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

      CALL get_lun(lun)
      CALL get_lun(luno)

      blnkname='                              '
      basename= ovxdir(1:str_1st_blank(ovxdir)-1)//'/'//
     &                            ovxname(1:str_1st_blank(ovxname)-1)
      l1= str_1st_blank(basename)-1
      CALL date(dato)
      
c-- Open the site list file.

      sl_len=str_1st_blank(slfile)-1
      OPEN(UNIT=lun, file=slfile(1:sl_len), 
     &      form='formatted', status='old', err=900)


c-- Toss header record.

      READ(lun,1) dum

c-- Read sites and create their files in the output directory.

  100 CONTINUE
        READ(lun,1,end=101,err=901) siterec
        READ(siterec,2) siteno 
        WRITE(stid,3) siteno

        filename= basename(1:l1)//stid
        WRITE(6,'(A)')filename
        OPEN(unit=luno,file=filename,form='formatted')

        sitename= blnkname
        sitename= siterec(33:62)
        WRITE(luno,1)sitename // siterec(1:32)
        WRITE(luno,1)'TOMS V.7.2 Overpass Index for '//sat2lc//
     &         '.  Generated: '//dato
        WRITE(luno,1)'MJD    RANK FILE RECD SCN GMTSEC'
        WRITE(luno,1)'#'
        CLOSE(luno)
        GOTO 100

  101 CONTINUE
        CALL unget_lun(luno)
        CLOSE(lun)
        CALL unget_lun(lun)


        success=.TRUE.
        IF(debuglevel .GT. 3) WRITE(6,*)'> SUBROUTINE init_out'
        RETURN

  900 CONTINUE
      WRITE(6,*)'Could not open file SITELIST for reading.'
      success= .FALSE.
      CALL unget_lun(lun)
        IF(debuglevel .GT. 3) WRITE(6,*)'> SUBROUTINE init_out'
      RETURN


  901 CONTINUE
        WRITE(6,*)'From subroutine init_out: error while reading'//
     &  ' site list.'
        success= .FALSE.
        CLOSE(lun)
        CALL unget_lun(lun)
        IF(debuglevel .GT. 3) WRITE(6,*)'> SUBROUTINE init_out'
        RETURN

    1 FORMAT(A)
    2 FORMAT(I3)
    3 FORMAT(I3.3)

      END
