!+ Subroutines to write card input for LOWTRAN7.
!
! Method:
!	The input to these routines is in S. I. units: these units are
!	conveted to those employed by LOWTRAN7. Exceptions to this 
!	rule are:
!		1. IDAY for cards 3 and 3A1 which is in days.
!		2. The input to card 3A2.
!
! 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.
!
!- ---------------------------------------------------------------------
!
!     ****** CARD1 *******
      SUBROUTINE WRITE_CARD_1(MODEL, ITYPE, IEMSCT, IMULT, M1, M2, M3
     &   , M4, M5, M6, MDEF, IM, NOPRT, TBOUND_SI, SALB)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     MODEL
!             TYPE OF ATMOSPHERE
     &   , ITYPE
!             ATMOSPHERIC PATH
     &   , IEMSCT
!             MODE OF EXECUTION
     &   , IMULT
!             EXECUTION WITH MULTIPLE SCATTERING
     &   , M1
!             PROFILE MODIFICATION
     &   , M2
!              "
     &   , M3
!              "
     &   , M4
!              "
     &   , M5
!              "
     &   , M6
!              "
     &   , MDEF
!              "
     &   , IM
!             READING OF INPUT DATA
     &   , NOPRT
!             CONTROL OF PRINTING
      REAL*8	!, INTENT(IN)
     &     TBOUND_SI
!             BOUNDARY LAYER TEMPERATURE (IN K).
     &   , SALB
!             SURFACE ALBEDO
!
!
      WRITE(IU_LOWTRAN, '(13I5, F8.3, F7.2)')
     &     MODEL, ITYPE, IEMSCT, IMULT, M1, M2, M3, M4, M5, M6, MDEF
     &   , IM, NOPRT, TBOUND_SI, SALB
!
      RETURN
      END
!
!
!     ****** CARD2 ******
!
      SUBROUTINE WRITE_CARD_2(IHAZE, ISEASN, IVULCN, ICSTL, ICLD
     &   , IVSA, VIS_SI, WSS_SI, WHH_SI, RAINRT_SI, GNDALT_SI)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     IHAZE
!             EXTINCTION TYPE FOR B.L. AEROSOLS
     &   , ISEASN
!             SEASONAL AEROSOL PROFILE
     &   , IVULCN
!             STRATOSPHERIC AEROSOL PROFILE
     &   , ICSTL
!             AIR MASS CHARACTER
     &   , ICLD
!             RAIN AND CLOUD MODEL
     &   , IVSA
!             ARMY VERICAL STRUICTURE ALGORITHM
      REAL*8	!, INTENT(IN)
     &     VIS_SI
!             METOEOROLOGICAL RANGE
     &   , WSS_SI
!             WIND SPEED
     &   , WHH_SI
!             AVERAGE WIND SPEED
     &   , RAINRT_SI
!             RAIN RATE
     &   , GNDALT_SI
!             SURFACE ALTITUDE
!
!     LOCAL VARIABLES.
      REAL*8
     &     VIS
!             CONVERTED VISIBILITY
     &   , RAINRT
!             CONVERTED RAIN RATE
     &   , GNDALT
!             CONVERTED ALTITUDE
!
!
!     CONVERSION OF UNITS.
      VIS=VIS_SI/1.0D+03
      RAINRT=RAINRT_SI*3.6D+03/1.0D-03
      GNDALT=GNDALT_SI/1.0D+03
!
      WRITE(IU_LOWTRAN, '(6I5, 5F10.3)')
     &     IHAZE, ISEASN, IVULCN, ICSTL, ICLD, IVSA
     &   , VIS, WSS_SI, WHH_SI, RAINRT, GNDALT
!
      RETURN
      END
!
!
!     ****** CARD 2A ******
!
      SUBROUTINE WRITE_CARD_2A(CTHIK_SI, CALT_SI, CEXT_SI, ISEED)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     ISEED
!             SEED FOR RANDOM NUMBERS
      REAL*8 	!, INTENT(IN)
     &     CTHIK_SI
!             THICKNESS OF CIRRUS
     &   , CALT_SI
!             CIRRUS BASE ALTITUDE
     &   , CEXT_SI
!             EXTINCTION COEFICIENT
!
!     LOCAL VARIABLES.
      REAL*8
     &     CTHIK
!             CONVERTED THICKNESS
     &   , CALT
!             CONVERTED ALTITUDE
     &   , CEXT
!             CONVERTED EXTINCTION COEFFICIENT
!
!
!     CONVERSION OF UNITS.
      CTHIK=CTHIK_SI/1.0D+03
      CALT=CALT_SI/1.0D+03
      CEXT=CEXT_SI/1.0D-03
!
      WRITE(IU_LOWTRAN, '(3F10.3, I10)')
     &     CTHIK, CALT, CEXT, ISEED
!
      RETURN
      END
!
!
!     ****** CARD 2B ******
!
      SUBROUTINE WRITE_CARD_2B(ZCVSA_SI, ZTVSA_SI, ZINVSA_SI)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      REAL*8	!, INTENT(IN)
     &     ZCVSA_SI
!             CLOUD CEILING
     &   , ZTVSA_SI
!             CLOUD THICKNESS
     &   , ZINVSA_SI
!             HEIGHT OF INVERSION
!
!     LOCAL VARIABLES.
      REAL*8	!, INTENT(IN)
     &     ZCVSA
!             CONVERTED CLOUD CEILING
     &   , ZTVSA
!             CONVERTED CLOUD THICKNESS
     &   , ZIVSA
!             CONVERTED INVERSION HEIGHT
!
!
!     CONVERSION OF UNITS.
      ZCVSA=ZCVSA_SI/1.0D+03
      ZTVSA=ZTVSA_SI/1.0D+03
      ZIVSA=ZINVSA_SI/1.0D+03
!
      WRITE(IU_LOWTRAN, '(3F10.3)')
     &     ZCVSA, ZTVSA, ZIVSA
!
      RETURN
      END
!
!
!     ****** CARD 2C ******
!
      SUBROUTINE WRITE_CARD_2C(ML, IRD1, IRD2, TITLE)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      CHARACTER	!, INTENT(IN)
     &     TITLE*(*)
!             TITLE OF NEW ATMOSPHERE
      INTEGER	!, INTENT(IN)
     &     ML
!             NUMBER OF ATMOSPHERIC LEVELS
     &   , IRD1
!             READING CONTROL
     &   , IRD2
!             READING CONTROL
!
!
      WRITE(IU_LOWTRAN, '(3I5, A)')
     &     ML, IRD1, IRD2, TITLE
!
      RETURN
      END
!
!
!     ****** CARD 2C1 ******
!
      SUBROUTINE WRITE_CARD_2C1(ZMDL_SI, P_SI, T_SI, WMOL_SI, JCHAR)
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_lwtrn_io.icf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/lowtran_parameters.ecf'
!
!     DUMMY ARGUMENTS
      CHARACTER 	!, INTENT(IN)
     &     JCHAR(NPD_GAS_LOW+2)
!             CONTROL VARIABLE SELECTING PROFILE UNITS
      REAL*8	!, INTENT(IN)
     &     ZMDL_SI
!             ALTITUDE OF LAYER BOUNDARY
     &   , P_SI
!             PRESSURE OF LAYER BOUNDARY
     &   , T_SI
!             TEMPERATURE OF LAYER BOUNDARY
     &   , WMOL_SI(NPD_GAS_LOW)
!             MOLECULAR SPECIES
!
!     LOCAL VARIABLE
      INTEGER
     &     J
!             LOOP VARIABLE
      REAL*8
     &     ZMDL
!             CONVERTED ALTITUDE
     &   , P
!             CONVERTED PRESSURE
     &   , WMOL(NPD_GAS_LOW)
!             CONVERTED CONCENTRATIONS
!
!
!     CONVERSION OF UNITS
      ZMDL=ZMDL_SI/1.0D+03
      P=P_SI/1.0D+02
!
!     CONVERT MASS DENSITIES FROM KG/M3 TO GM/M3.
      DO J=1, 3
         WMOL(J)=WMOL_SI(J)*1.0D+03
      ENDDO
!
      WRITE(IU_LOWTRAN, '(F10.3, 5E10.3, 15A1)')
     &     ZMDL, P, T_SI, WMOL(1), WMOL(2), WMOL(3)
     &   , (JCHAR(J), J=1, 14)
!
      RETURN
      END
!
!
!     ****** CARD 2C2 ******
!
      SUBROUTINE WRITE_CARD_2C2(WMOL_SI)
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_lwtrn_io.icf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/lowtran_parameters.ecf'
!
      REAL*8	!, INTENT(IN)
     &     WMOL_SI(NPD_GAS_LOW)
!             MOLECULAR SPECIES
!
!     LOCAL VARIABLE
      INTEGER
     &     J
!             LOOP VARIABLE
      REAL*8
     &     WMOL(12)
!             CONVERTED MASS MIXING RATIO
!
!
!     CONVERSION OF MASS DENSITIES FROM KG/M3 TO GM/M3.
      DO J=4,12
         WMOL(J)=WMOL_SI(J)*1.0D+03
      ENDDO
!
      WRITE(IU_LOWTRAN, '(8E10.3)')
     &     (WMOL(J), J=4, 12)
!
      RETURN
      END
!
!
!     ****** CARD 2C3 ******
!
      SUBROUTINE WRITE_CARD_2C3(AHAZE_SI, EQLWCZ_SI, RRATZ_SI
     &   , IHA1, ICLD1, IVUL1, ISEA1, ICHR1)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     IHA1
!             AEROSOL MODEL
     &   , ICLD1
!             CLOUD EXTINCTION CONTROL
     &   , IVUL1
!             STRATOSPHERIC AEROSOL
     &   , ISEA1
!             SEASONAL AEROSOL
     &   , ICHR1
!             CHANGE OF AEROSOL REGIONS
!
      REAL*8	!, INTENT(IN)
     &     AHAZE_SI
!             AEROSOL SCALING FACTOR
     &   , EQLWCZ_SI
!             EQUIVALENT LIQUID WATER CONTENT
     &   , RRATZ_SI
!             RAIN RATE
!
!     LOCAL VARIABLES.
      REAL*8
     &     AHAZE
!             CONVERTED SCALING FACTOR
     &   , EQLWCZ
!             CONVERTED LIQUID WATER
     &   , RRATZ
!             CONVERTED RAIN RATE
!
!
!     CONVERSION OF UNITS.
      AHAZE=AHAZE_SI*1.0D+03
      EQLWCZ=EQLWCZ_SI*1.0D+03
      RRATZ=RRATZ_SI*3.6D+03/1.0D-03
!
      WRITE(IU_LOWTRAN, '(10X, 3F10.3, 5I5)')
     &     AHAZE, EQLWCZ, RRATZ
     &   , IHA1, ICLD1, IVUL1, ISEA1, ICHR1
!
      RETURN
      END
!
!
!     ****** CARD 2D ******
!
      SUBROUTINE WRITE_CARD_2D(IREG)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     IREG(4)
!             REGIONS FOR USER'S AEROSOL MODEL
!
!     LOCAL VARIABLE
      INTEGER
     &     J
!             LOOP VARIABLE
!
!
      WRITE(IU_LOWTRAN, '(4I5)')
     &     (IREG(J), J=1, 4)
!
      RETURN
      END
!
!
!     ****** CARD 2D1 ******
!
      SUBROUTINE WRITE_CARD_2D1(AWCCON, TITLE)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      CHARACTER	!, INTENT(IN)
     &     TITLE
!             TITLE FOR REGIONS
      REAL*8	!, INTENT(IN)
     &     AWCCON
!             LIQUID WATER CONVERSION FACTOR
!
!
!     AWCCON HAS A CONVERSION FACTOR OF UNITY, 
!     SO IT NEED NOT BE CONVERTED.
!
      WRITE(IU_LOWTRAN, '(E10.3, 18A4)')
     &     AWCCON, TITLE
!
      RETURN
      END
!
!
!     ****** CARD 2D2 ******
!
      SUBROUTINE WRITE_CARD_2D2(VX_SI, EXTC_SI, ABSC_SI, ASYM)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      REAL*8	!, INTENT(IN)
     &     VX_SI
!             WAVELENGTH FOR COEFFICIENTS
     &   , EXTC_SI
!             CLOUD EXTINCTION COEFFICIENT
     &   , ABSC_SI
!             AEROSOL ABSORPTION COEFFICIENT
     &   , ASYM
!             AEROSOL ASYMMETRY FACTOR
!
!     LOCAL VARIABLES.
      REAL*8
     &     VX
!             CONVERTED WAVELENGTH
     &   , EXTC
!             CONVERTED EXTINCTION
     &   , ABSC
!             CONVERTED ABSORPTION COEFFICIENT
!
!
!
!     CONVERSIONS.
      VX=VX_SI
      EXTC=EXTC_SI*1.0D+03
      ABSC=ABSC_SI*1.0D+03
!
      WRITE(IU_LOWTRAN, '(F6.2, 2F7.5, F6.4)')
     &     VX, EXTC, ABSC, ASYM
!
      RETURN
      END
!
!
!     ****** CARD 3 ******
!
      SUBROUTINE WRITE_CARD_3(IEMSCT, H1_SI, H2_SI, ANGLE_SI
     &   , RANGE_SI, BETA_SI, RO_SI
     &   , LEN, IDAY, ISOURC, ANGLEM_SI)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
      INCLUDE 'incl/math_cnst.ccf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &      IEMSCT
!             FLAG FOR TRANSMITTANCE MODE
     &    , LEN
!             SHORT OR LONG PATH
     &    , IDAY
!             DAY OF YEAR
     &    , ISOURC
!             EXTRATERRESTRIAL SOURCE
      REAL*8	!, INTENT(IN)
     &      H1_SI
!             INITIAL ALTITUDE
     &    , H2_SI
!             FINAL ALTITUDE
     &    , ANGLE_SI
!             INITIAL ZENITH ANGLE
     &    , RANGE_SI
!             PATH LENGTH
     &    , BETA_SI
!             EARTH CENTRE ANGLE
     &    , RO_SI
!             RADIUS OF EARTH AT LATITUDE
     &    , ANGLEM_SI
!             LUNAR PHASE ANGLE
!
!     LOCAL VARIABLES.
      REAL*8
     &     H1
!             CONVERTED INITIAL HEIGHT
     &   , H2
!             CONVERTED FINAL HEIGHT
     &   , ANGLE
!             CONVERTED ZENITH ANGLE
     &   , RANGE
!             CONVERTED RANGE
     &   , BETA
!             CONVERTED EARTH-CENTRE ANGLE
     &   , RO
!             CONVERTED RADIUS OF EARTH
     &   , ANGLEM
!             CONVERTED LUNAR PHASE ANGLE
!
!
      IF (IEMSCT.NE.3) THEN
!        CONVERSION OF UNITS
         H1=H1_SI*1.0D-03
         H2=H2_SI*1.0D-03
         ANGLE=ANGLE_SI*180.0D+00/PI
         RANGE=RANGE_SI*1.0D-03
         BETA=BETA_SI*180.0D+00/PI
         RO=RO_SI*1.0D-03
!
         WRITE(IU_LOWTRAN, '(6F10.3, I5)')
     &        H1, H2, ANGLE, RANGE, BETA, RO, LEN
      ELSE
!        ALTERNATIVE CARD 3.
         H1=H1_SI*1.0D-03
         H2=H2_SI*1.0D-03
         ANGLE=ANGLE_SI*180.0D+00/PI
         RO=RO_SI*1.0D-03
         ANGLEM=ANGLEM_SI*180.0D+00/PI
         WRITE(IU_LOWTRAN, '(3F10.3, I5, 5X, F10.3, I5, F10.3)')
     &        H1, H2, ANGLE, IDAY, RO, ISOURC, ANGLEM
      ENDIF
!
      RETURN
      END
!
!
!     ****** CARD 3A1 ******
!
      SUBROUTINE WRITE_CARD_3A1(IPARM, IPH, IDAY, ISOURC)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     IPARM
!             CONTROL OF GEOMETRY SPECIFICATION
     &   , IPH
!             AEROSOL PHASE FUNCTION
     &   , IDAY
!             DAY OF YEAR
     &   , ISOURC
!             EXTRATERRESTRIAL SOURCE
!
!
      WRITE(IU_LOWTRAN, '(4I5)')
     &     IPARM, IPH, IDAY, ISOURC
!
      RETURN
      END
!
!
!     ****** CARD 3A2 ******
!
      SUBROUTINE WRITE_CARD_3A2(PARM1, PARM2, PARM3, PARM4
     &   , TIME, PSIPO, ANGLEM, G)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      REAL*8	!, INTENT(IN)
     &     PARM1
!             OBSERVER'S LATITUDE
     &   , PARM2
!             OBSERVER'S LONGITUDE
     &   , PARM3
!             SOURCE LATITUDE
     &   , PARM4
!             SOURCE LONGITUDE
     &   , TIME
!             GREENWICH TIME
     &   , PSIPO
!             PATH AZIMUTH
     &   , ANGLEM
!             LUNAR PHASE ANGLE
     &   , G
!             ASYMMETRY FACTOR
!
!
      WRITE(IU_LOWTRAN, '(8F10.3)')
     &     PARM1, PARM2, PARM3, PARM4, TIME, PSIPO, ANGLEM, G
!
      RETURN
      END
!
!
!     ****** CARD 3B1 ******
!
      SUBROUTINE WRITE_CARD_3B1(NANGLS)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     NANGLS
!             NUMBER OF ANGLES FOR PHASE FUNCTION
!
!
      WRITE(IU_LOWTRAN, '(I5)')
     &     NANGLS
!
      RETURN
      END
!
!
!     ****** CARD 3B2 ******
!
      SUBROUTINE WRITE_CARD_3B2(ANGF_SI, F)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
      INCLUDE 'incl/math_cnst.ccf'
!
!     DUMMY ARGUMENTS
      REAL*8 	!, INTENT(IN)
     &     ANGF_SI
!             SCATTERING ANGLE
     &   , F(4)
!             USER'S PHASE FUNCTION
!
!     LOCAL VARIABLE
      INTEGER
     &     J
!             LOOP VARIABLE
      REAL*8
     &     ANGF
!             CONVERTED ACTTERING ANGLE
!
!
!     CONVERSION OF UNITS.
      ANGF=ANGF_SI*180.0D+00/PI
!
      WRITE(IU_LOWTRAN, '(5E10.3)')
     &     ANGF, (F(J), J=1, 4)
!
      RETURN
      END
!
!
!     ****** CARD 4 ******
!
      SUBROUTINE WRITE_CARD_4(V1_SI, V2_SI, DV_SI)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      REAL*8	!, INTENT(IN)
     &     V1_SI
!             INITIAL WAVENUMBER
     &   , V2_SI
!             FINAL WAVENUMBER
     &   , DV_SI
!             FREQUENCY INCREMENT
!     LOCAL VARIABLES
      REAL*8
     &     V1
!             CONVERTED INITIAL WAVENUMBER
     &   , V2
!             CONVERTED FINAL WAVENUMBER
     &   , DV
!             CONVERTED FREQUENCY INCREMENT
!
!
!     CONVERSION.
      V1=V1_SI/1.0D+02
      V2=V2_SI/1.0D+02
      DV=DV_SI/1.0D+02
!
      WRITE(IU_LOWTRAN, '(3F10.3)')
     &     V1, V2, DV
!
      RETURN
      END
!
!
!     ****** CARD 5 ******
!
      SUBROUTINE WRITE_CARD_5(IPRT)
!
!
      IMPLICIT NONE
!
!
!     DEFINITION OF I/O UNIT NUMBERS
      INCLUDE 'incl/def_lwtrn_io.icf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(IN)
     &     IPRT
!             RECYCLING CONTROL
!
!
      WRITE(IU_LOWTRAN, '(I5)')
     &     IPRT
!
      RETURN
      END
