      SUBROUTINE ELAYER(IFLAG,FOE,HE)
C***********************************************************************
C* SUBROUTINE NAME:  ELAYER            CPC:  SS/MOD/RTN/ELAYER         *
C*         VERSION:  90-REF           DATE:  20 DEC 89                 *
C*                                                                     *
C*         PURPOSE:  THIS SUBROUTINE CALCULATES THE FREQUENCY OF THE   *
C*                   ORDINARY RAY AND THE HEIGHT OF THE ELECTRON DEN-  *
C*                   SITY MAXIMUM IN THE E LAYER.                      *
C*                                                                     *
C*         CALLING                                                     *
C*       ARGUMENTS:  IFLAG,FOE,HE                                      *
C*                                                                     *
C*  ABBREVIATIONS:  NONE                                               *
C*                                                                     *
C*  COMMON BLOCKS:  F6PARM                                             *
C*                                                                     *
C* FILES ACCESSED:  NONE                                               *
C*                                                                     *
C*         METHOD:  1.  IF SOLAR,                                      *
C*                    - COMPUTE FREQUENCY AND HEIGHT USING TITHERIDGE  *
C*                      METHOD                                         *
C*                  2.  IF AURORAL,                                    *
C*                    - COMPUTE AURORAL ZONE BOUNDARIES                *
C*                    - COMPUTE LOCATION OF MAX IONIZATION IN AURORAL  *
C*                      ZONE BASED ON Q INDEX AND MAGNETIC LOCAL TIME  *
C*                    - COMPUTE IONIZATION AT EDGES OF AURORAL ZONE    *
C*                    - LINEARLY INTERPOLATE VALUES AT GRIDPOINT       *
C*                  3.  IF SOLAR AND AURORAL,                          *
C*                    - COMBINE SOLAR AND AURORAL CONTRIBUTIONS        *
C*                                                                     *
C*        REMARKS:  NONE                                               *
C*                                                                     *
C*     REFERENCES:  1.  ICED-III SYSTEM DOCUMENTATION                  *
C*                  2.  SPERRY FORTRAN-77(ASCII) PRM                   *
C*                  3.  AFGWC FORM 10 DX-50194                         *
C*                  4.  AFGWC FORM 10 DX-60096                         *
C*                                                                     *
C* COMMON /F6PARM/IYR,IMO,IDA,TIME,DAYJUL,EFFSSN,EFFQ,EFFKP,           *
C*                GGLAT,GGLON,CGLAT,CGLON,TCGM                         *
C*    IYR    IS  YEAR OF DATA SET                                      *
C*    IMO    IS  MONTH OF DATA SET                                     *
C*    IDA    IS  DAY OF DATA SET                                       *
C*    TIME   RS  UNIVERSAL TIME IN HH.HH OF DATA SET                   *
C*    DAYJUL RS  JULIAN DATE OF DATA SET (REAL)                        *
C*    EFFSSN RS  EFFECTIVE SUNSPOT NUMBER                              *
C*    EFFQ   RS  EFFECTIVE AURORAL Q VALUE                             *
C*    EFFKP  RS  EFFECTIVE PLANETARY K INDEX                           *
C*    GGLAT  RS  GEOGRAPHIC LATITUDE OF A GRIDPOINT                    *
C*    GGLON  RS  GEOGRAPHIC LONGITUDE OF A GRIDPOINT                   *
C*    CGLAT  RS  CORRECTED GEOMAGNETIC LATITUDE OF A GRIDPOINT         *
C*    CGLON  RS  CORRECTED GEOMAGNETIC LONGITUDE OF A GRIDPOINT        *
C*    TCGM   RS  CORRECTED GEOMAGNETIC TIME OF A GRIDPOINT             *
C*                                                                     *
C*LOCAL VARIABLES:  IFLAG  - IS - FLAG QUALIFIER USED TO SELECT THE    *
C*                                PROCESSING ALGORITHM                 *
C*                  CGEQAT - RS - AURORAL ZONE EQUATORIAL CG LATITUDE  *
C*                  CGMIDL - RS - AURORAL ZONE MID POINT  CG LATITUDE  *
C*                  CGOVAL - RS - AURORAL ZONE AVERAGE LOCATION        *
C*                  CGPOLR - RS - AURORAL ZONE POLEWARD BOUNDARY       *
C*                  DR     - RS - DEG-RADIAN CONVERSION CONSTANT       *
C*                  DUM    - RS - PLACEHOLDER IN CALL TO SOLPOS        *
C*                  FLUX   - RS - 10.7 CM SOLAR RADIO FLUX (FROM SSN)  *
C*                  FOE    - RS - E LAYER FREQUENCY                    *
C*                  FOE1   - RS - E LAYER FREQUENCY (SOLAR PRODUCED)   *
C*                  FOE2   - RS - E LAYER FREQUENCY (AURORAL PRODUCED) *
C*                  FOEA   - RS - FREQUENCY AT POINT OF MAX IONIZATION *
C*                                IN AURORAL ZONE                      *
C*                  FOEAMN - RS - MINIMUM IONIZATION IN AURORAL ZONE   *
C*                  FOEE   - RS - FREQUENCY AT EQUATORWARD EDGE OF AZ  *
C*                  FOEP   - RS - FREQUENCY AT POLEWARD EDGE OF AZ     *
C*                  HE     - RS - E LAYER HEIGHT                       *
C*                  HE1    - RS - E LAYER HEIGHT (SOLAR PRODUCED)      *
C*                  HE2    - RS - E LAYER HEIGHT (AURORAL PRODUCED)    *
C*                  SLOPEE - RS - SLOPE OF EQUATORIAL SIDE OF E LAYER  *
C*                  SLOPEP - RS - SLOPE OF POLAR SIDE OF E LAYER       *
C*                  TIMLOC - RS - LOCAL TIME AT GGLON                  *
C* (I=INTEGER, R=REAL, C=CHARACTER, S=SCALAR, V=VECTOR, A=ARRAY)       *
C*                                                                     *
C*   SETC OPTIONS:  NONE USED                                          *
C*                                                                     *
C*     SUBPROGRAMS                                                     *
C*         CALLED:  QOVAL1 - COMPUTES AURORAL OVAL POSITION            *
C*                                                                     *
C*     SUBPROGRAM                                                      *
C*      CALLED BY:  FIELD6                                             *
C*                                                                     *
C*PROGRAM WRITTEN:  JAN 86 - NATIONAL GEOPHYSICAL DATA CENTER          *
C*        UPDATES:  JUN 86 - AFGWC/SDDE - UPDATED DOCUMENTATION        *
C*                  AUG 87 - NATIONAL GEOPHYSICAL DATA CENTER (87-I)   *
C*                  MAR 88 - NGDC (88-II) CCIR SOLAR E LAYER           *
C*                  DEC 89 - NGDC (89-??) TITHERIDGE E ALGORITHMS      *
C*                                                                     *
C***********************************************************************
      INTEGER IDA
      INTEGER IMO
      INTEGER IYR
      REAL CGLAT
      REAL CGLON
      REAL DAYJUL
      REAL EFFKP
      REAL EFFQ
      REAL EFFSSN
      REAL GGLAT
      REAL GGLON
      REAL TCGM
      REAL TIME
      COMMON/F6PARM/IYR,IMO,IDA,TIME,DAYJUL,EFFSSN,EFFQ,EFFKP,
     +            GGLAT,GGLON,CGLAT,CGLON,TCGM
      INTEGER IFLAG
      REAL CGEQAT
      REAL CGMIDL
      REAL CGOVAL
      REAL CGPOLR
      REAL CHI
      REAL DR
      REAL DUM
      REAL FLUX
      REAL FOE
      REAL FOE1
      REAL FOE2
      REAL FOEA
      REAL FOEAMN
      REAL FOEE
      REAL FOEP
      REAL HE
      REAL HE1
      REAL HE2
      REAL SLOPEE
      REAL SLOPEP
      REAL TIMLOC
      DATA DR/0.0174532/
 
C......................................................................
C......................................................................
C     POLAR CAP GRIDPOINT - USE DEFAULT                               .
C......................................................................
C......................................................................
      IF ( IFLAG.EQ.9 ) THEN
        FOE = 0.6
        HE = 120.0
        RETURN
      ENDIF
 
C......................................................................
C......................................................................
C     SOLAR E-LAYER COMPUTED FROM TITHERIDGE ALGORITHMS               .
C     IFLAG = 0 IMPLIES LOW/MID LAT NIGHTTIME                         .
C     IFLAG = 4 IMPLIES LOW/MID LAT SUNRISE/SUNSET POINT              .
C     IFLAG = 6 IMPLIES LOW/MID LAT DAYTIME POINT                     .
C     IFLAG = 7 IMPLIES AURORAL ZONE DAYTIME POINT                    .
C......................................................................
C......................................................................
      IF ( (IFLAG.EQ.0).OR.(IFLAG.EQ.4).OR.(IFLAG.EQ.6).OR.
     +     (IFLAG.EQ.7) ) THEN
 
C......................................................................
C       COMPUTE 10.7 CM FLUX                                          .
C......................................................................
        FLUX = 63.7 + 0.728*EFFSSN + 0.00089 * EFFSSN**2
 
C......................................................................
C       CALCULATE THE CHI ANGLE (ANGLE BETWEEN ZENITH AND SUN)        .
C......................................................................
        TIMLOC = TIME + GGLON/15.0
        IF ( TIMLOC.GE.24.00 ) TIMLOC = TIMLOC - 24.00
        IF ( TIMLOC.LT. 0.00 ) TIMLOC = TIMLOC + 24.00
        CALL SOLPOS( IYR,IMO,IDA,TIMLOC,GGLAT,GGLON,CHI,DUM,DUM,DUM )
 
C.....................................................................
C       TITHERIDGE FORMULA FOR FOE                                   .
C       (HAD TO ADD TO FORMULA :   ABS(COS..)                        .
C.....................................................................
        IF ( ABS(CHI).LT.90 ) THEN
          FOE1 = 1.12 * (FLUX**0.25) * (ABS(COS(CHI*DR))**0.30)
          IF ( FOE1.LT.0.6 ) FOE1 = 0.6
        ELSE
          FOE1 = 0.6
        ENDIF
 
C.....................................................................
C       TITHERIDGE FORMULA FOR HME                                   .
C       UPPER LIMIT SET TO 120 KM FOR LARGE ZENITH ANGLES            .
C.....................................................................
        IF ( CHI.GE.77.10 ) THEN
          HE1 = 120.0
        ELSE
          HE1 = 108.0 + 8.0 * LOG( 1.0/COS(CHI*DR) )
        ENDIF
 
      ENDIF
 
C......................................................................
C......................................................................
C     AURORAL E-LAYER                                                 .
C......................................................................
C......................................................................
      IF ( (IFLAG.EQ.1).OR.(IFLAG.EQ.5).OR.(IFLAG.EQ.7) ) THEN
 
C......................................................................
C       AURORAL ZONE BOUNDARIES                                       .
C......................................................................
        CALL QOVAL1(EFFQ,TCGM,CGPOLR,CGMIDL,CGEQAT)
 
C......................................................................
C       FOEA IS MAX IONIZATION  (GASSMAN AND VONDRAK ET AL. 1977)     .
C......................................................................
        FOEA = 1.21*EFFQ - 0.356
        IF(EFFQ.GT.4.2) FOEA = 3.2 + (0.4*EFFQ)
        IF(EFFQ.LE.2.7) FOEA = 2.5 + (EFFQ/9.)
C......................................................................
C       MODIFY FOEA FOR MAGNETIC LOCAL TIME VARIATIONS (MAX IONIZATION.
C       AT 03 MLT, MINIMUM IONIZATION AT 15 MLT)                      .
C......................................................................
        FOEAMN = 1.0
        IF ( TCGM.LE.15.0 ) THEN
          FOEA = FOEA - (ABS(TCGM-3)/12.0) * (FOEA-FOEAMN)
        ELSE
          FOEA = FOEA - ((27-TCGM)/12.0) * (FOEA-FOEAMN)
        ENDIF
 
C.......................................................................
C       CGOVAL = LOCATION OF MAX IONIZATION                            .
C.......................................................................
        CGOVAL = CGMIDL
        IF ( EFFQ.GT.3.0 ) THEN
          IF ( (TCGM.GT.00.0).AND.(TCGM.LE.06.0) )
     +      CGOVAL = CGMIDL + (-2.0*SIN(30.0*TCGM*DR))*(EFFQ/4.0)
          IF ( (TCGM.GE.21.0).AND.(TCGM.LT.24.0) )
     +      CGOVAL = CGMIDL + SIN( (TCGM-21.0)*60.0*DR )
        ENDIF
 
C.......................................................................
C       COMPUTE FOE RELATIVE TO POSITION OF MAX IONIZATION             .
C.......................................................................
        IF ( CGLAT.LE.CGOVAL ) THEN
          FOEE=.6*FOEA
          SLOPEE = (FOEA-FOEE)/(CGOVAL-CGEQAT)
          FOE2 = FOEA + SLOPEE*(CGLAT-CGOVAL)
        ELSE
          FOEP=.6*FOEA
          SLOPEP = (FOEA-FOEP)/(CGOVAL-CGPOLR)
          FOE2 = FOEA + SLOPEP*(CGLAT-CGOVAL)
        ENDIF
C......................................................................
C       AURORAL HME ALGORITHM DERIVED FROM VONDRACK ET AL 1977        .
C......................................................................
        IF ( FOE2.LE.1.0 ) HE2 = 130.0
        IF ( (FOE2.GT.1.0).AND.(FOE2.LT.7.0) )
     +    HE2 = 130.0 - ( (FOE2-1.0)/(7.0-1.0) ) * (130.0-90.0)
        IF ( FOE2.GE.7.0 ) HE2 = 90.0
      ENDIF
 
C......................................................................
C     COMBINE SOLAR AND AURORAL CONTRIBUTIONS IF APPROPRIATE          .
C......................................................................
      IF ( (IFLAG.EQ.0).OR.(IFLAG.EQ.4).OR.(IFLAG.EQ.6) ) THEN
        FOE = FOE1
        HE = HE1
      ENDIF
      IF ( (IFLAG.EQ.1).OR.(IFLAG.EQ.5) ) THEN
        FOE = FOE2
        HE = HE2
      ENDIF
      IF ( IFLAG.EQ.7 ) THEN
        IF ( ABS(HE1-HE2).LE.10.0 ) THEN
          FOE = ( (FOE1**4) + 1.5*(FOE2**4) ) ** 0.25
          HE = (HE1+HE2) / 2.0
        ELSE
          IF ( FOE1/FOE2.LT.1.1 ) THEN
            FOE = FOE2
            HE = HE2
          ELSE
            FOE = FOE1
            HE = HE1
          ENDIF
        ENDIF
      ENDIF
 
      RETURN
      END
 
