# -*- coding: utf-8 -*-
require "numru/ggraph"
include NumRu

t2 = ARGV[0].to_i

file  = 'thermal-moist_PTempAll.nc'
var   = 'PTempAll'

gphys  = GPhys::IO.open( file , var  )
timearray = gphys.coord(3).val

for t in timearray
  if t <= t2 then
#    timestep = t % ( 3600 * 6 ) 
    timestep = t % ( 3600 * 3 )
#    timestep = t % ( 3600 * 1 )
    if timestep == 0 then
    p t
#    p timestep

    system('ruby draw_z_tempmeanx.rb ' + t2.to_s + ' ' + t.to_s )
    system('ruby psfat.rb'  + ' dcl.ps > dclnew.ps' )
    system("convert -rotate 90 dclnew.ps dcl.gif" )
    com = sprintf( "mv dcl.gif zzz-figs/zzzNew2/dcl_Temp_z_1-2-2_z48km_%0#{8}d.gif", t )
#    com = sprintf( "mv dcl.gif zzz-figs/zzzNew2/dcl_Temp_z_1-4-2_z48km_%0#{8}d.gif", t )
    system(com)

    end
  end
end

#system('gifsicle --delay 25 zzz-gifs/zzzNew2/dcl_Temp_z_1-4-2_z48km_* > zzz-figs/zzzNew2/dcl_Temp_z_1-4-2_z48km_anim.gif')

exit

### z = 0-20km ###

for t in timearray
#  timestep = t % ( 3600 * 6 )
  timestep = t % ( 3600 * 3 )
  if timestep == 0 then
  p t
#  p timestep

  system('ruby draw_xz_cloudwatermixingratio_z=0-20km.rb ' + t.to_s )
  system('ruby psfat.rb'  + ' dcl.ps > dclnew.ps' )
  system("convert -rotate 90 dclnew.ps dcl.gif" )
  com = sprintf( "mv dcl.gif zzz-figs/zzzNew/dcl_H2O-l-CloudAll_xz_z=0-20km_1-2_z24km_%0#{8}d.gif", t )
  system(com)

  end
end
