      SUBROUTINE PHIETA (PHI, T,PSMBLN, AFT,BFT,AHT,BHT, 
     1                   RGASM, LEN,NSL,NSL1, SIGFT,SIGHT,DLNSIGFT) 
  
C     * JUL 27/94 - J. KOSHYK

C     * COMPUTE PHI FROM T ON MODEL THERMOD. HALF LEVELS.
C     * PHI AND T MAY BE EQUIVALENCED IN THE CALLING PROGRAM. 
C     * AFT AND BFT CONTAIN INFORMATION FOR MODEL THERMOD. FULL LEVELS.
C     * AHT AND BHT CONTAIN INFORMATION FOR MODEL THERMOD. HALF LEVELS.
C     * PHIS, THE SURFACE GEOPOTENTIAL, MUST BE IN PHI( ,NSL+1) 
C     * PSMBLN IS LN(PS), FOR PS IN MB. 
C     * NSLP = NSL + 1. 
  
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      REAL PHI(LEN,NSL),T(LEN,NSL),RGASM(LEN,NSL),PSMBLN(LEN) 
  
      REAL AFT(NSL1),BFT(NSL1),AHT(NSL),BHT(NSL)
      REAL SIGFT(NSL1),SIGHT(NSL),DLNSIGFT(NSL) 

C---------------------------------------------------------------------------------
  
      DO 500 N=1,LEN
  
         CALL NIVCAL (SIGFT, AFT,BFT,100.E0*EXP(PSMBLN(N)),NSL1,1,1) 
         DO 200 L=1,NSL 
            DLNSIGFT(L)=LOG(SIGFT(L+1)/SIGFT(L))
  200    CONTINUE 
 
C        * COMPUTE PHI ON MODEL THERMOD. FULL LEVELS (LAYER INTERFACES).

         DO 300 L=NSL,1,-1
            PHI(N,L)=PHI(N,L+1) + RGASM(N,L)*T(N,L)*DLNSIGFT(L) 
  300    CONTINUE 

         CALL NIVCAL (SIGHT, AHT,BHT,100.E0*EXP(PSMBLN(N)),NSL,1,1) 

C        * COMPUTE PHI ON MODEL THERMOD. HALF LEVELS.

         DO 400 L=1,NSL
            PHI(N,L)=PHI(N,L+1)
     1               + RGASM(N,L)*T(N,L)*LOG(SIGFT(L+1)/SIGHT(L))
  400    CONTINUE

  500 CONTINUE

      RETURN
      END 
