!=================================================================
!  一次元 CO2 大気放射対流平衡計算プログラム; 
!  DCL による描画
!
!  1999/05/31  小高正嗣
!  1999/06/04  小高正嗣
!=================================================================

      subroutine dclfig
     I   ( ZGRID , TEMP0 , PRES0 , OPL   ,
     I     FXRADU, FXRADD, FXRADN, FXCONV,
     I     QRAD  ,
     D     NZ    , NZB                     )

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

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

      dimension 
     \   FXRADU(-2:NZB), FXRADD(-2:NZB), FXRADN(-2:NZB),
     \   FXCONV(-2:NZB), OPL(-2:NZB)   , QRAD(-2:NZB)

      real*4
     \   PRES0_p(0:NZ) , TEMP0_p(0:NZ) , ZGRID_p(0:NZ),     
     \   FXRADU_p(0:NZ), FXRADD_p(0:NZ), FXRADN_p(0:NZ),
     \   FXCONV_p(0:NZ), OPL_p(0:NZ)   , QRAD_p(0:NZ)

      real*4
     \   FXRDMAX, OPL_b, OPL_t  , ZMIN, ZMAX,
     \   TMAX   , TMIN , FNETMAX, QMAX, QMIN

      real*4
     \   TEMP0_ref(0:NZ)
!-----------------------------------------------------------------      

      call setcst
     O   ( GRAV, PSD, AMDRY, RDRY, CPDRY, RMVAP, ALATNT )

      do iz = 0, NZ
         PRES0_p(iz) = real( PRES0(iz) )
         TEMP0_p(iz) = real( TEMP0(iz) )
         ZGRID_p(iz) = real( ZGRID(iz) )/ 1000.0
         FXRADU_p(iz)= real( FXRADU(iz) )
         FXRADD_p(iz)= real( FXRADD(iz) )
         FXRADN_p(iz)= real( FXRADN(iz) )
         FXCONV_p(iz)= real( FXCONV(iz) )
         OPL_p(iz)   = real( OPL(iz) )
         QRAD_p(iz)  = real( QRAD(iz) ) * 86400.0D0
      end do

      OPL_b   = OPL_p(0)
      OPL_t   = OPL_p(NZ)
      ZMIN    = ZGRID_p(0)
      ZMAX    = ZGRID_p(NZ)
c      ZMAX    = 10.0D0
      TMIN    = TEMP0_P(NZ)
      TMAX    = TEMP0_P(0)

      FXRDMAX = FXRADU_p(0)
      FNETMAX = FXRADN_p(0)
      QMAX    = QRAD_p(0)
      QMIN    = QRAD_p(0)

      do iz = 0, NZ
         FNETMAX = MAX( FXRADN_p(iz), FNETMAX ) 
         FXRDMAX = MAX( FXRADU_p(iz), FXRDMAX ) 
         QMAX    = MAX( QMAX, QRAD_p(iz) )
         QMIN    = MIN( QMIN, QRAD_p(iz) )

      end do

      CALL swiset('IWIDTH', 700)                                        
      CALL swiset('IHEIGHT', 600)                                       
      CALL sglset('LCORNER', .FALSE.)                                   
      WRITE(*, *) 'WORKSTATION ID (I) ?;'                               
      CALL sgpwsn                                                       
      READ(*, *) iws                                                    
      CALL gropn(iws)                                                   
C      CALL sldiv('Y', 2, 1)
      CALL sldiv('Y', 2, 2)
      
      CALL grfrm                                                        
      CALL grswnd( TMIN , TMAX + 20., ZMIN, ZMAX )   
c      CALL grswnd( TMIN , TMAX + 20., OPL_b, OPL_t )   
      CALL grsvpt( 0.2, 0.8, 0.2, 0.8)                     
      CALL grstrn( 1 )
      CALL grstrf
      call ussttl( 'Temp.', '[K]', '', 'Z[km]' )
      CALL usdaxs
      CALL uuslni( 2 )
      CALL uulin( NZ+1, TEMP0_p, ZGRID_p )
c      CALL uuslni( 1 )
c      CALL uulin( 101, TEMP0_ref, ZGRID_p )
cc      CALL uulin( NZ+1, TEMP0_p, OPL_p )

      CALL grfrm                                                        
      CALL grswnd( 0., FNETMAX +10., ZMIN, ZMAX )   
cc      CALL grswnd( 0., FXRDMAX + 100., OPL_b, OPL_t )   
      CALL grsvpt( 0.2, 0.8, 0.2, 0.8)                     
      CALL grstrn( 1 )
      CALL grstrf
      call ussttl( 'netflux', '[W/m^2]', '', 'Z[km]' )
cc      call ussttl( 'netflux', '[W/m^2]', 'optical depth', '' )
      CALL usdaxs
      CALL uuslni( 2 )
      CALL uulin( NZ+1, FXRADN_p, ZGRID_p )
cc      CALL uulin( NZ+1, FXRADN_p, OPL_p )

      CALL grfrm                                                        
      CALL grswnd( 0., FXRDMAX +100., ZMIN, ZMAX )   
cc      CALL grswnd( 0., FXRDMAX +100., OPL_b, OPL_t )   
      CALL grsvpt( 0.2, 0.8, 0.2, 0.8 )                     
      CALL grstrn( 1 )
      CALL grstrf
      call ussttl( 'flux', '[W/m^2]', '', 'Z[km]' )
cc      call ussttl( 'netflux', '[W/m^2]', 'optical depth', '' )
      CALL usdaxs
      CALL uulin( NZ+1, FXRADU_p, ZGRID_p )
cc      CALL uulin( NZ+1, FXRADU_p, OPL_p )
      CALL uulin( NZ+1, FXRADD_p, ZGRID_p )
cc      CALL uulin( NZ+1, FXRADD_p, OPL_p )
      
      CALL grfrm
      CALL grswnd( QMIN, QMAX, ZMIN, ZMAX )   
c      CALL grswnd( QMIN, QMAX,  OPL_b, OPL_t )   
      CALL grsvpt( 0.2, 0.8, 0.2, 0.8 )
      CALL grstrn( 1 )
      CALL grstrf
      call ussttl( 'Qrad', '[K/day]', '', 'Z[km]' )
c      call ussttl( 'Qrad', '[K/day]', 'optical dept', '' )
      CALL usdaxs
      CALL uulin( NZ+1, QRAD_p, ZGRID_p )
cc      CALL uulin( NZ+1, FXRADD_p, OPL_p )
      
      
      CALL grcls                                                        

      return

      end

