#
# dcpam の計算結果もしくは NCEP データの月平均・東西平均分布を描画する ctl スクリプト
#
# * 2011/11/30 タイトル編集
# * 2011/09/22 NCEP のデータも扱えるように編集
#
#

require "numru/ggraph"
include NumRu

data = ARGV[1].to_s

if data == "dcpam"  then

   dir = '..'
   vname = ARGV[0]

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

   iyrs = 3
   iyre = 3

elsif data == "NCEP" then

   dir = '/home2/yukai-home2/NCEP'
   vname = ARGV[0]

   p vname

   gphys = GPhys::NetCDF_IO.open( dir + '/' +  'ulwrftop.mon.mean' + '.nc', 'ulwrf')
   tm = gphys.shape[0] # number of elements for time      dimension

   iyrs = 1988
   iyre = 2007
   
end   

figdir = 'figs_zm_clim_' + vname + '_mon'
Dir::mkdir( figdir )

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_1panel.rb ' + dir + ' ' + vname + ' ' + iyrs.to_s + ' ' + iyre.to_s + ' ' + imon.to_s + ' ' + title + ' ' + data )

#    system("pstoimg -type gif -flip r270 dcl.ps")
    system("pstoimg -type gif dcl.ps")
    com = sprintf( "mv dcl.gif "+figdir+"/dcl_mon%0#{2}d.gif", imon )
    system(com)
    com = sprintf( "mv dcl.ps  "+figdir+"/dcl_mon%0#{2}d.ps" , imon )
    system(com)

end

