!=================================================================
!  放射過程計算ルーチン; 初期設定
!
!  1999/05/25  小高正嗣
!  1999/06/07  小高正嗣
!  2000/04/12  小高正嗣; 透過幅配列サイズを変更
!=================================================================

      subroutine RBASIC
     I   ( RGRID, PSFC  , RDZ  , RDZM  ,
     O     OPL  , EMSV  ,
     C     EMSV_REF, OPLLOG_REF,
     C     GRAV , RDRY  ,
     D     NZ   , NZB   , NZR  , NZRB  , NREF, DX  )

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

      parameter ( nzmaxm = 25000 )

      dimension 
     \     RGRID (-2:NZRB), 
     \     RDZ   (-2:NZRB), RDZM  (-2:NZRB),
     \     OPL   (-2:NZRB)

      dimension 
     \     EMSV(0:NZR+1,0:NZR+1)

      dimension 
     \     EMSV_REF(NREF), OPLLOG_REF(NREF)

      dimension
     \     PRES0R(-2:NZRB), TEMP0R(-2:NZRB)

      dimension
     \   ZPROF(0:nzmaxm), TPROF(0:nzmaxm),  PPROF(0:nzmaxm),
     \   DPROF(0:nzmaxm), PPLOG(0:nzmaxm)

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

      NZMAX = nzmaxm
      DZZ = 1.00D1
C
      do IZ = 0, NZMAX
         ZPROF(IZ) = DZZ * IZ
      end do
C
      do IZ = 0, NZMAX
         TPROF(IZ) = TEMPZ( ZPROF(IZ) )
      end do
C
      pprof(0) = psfc
      dprof(0) = psfc / ( rdry * tprof(0) )
      pplog(0) = log(psfc)

      do iz = 1, nzmax
         tmid = ( tprof(iz) + tprof(iz-1) ) / 2.0d0
         pplog(iz) = pplog(iz-1) - grav / rdry / tmid * dzz
         pprof(iz) = exp( pplog(iz) )
         dprof(iz) = pprof(iz)  / ( rdry * tprof(iz) )
      end do

      do IZ = 0, NZR
         IZZ = INT( RGRID(IZ) / DZZ )
         FZZ = ( RGRID(IZ) - DZZ*FLOAT(IZZ) ) / DZZ
         PRES0R(IZ) =   ( 1.0D0 - FZZ ) * PPROF(IZZ  )
     \               +           FZZ   * PPROF(IZZ+1)
         TEMP0R(IZ) = TEMPZ( RGRID(IZ) )
      end do

      call SETOPL
     I   ( PRES0R, PSFC,
     O     OPL, 
     C     GRAV , 
     D     NZR   , NZRB  )

      call CLEMSV
     I   ( OPL , 
     O     EMSV ,
     C     EMSV_REF, OPLLOG_REF,
     D     NZR , NREF)

      return
      end


