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

!-----------------------------------------------------------------      
      implicit real*8 ( a-h,o-z )
!-----------------------------------------------------------------      
#include "grid_size_M.f"
!-----------------------------------------------------------------      
      parameter ( NZP = 40 )

      dimension
     \   TEMP0(-2:NZB), TPOT0(-2:NZB),
     \   CDTURB(-2:NZB)

      real*4
     \   ZGRID_p(0:NZP),
     \   QVAL1_p(0:NZP), 
     \   QVAL2_p(0:NZP), 

      real*4
     \   ZMIN , ZMAX ,
     \   Q1MAX, Q1MIN,
     \   Q2MAX, Q2MIN,

      character*13 header
      character*2 ltime day

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

      open(10,'exparam)
      read(10,*) IRUN
      read(10,*) TIME0, NLOOP1, NLOOP2, DTIME

      write(day,'(I2.2)') irun

      call FOPEN ( irun+1 )

      write(header,'(I5.5)') INT( TIME/3600.0 )

      do IZ = -2, NZB
         WRITE(16,*) IZ, ZGRID(IZ), TEMP0(IZ), CDTURB(IZ)
      end do

      do iz = 0, nzp
         ZGRID_p(iz)= real( ZGRID(iz) )/ 1000.0
      end do

      ZMIN    = ZGRID_p(0)
      ZMAX    = ZGRID_p(NZP)

      write(6,*) 'data number = ', nloop1
      write(6,*) 'INPUT DATA BEGINING, END, & INTERVAL' 
      write(6,*) 'itb ite interval ?'
      read (*,*) itb, ite, interv

      CALL sgpwsn
      read(*,*) iws
      CALL gropn(iws)
      CALL sglset( 'LCORNER', .FALSE. )

      CALL grfrm
      CALL grswnd( 180.0, 300.0, ZMIN, ZMAX )   
      CALL grsvpt( 0.2, 0.8, 0.2, 0.8)                     
      CALL grstrn( 1 )
      CALL grstrf
      CALL ussttl( 'Ptemp', '[]', '', 'Z[km]' )
      CALL usdaxs
      CALL uxsttl( 'T', header, 1. )      

      do it = 1, ite

         read(32) TIME, ( TPOT0 (IZ), IZ=-2,NZB )
         write(0,*) 'reading time = ', time

         if ( it .ge. itb   .and.  it .le. ite ) then
            if ( mod( (it-itb), interv ) .eq. 0 ) then

               write(0,*) 'writing time = ', time
         
c*** 時刻変換: 秒から LT へ************************************
               time = time - 86400.* ( irun -1 )
               time = time / 3600. + 6
c**************************************************************

               write(timel,'(I2.2)') INT(time)
               header = 'day' // day // ' LT=' // timel // ':00'
    
               do iz = 0, NZ
                  QVAL1_p(iz) = real( TPOT0(iz) )
               end do

               Q1MIN    = QVAL1_p(0)

               do iz = 0, NZP
                  Q1MAX    = MAX( Q1MAX, QVAL1_p(iz) )
                  Q1MIN    = MIN( Q1MIN, QVAL1_p(iz) )
               end do

               CALL uuslni( 2 )
               CALL uulin( NZP+1, QVAL1_p, ZGRID_p )

            end if
         end if

      end do

      CALL grcls                                                        


      stop
      end

