!=================================================================
!  一次元 CO2 大気放射対流平衡計算プログラム; 
!  等価幅の計算(Pollack et al., 1981:J. Atmos. Sci., 38, 3--29.)
!
!  1999/06/04  小高正嗣
!=================================================================

      subroutine CLEQWD
     I   ( TEMP0 , PRES0, OPL , 
     I     ZGRID , FDZ  , FDZM, DX, 
     O     EQWDTH,
     D     NZ  , NZB      )

!-----------------------------------------------------------------      
      implicit real*8 ( a-h,o-z )
!-----------------------------------------------------------------      

      dimension
     \   TEMP0(-2:NZB), PRES0(-2:NZB), OPL(-2:NZB), 
     \   ZGRID(-2:NZB), FDZ(-2:NZB)  , FDZM(-2:NZB)

      dimension 
     \   EQWDTH(0:NZ,0:NZ)

      parameter ( EPSILON = 1.0D-15 )
      parameter ( TREF    = 200.0D0 )

!-----------------------------------------------------------------      

      P0MINF = 350.0D0

      do iz = 0, NZ
         EQWDTH(iz,iz)=0.0D0
      end do
      
      do iz = 1, NZ-1

         do jz = 0, iz-1

            T0MEAN = 0.0D0
            P0MEAN = 0.0D0

            ZLENG  = ( ZGRID( iz ) - FDZ( iz )* DX /2.0D0 ) -
     \               ( ZGRID( jz ) - FDZ( jz )* DX /2.0D0 ) 
            
            do kz = jz, iz - 1
               T0MEAN = T0MEAN + 
     \              TEMP0( kz ) * FDZ( kz ) * DX / MAX(ZLENG,EPSILON)
               P0MEAN = P0MEAN + 
     \              PRES0( kz ) * FDZ( kz ) * DX / MAX(ZLENG,EPSILON)
            end do
            
c            P0MEAN = MAX( P0MEAN, P0MINF )

            EQWDTH(iz,jz) = 54.4D0 * ( T0MEAN / TREF )**(0.879D0) *
     \           LOG( 1.0D0 + 0.153D0 * ( T0MEAN / TREF )**(-0.256D0) *
     \                ( ABS ( OPL( jz ) - OPL( iz ) ) )**(0.566D0) *
     \                P0MEAN**(0.323D0) )

         end do
      end do

      do iz = 0, NZ-1
         EQWDTH(NZ,iz) = EQWDTH(NZ-1,iz)
      end do

      do iz = 0, NZ
         do jz = iz+1, NZ
            EQWDTH(iz, jz) = EQWDTH(jz, iz)
         end do
      end do

      return

      end
