      SUBROUTINE XOPNSC(CFILE, QPEND, CSTR, QTIME, IUNIT, IERR)
      CHARACTER CFILE*(*), CSTR*(*)
      LOGICAL   QPEND, QTIME
      INTEGER   IUNIT, IERR
C---
C XPARSE subroutine to open the log file for output.
C---
C CFILE     I/O  The file to be opened
C QPEND     I    If true, the file is oppend append, else new
C CSTR      I    String used as an initial line(with form feed)
C QTIME     I    If true, a date/time stamp is placed on the
C                -initial line
C IUNIT     I/O  If IUNIT>0 then it is the Fortran unit number to be used.
C                -If IUNIT<=0 then on output it is the Fortran unit
C                -number of the log file, as generated by GETLUN
C IERR        O  Error flag from open
C---
C 1990-Nov-01 - Created from XOPNLG [AFT]
C 1998-Jul-17 - James Peachey, HEASARC/GSFC/NASA, Raytheon STX
C               For Y2K compliance, subroutine getdat now returns an
C               11 character date. CTIME was accordingly increased
C               from 18 to 20 characters.
C---
      INTEGER   LENACT
C
      CHARACTER CTMP*80
      CHARACTER CTIME*20
      REAL      RBUF(2)
      INTEGER   LTMP, NBUF
C---
      RBUF(1)=IUNIT
      IF(QPEND) THEN
         RBUF(2)=1.0
      ELSE
         RBUF(2)=0.0
      END IF
      NBUF=2
      LTMP=LENACT(CFILE)
      CALL SCRIPT(3, RBUF, NBUF, CFILE, LTMP)
      IF(NBUF.LT.0) RETURN
      IUNIT=RBUF(1)
C---
C If requested write current date and time
      IF(QTIME) THEN
         CALL GETDAT(CTIME(1:11))
         CTIME(12:12)=' '
         CALL GETTIM(CTIME(13:20))
      ELSE
          CTIME=' '
      END IF
C---
C Write startup string as a comment.
      LTMP=LENACT(CSTR)
      IF(LTMP.GT.0 .OR. QTIME) THEN
         CTMP = '!' // CSTR(:MAX(1,LTMP)) // ' ' //
     &          CTIME(:MAX(1,LENACT(CTIME)))
         CALL SCRIPT(5, RBUF, NBUF, CTMP, LTMP)
      END IF
      RETURN
      END
