!+ Subroutine to write card input for LOWTRAN7.
!
! Method:
!	A suitable range of wavenumbers is determined.
!	Subroutines are called to convert from S. I. units to those
!	employed by LOWTRAN and write the cards themselves.
!
! 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.
!
!- ---------------------------------------------------------------------
      SUBROUTINE LOWTRAN_CARDS(P, T, RANGE, WMOL
     &   , WL_1, WL_2
     &   , L_FIRST, I_REPEAT
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/lowtran_parameters.ecf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(IN)
     &     I_REPEAT
!             REPEAT FLAG FOR LOWTRAN
      LOGICAL	!, INTENT(IN)
     &     L_FIRST
!             FLAG FOR FIRST ENTRY
      REAL*8	!, INTENT(IN)
     &     P
!             PRESSURE
     &   , T
!             TEMPERATURE
     &   , RANGE
!             RANGE IN LOWTRAN
     &   , WMOL(NPD_GAS_LOW)
!             LOWTRAN ARRAY
     &   , WL_1
!             SHORT WAVELENGTH
     &   , WL_2
!             LONG WAVELENGTH
!     LOCAL VARIABLES.
      REAL*8
     &     NU_1
!             LOW INVERSE WAVELENGTH
     &   , NU_2
!             HIGH INVERSE WAVELENGTH
     &   , DELTA_FREQUENCY
!             LOWTRAN FREQUENCY INTERVAL
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     WRITE_CARD_1, WRITE_CARD_2, WRITE_CARD_2C
     &   , WRITE_CARD_2C1, WRITE_CARD_2C2
     &   , WRITE_CARD_3, WRITE_CARD_4, WRITE_CARD_5
!
!
!
!     CHECK THAT THE USER'S RESOLUTION IS ACCEPTABLE.
      IF (LOWTRAN_USER_RESOLUTION.LT.LOWTRAN_RESOLUTION) THEN
         DELTA_FREQUENCY=LOWTRAN_RESOLUTION
      ELSE
         DELTA_FREQUENCY=LOWTRAN_USER_RESOLUTION
      ENDIF
!     ESTABLISH THE LIMITS OF THE BANDS IN WHICH LOWTRAN WILL WORK.
!     A LITTLE TOLERANCE IS ADDED TO ENSURE THAT THE BAND IS COVERED.
      NU_1=1.0D+00/WL_2-DELTA_FREQUENCY
      NU_2=1.0D+00/WL_1+DELTA_FREQUENCY
      NU_1=DELTA_FREQUENCY*DBLE(INT(NU_1/DELTA_FREQUENCY))
      NU_2=DELTA_FREQUENCY*DBLE(INT(0.5D+00+NU_2/DELTA_FREQUENCY))
!     CHECK THAT THESE LIMITS ARE WITHIN LOWTRAN'S RANGE.
      IF (NU_1.LT.LIMIT_WAVE_NUM_IR) THEN
         NU_1=LIMIT_WAVE_NUM_IR
      ENDIF
      IF (NU_2.GT.LIMIT_WAVE_NUM_UV) THEN
         NU_2=LIMIT_WAVE_NUM_UV
      ENDIF
!
!     CALL AS REQUIRED THE ROUTINES TO CONVERT FROM S.I. UNITS TO
!     LOWTRAN'S UNITS AND WRITE THE FORMATTED DATA CARDS.
!
!     WRITE THE TERMINIATION CARD FOR THE PREVIOUS SECTION FIRST.
      IF (.NOT.L_FIRST) THEN
         CALL WRITE_CARD_5(1)
      ENDIF
!
      CALL WRITE_CARD_1(0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 1, -1
     &   , 273.16D+00, 0.0D+00)
      CALL WRITE_CARD_2(0, 0, 0, 3, 0, 0, 0.0D+00, 0.0D+00, 0.0D+00
     &   , 0.0D+00, 0.0D+00)
      CALL WRITE_CARD_2C(1, 1, 0, 'Transmission Data')
      CALL WRITE_CARD_2C1(0.0D+00, P, T, WMOL, 'AADDDDDDDDDDDD')
      CALL WRITE_CARD_2C2(WMOL)
      CALL WRITE_CARD_3(0, 0.0D+00, 0.0D+00, 0.0D+00, RANGE, 0.0D+00
     &   , EARTH_RADIUS, 0, 1, 0, 0.0D+00)
      CALL WRITE_CARD_4(NU_1, NU_2, DELTA_FREQUENCY)
!
      RETURN
      END
