      SUBROUTINE STMCAL(STAMAT,STAINV,AL1,BL1,S,SH,SF,DEL,RGOCP,ILEV) 
C 
C     * FEB 28/83 - R.LAPRISE.
C     *****   NOV 1975  - JOHN HENDERSON, ROGER DALEY   ***** 
C     * CALCULATES THE DRY CONVECTIVE STABILITY MATRIX STAMAT AND THE 
C     *  INVERSE STAINV. THE FIRST (ILEV-1) ROWS OF THE MATRIX ARE
C     * USED TO CALCULATE THE (ILEV-1) STATIC STABILITIES FROM
C     * THE ILEV TEMPERATURES. THIS GENERALLY RESULTS IN A
C     * TRI-DIAGONAL SYSTEM WITH MODIFICATIONS AT THE TOP AND BOTTOM. 
C     * THE LAST ROW OF THE MATRIX CONTAINS ELEMENTS WHICH WHEN 
C     * MULTIPLIED BY THE COLUMN VECTOR OF TEMPERATURE YIELDS 
C     * THE POTENTIAL ENERGY. 
C 
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      DIMENSION S(ILEV),SH(ILEV),SF(ILEV),DEL(ILEV) 
      DIMENSION STAMAT(ILEV,1),STAINV(ILEV,1) 
C-----------------------------------------------------------------------
      ILEVM = ILEV-1
C 
      DO 10 J=1,ILEV
      DO 10 I=1,ILEV
   10 STAMAT(I,J) = 0.E0
      STAMAT(1,1)=(RGOCP+SF(2)*(BL1-1.E0)/((SF(1)+SF(2))*SF(1)) 
     1 +AL1/SF(1))/SH(1)
      STAMAT(2,1) = (BL1-1.E0)/((SF(1)+SF(2))*SH(1))
C 
      DO 20 J=2,ILEVM 
      JP = J+1
      JM=J-1
      A = 1.E0/(SH(J)*(SF(JP)+SF(JM)+SF(J)))
      B = (SF(J) + 2.E0*SF(JP))/(SF(JM) + SF(J))
      C = (SF(J) + 2.E0*SF(JM))/(SF(JP) + SF(J))
      STAMAT(JM,J)=+A*B 
      STAMAT(JP,J)=-A*C 
      STAMAT(J ,J)= RGOCP/SH(J)-STAMAT(JM,J)-STAMAT(JP,J) 
   20 CONTINUE
      STAMAT(1,ILEV) = S(1)*(AL1 + BL1*SF(2)/(SF(1)+SF(2))) + DEL(1)
      STAMAT(2,ILEV) = S(1)*BL1*SF(1)/(SF(2)+SF(1)) + DEL(2)
C 
      DO 30 I=3,ILEV
   30 STAMAT(I,ILEV) = DEL(I) 
C 
      RETURN
      END
