      SUBROUTINE SKYP(nlev,pd,pd8,gtemp)
      implicit real(selected_real_kind(15)) (a-h,o-z)
      dimension q(40),qmh(41),qi(40),pd(200),pd8(200),gtemp(200)
      dimension plm(200)
      DATA Q /
     *     0.9447012E-05, 0.3042544E-04, 0.6876343E-04, 0.1295448E-03,
     *     0.2187045E-03, 0.3446506E-03, 0.5182561E-03, 0.7525096E-03,
     *     0.1065881E-02, 0.1484524E-02, 0.2044372E-02, 0.2791420E-02,
     *     0.3783706E-02, 0.5096454E-02, 0.6827019E-02, 0.9101167E-02,
     *     0.1208109E-01, 0.1597555E-01, 0.2105252E-01, 0.2765502E-01,
     *     0.3622044E-01, 0.4730383E-01, 0.6154377E-01, 0.7960552E-01,
     *     0.1022674E 00, 0.1304765E 00, 0.1652889E 00, 0.2078405E 00,
     *     0.2584953E 00, 0.3166243E 00, 0.3816890E 00, 0.4530773E 00,
     *     0.5297009E 00, 0.6099063E 00, 0.6913949E 00, 0.7711706E 00,
     *     0.8455313E 00, 0.9101312E 00, 0.9601436E 00, 0.9905502E 00/
C
      DATA QMH /
     *     0.0          , 0.1911410E-04, 0.4843058E-04, 0.9763264E-04,
     *     0.1718878E-03, 0.2782727E-03, 0.4268617E-03, 0.6292185E-03,
     *     0.8999584E-03, 0.1262393E-02, 0.1745741E-02, 0.2394086E-02,
     *     0.3254696E-02, 0.4398700E-02, 0.5904891E-02, 0.7893145E-02,
     *     0.1049407E-01, 0.1390813E-01, 0.1835028E-01, 0.2415268E-01,
     *     0.3166522E-01, 0.4143094E-01, 0.5400919E-01, 0.7012945E-01,
     *     0.9036189E-01, 0.1157414E 00, 0.1470876E 00, 0.1857426E 00,
     *     0.2325674E 00, 0.2873136E 00, 0.3489250E 00, 0.4175294E 00,
     *     0.4916515E 00, 0.5706949E 00, 0.6518117E 00, 0.7333819E 00,
     *     0.8109064E 00, 0.8816345E 00, 0.9395488E 00, 0.9811897E 00,
     *     0.1000000E 01/
C  THE GENERAL FORMULAS FOR SKYHI PRESSURES ARE: 
C   FOR THE UPPER SANDWICH-K=1,30(LH)-----
C
C     QI(I,K)=1013250.*Q(K)/PSS(I)
C
C  FOR THE LOWER SANDWICH K=31,40
C
C    QI(I,K)=PC*(1.-Q(K))+PSS(I)*(Q(K)-QMH(31))
C            ---------------------------------
C             PSS(I)*(1.-QMH(31))
C
C    WHERE PC=1013250.*QMH(31),PSS(I)=SFC PRESSURE AT POINT I,
C    AND Q,QMH ARE SPECIFIED LEVELS
C
C    FOR THE CASE PSS=1013250. (STANDARD PRESSURE) BOTH FORMULAS
C     REDUCE TO QI(I,K)=Q(K) FOR ALL K.
      kd=nlev
      kp=kd+1
      lh=30
      km=kd-1
      lhp=lh+1
      kp2=kd+2
      PSS=    1013250.
      DO 1 K=1,LH
      QI(K)=1013250.*Q(K)/PSS
      PD(K+1)=QI(K)*PSS
1     CONTINUE
      DO 2 K=LHP,KD
      QI(K)=(1013250.*QMH(LHP)*(1.-Q(K))+PSS*(Q(K)-QMH(LHP)))/
     1   (PSS*(1.-QMH(LHP)))
      PD(K+1)=QI(K)*PSS
2     CONTINUE
      PD(1)=0.
      PD(KP2)=PSS
      PLM(1)=0.
      DO 3 K=1,KM
      PLM(K+1)=0.5*(PD(K+1)+PD(K+2))
3     CONTINUE
      PLM(KP)=PSS
      DO 4 K=1,KD
      GTEMP(K)=PD(K+1)**0.2*(1.+PD(K+1)/30000.)**0.8/1013250.
4     CONTINUE
      GTEMP(KP)=0.
      WRITE (10,100) (GTEMP(K),K=1,KD)
      WRITE (10,100) (PD(K),K=1,KP2)
      WRITE (10,100) (PLM(K),K=1,KP)
C***TAPES 41,42 ARE OUTPUT TO THE CO2 INTERPOLATION PROGRAM(PS=1013 MB)
C  THE FOLLOWING PUTS P-DATA INTO MB
      DO 11 I=1,KP
      PD(I)=PD(I)*1.0E-3
      PLM(I)=PLM(I)*1.0E-3
11    CONTINUE
      PD(KP2)=PD(KP2)*1.0E-3
      WRITE (41,101) (PD(K),K=1,KP2)
      WRITE (41,101) (PLM(K),K=1,KP)
      WRITE (42,101) (PLM(K),K=1,KP)
C***SECOND PASS: PS=810 MB,GTEMP NOT COMPUTED
      PSS=0.8*1013250.
      DO 201 K=1,LH
      QI(K)=1013250.*Q(K)/PSS
      PD8(K+1)=QI(K)*PSS
201   CONTINUE
      DO 202 K=LHP,KD
      QI(K)=(1013250.*QMH(LHP)*(1.-Q(K))+PSS*(Q(K)-QMH(LHP)))/
     1   (PSS*(1.-QMH(LHP)))
      PD8(K+1)=QI(K)*PSS
202   CONTINUE
      PD8(1)=0.
      PD8(KP2)=PSS
      PLM(1)=0.
      DO 203 K=1,KM
      PLM(K+1)=0.5*(PD8(K+1)+PD8(K+2))
203   CONTINUE
      PLM(KP)=PSS
      WRITE (10,100) (PD8(K),K=1,KP2)
      WRITE (10,100) (PLM(K),K=1,KP)
C***TAPES 43,44 ARE OUTPUT TO THE CO2 INTERPOLATION PROGRAM(PS=810 MB)
C  THE FOLLOWING PUTS P-DATA INTO MB
      DO 211 I=1,KP
      PD8(I)=PD8(I)*1.0E-3
      PLM(I)=PLM(I)*1.0E-3
211   CONTINUE
      PD8(KP2)=PD8(KP2)*1.0E-3
      WRITE (43,101) (PD8(K),K=1,KP2)
      WRITE (43,101) (PLM(K),K=1,KP)
      WRITE (44,101) (PLM(K),K=1,KP)
100   FORMAT (1X,5E20.13)
101   FORMAT (5E16.9)
      RETURN
      END
