!+ Program to produce formatted  transmission data.
!
! Method:
!	A binary file of averaged transmissions is read and its
!	contents are written in a readable form.
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	Version		Date		Comment
!	1.0		12-04-95	First Version under RCS
!					(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77 with extensions listed in documentation.
!
!- ---------------------------------------------------------------------
      PROGRAM LINE_FORMAT
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/def_pp_io.icf'
      INCLUDE 'incl/record_size_trans.pcf'
      INCLUDE 'incl/error.pcf'
!
!     DECLARATION OF VARIABLES
!
      LOGICAL
     &     LOCK_CODE
!             LOGICAL TO FORBID INTERACTIVE LOOPING
      EXTERNAL
     &     LOCK_CODE
!
      CHARACTER
     &     TRANS_TYPE(NPD_SET)*4
!             TYPES OF TRANSMISSION
     &   , CHAR_YN*1
!             CHARACTER RESPONSE VARIABLE
!
      LOGICAL
     &     LOCK_CODE
!             LOGICAL TO FORBID INTERACTIVE LOOPING
      INTEGER
     &     IERR
!             ERROR FLAG
     &   , N_SET
!             NUMBER OFSETS
     &   , LENGTH_SET(NPD_SET)
!             LENGTHS OF SETS
     &   , BAND_SET(NPD_SET)
!             BANDS OF SETS
     &   , TYPE_SET(NPD_SET)
!             TYPE NUMBERS OF GASES
     &   , INDEX_SET(NPD_SET)
!             INDEXING NUMBERS OF GASES
     &   , I_FIRST_RECORD(NPD_SET)
!             FIRST RECORDS OF SETS
     &   , N_PER_TRANS_RECORD
!             NUMBER PER TRANSMISSION RECORD
      INTEGER
     &     I
!             LOOP VARIABLE
      LOGICAL
     &     L_CONTINUUM
!             WORK IN CONTINUUM MODE
      REAL*8
     &     P_SET(NPD_SET)
!             PRESSURES OF SETS
     &   , T_SET(NPD_SET)
!             TEMPERATURES OF SETS
     &   , WAVE_LENGTH_SHORT_SET(NPD_SET)
!             SHORT WAVELENGTH LIMIT OF SET
     &   , WAVE_LENGTH_LONG_SET(NPD_SET)
!             LONG WAVELENGTH LIMIT OF SET
     &   , U_SET(NPD_AMOUNT)
!             AMOUNTS OF ABSORBER IN SETS
     &   , DENSITY_BROAD(NPD_AMOUNT)
!             DENSITY OF BROADENING SPECIES
     &   , TRANS_SET(NPD_AMOUNT)
!             TRANSMISSIONS IN SETS
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     OPEN_TRANS_IN, OPEN_FILE_OUT, READ_TRANS_SUMMARY
     &   , READ_CONTINUUM_DATA, READ_TRANS_DATA
     &   , WRITE_CONTINUUM_FORM, WRITE_TRANS_FORM
!
!
      DATA IERR/I_NORMAL/
!
!
!
!     THIS PROGRAM CAN OPERATE IN LINE OR CONTINUUM MODE.
      WRITE(IU_USER, '(/A/)')
     &   'DO YOU WISH TO FORMAT LINE OR CONTINUUM DATA? (L/C)'
1     READ(IU_STDIN, '(A)') CHAR_YN
      IF ( (CHAR_YN.EQ.'L').OR.(CHAR_YN.EQ.'l') ) THEN
         L_CONTINUUM=.FALSE.
      ELSE IF ( (CHAR_YN.EQ.'C').OR.(CHAR_YN.EQ.'c') ) THEN
         L_CONTINUUM=.TRUE.
      ELSE
         WRITE(IU_ERR, '(A)') '+++ ILLEGAL RESPONSE.'
         IF (LOCK_CODE(.TRUE.)) THEN
            INCLUDE 'batch_error_main.finc'
         ELSE
            WRITE(IU_ERR, '(A)') 'PLEASE RE_TYPE.'
            GOTO 1
         ENDIF
      ENDIF
!
!     OPEN THE INPUT TRANSMISSION FILES
      CALL OPEN_TRANS_IN(IERR, N_PER_TRANS_RECORD)
      IF (IERR.NE.I_NORMAL) STOP
!
!     OPEN THE FORMATTED OUTPUT FILE.
      CALL OPEN_FILE_OUT(IERR, IU_TRANSMISSION_FORM
     &   , 'GIVE A NAME FOR THE FORMATTED OUTPUT FILE.')
      IF (IERR.NE.I_NORMAL) STOP
!
!     READ THE SUMMARY FILE TO DETERMINE THE CHARACTERISTICS OF THE DATA
      CALL READ_TRANS_SUMMARY(IERR, L_CONTINUUM
     &   , TRANS_TYPE
     &   , N_SET, LENGTH_SET , P_SET, T_SET
     &   , WAVE_LENGTH_SHORT_SET, WAVE_LENGTH_LONG_SET
     &   , BAND_SET, TYPE_SET, INDEX_SET, I_FIRST_RECORD
     &   )
      IF (IERR.NE.I_NORMAL) STOP
!
!     FOR EACH SET IN TURN READ THE DATA AND WRITE 
!     THEM OUT IN THE USUAL FORM.
      DO I=1, N_SET
         IF (L_CONTINUUM) THEN
            CALL READ_CONTINUUM_DATA(I_FIRST_RECORD(I), LENGTH_SET(I)
     &         , U_SET, DENSITY_BROAD, TRANS_SET, N_PER_TRANS_RECORD)
            CALL WRITE_CONTINUUM_FORM(TRANS_TYPE(I)
     &         , LENGTH_SET(I), BAND_SET(I), INDEX_SET(I)
     &         , P_SET(I), T_SET(I)
     &         , U_SET, DENSITY_BROAD, TRANS_SET
     &         , WAVE_LENGTH_SHORT_SET(I), WAVE_LENGTH_LONG_SET(I)
     &         )
         ELSE
            CALL READ_TRANS_DATA(I_FIRST_RECORD(I), LENGTH_SET(I)
     &         , U_SET, TRANS_SET, N_PER_TRANS_RECORD)
            CALL WRITE_TRANS_FORM(TYPE_SET(I)
     &         , TRANS_TYPE(I)
     &         , LENGTH_SET(I), BAND_SET(I), INDEX_SET(I)
     &         , P_SET(I), T_SET(I)
     &         , U_SET, TRANS_SET
     &         , WAVE_LENGTH_SHORT_SET(I), WAVE_LENGTH_LONG_SET(I)
     &         )
         ENDIF
      ENDDO
!
      CLOSE(IU_TRANSMISSION_FORM)
!
!
      STOP
      END
