#
# usage: draw_ctl5.rb を実行する.
#
# * 2011/12/20 eps ファイルを作成するように追記
# * 2011/09/30 drawzm_clim_1panel_ctl.rb をもとに作成. 重ね書き出来るように編集
#
#

require "numru/ggraph"
include NumRu

   dirD = '..'
   vnameD = ARGV[0]

   #gphysD = GPhys::NetCDF_IO.open( dirD + '/' + 'Ps' + '.nc', 'Ps' )
   #tmD = gphysD.shape[2] # number of elements for time      dimension

   iyrsD = 3
   iyreD = 3


   dirN = '/home2/yukai-home2/NCEP'
   vnameN = ARGV[1]

   #gphysN = GPhys::NetCDF_IO.open( dirN + '/' + vnameN + '.mon.mean' + '.nc', vnameN)
   #tmN = gphysN.shape[0] # number of elements for time      dimension

   iyrsN = 1988
   iyreN = 2007
   
 
figdir = 'figs_zm_clim_' + vnameD + '_wplot' + '_mon'
Dir::mkdir( figdir )
Dir::mkdir( figdir+"/eps" )

p vnameD

for imon in 1..12

    p 'Month: ' + imon.to_s

    case imon
    when 1
      title = 'JAN.'
    when 2
      title = 'FEB.'
    when 3
      title = 'MAR.'
    when 4
      title = 'APR.'
    when 5
      title = 'MAY'
    when 6
      title = 'JUN.'
    when 7
      title = 'JUL.'
    when 8
      title = 'AUG'
    when 9
      title = 'SEP.'
    when 10
      title = 'OCT.'
    when 11
      title = 'NOV.'
    when 12
      title = 'DEC.'
    end

    system('ruby drawzm_clim_wplot.rb ' + dirD + ' ' + dirN + ' ' + vnameD + ' ' + vnameN + ' ' + iyrsD.to_s + ' ' + iyreD.to_s + ' ' + iyrsN.to_s + ' ' + iyreN.to_s + ' ' + imon.to_s + ' ' + title )

    
# gif ファイルの作成

    com = sprintf( "convert -rotate 90 dcl.ps dcl_mon%0#{2}d.gif" , imon )
    system(com)

# eps ファイルの作成 

    com = sprintf( "convert -rotate 90 dcl.ps dcl_mon%0#{2}d.eps" , imon )
    system(com)

    if imon == 12 then

       com = sprintf( "gifsicle *gif --loopcount=20 >"+vnameD+"_zm_wplot_mon.gif" )
       system(com)

       com = sprintf( "mv *.gif "+figdir )
       system(com)

       com = sprintf( "mv *.eps "+figdir+"/eps/" )
       system(com)

    end

end

