# 月平均した降水量の緯度経度分布を描画する ctl ファイル
#
# * 2011/11/28 drawxy_clim_mon_ctl.rb を基に作成

require "numru/ggraph"
include NumRu

# dcpam データ用

   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


# NCEP データ用

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

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

   iyrsN = 1988
   iyreN = 2007
   
# 両方のデータ共通. 

figdir = 'figs_xy_' + vnameD + '_wplot' + '_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 drawxy_prate_wplot.rb ' + dirD + ' ' + dirN + ' ' + vnameD + ' ' + vnameN + ' ' + iyrsD.to_s + ' ' + iyreD.to_s + ' ' + iyrsN.to_s + ' ' + iyreN.to_s + ' ' + imon.to_s + ' ' + title )

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

    if imon == 12 then

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

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

    end
end
