C
C Subroutine file 'wrl.for' to facilitate writing VRML and POV files
C
C Version: 5.40
C Date: 1999, October 15
C
C.......................................................................
C
C This file consists of the following external procedures:
C     WRL1... Subroutine designed to write the beginning of the output
C             VRML or POV file.
C             WRL1
C
C=======================================================================
C
C     
C
      SUBROUTINE WRL1(LU1,LU2,FILE1,FILE2,VRML)
      INTEGER LU1,LU2
      CHARACTER*(*) FILE1,FILE2,VRML
C
C Subroutine designed to write the beginning of the output VRML or POV
C file.
C
C Input:
C     LU1...  Logical unit number to be used for a possible input.
C     LU2...  Logical unit number connected to output file FILE2.
C     FILE1...Possible input filename.  If FILE1 is blank, the header
C             will be written to FILE2.  If FILE1 is equal to FILE2,
C             FILE2 will be positioned at its end.  Otherwise, file
C             FILE1 will be opened, the content of file FILE1 will be
C             copied to the output file, and file FILE1 will be closed.
C     FILE2...Output filename.  The file has to be open.
C     VRML... Form of the output file: either 'vrml1', 'vrml2', 'gocad'
C             or 'pov'.
C
C No output.
C
C Date: 1999, October 15
C Coded by Ludek Klimes
C
C-----------------------------------------------------------------------
C
C     External function:
      EXTERNAL LENGTH
      INTEGER  LENGTH
C
C     Other variables:
      CHARACTER*255 TEXT
C     TEXT... Used to copy lines from input WRL to output WRL file.
C
C.......................................................................
C
      IF (FILE1.EQ.' ') THEN
C       Writing the beginning a new file:
        IF (VRML.EQ.'vrml1') THEN
          WRITE(LU2,'(A)') '#VRML V1.0 ascii'
        ELSE IF (VRML.EQ.'vrml2') THEN
          WRITE(LU2,'(A)') '#VRML V2.0 utf8'
        ELSE IF (VRML.EQ.'gocad') THEN
          WRITE(LU2,'(A)')
     *      '#GOCAD format (generated by SW3D package FORMS ver.5.40)'
        ELSE IF (VRML.EQ.'pov') THEN
          WRITE(LU2,'(A)') '//POV 3.1'
        END IF
      ELSE IF (FILE1.EQ.FILE2) THEN
C       Output is appended to the input file:
   11   CONTINUE
          READ(LU2,'(A)',END=12) TEXT
        GO TO 11
   12   CONTINUE
      ELSE
C       Copying input file to the output file:
        OPEN(LU1,FILE=FILE1,STATUS='OLD')
   13   CONTINUE
          READ(LU1,'(A)',END=14) TEXT
          WRITE(LU2,'(A)') TEXT(1:LENGTH(TEXT))
        GO TO 13
   14   CONTINUE
        CLOSE(LU1)
      END IF
      IF (FILE1.NE.' '.OR.VRML.NE.'gocad') THEN
        WRITE(LU2,'(A)')
      END IF
      RETURN
      END
C
C=======================================================================
C