#!/usr/bin/env ruby
# ----------------------------------------------
# local load path

$local_path = '/home/yukiko/work/ape/yukiko/lib'
$: << $local_path

# ----------------------------------------------
# 必要なライブラリ, モジュールの読み込み

load "#{$local_path}/ape-view.rb"

# ----------------------------------------------

END{

  host = "eva01"
  a = Ape_mkfig.new 3
  set_dir_id  = "aguforape"
  
  $cumulus = "eml"
  $rezol = "T39L48_eml"
  $expID = "control"
  set_dir(set_dir_id,host)
  a.nc_sh_zonal_comparing_t639_rezol
  
}


class Ape_mkfig

  def nc_sh_zonal_comparing_t639_rezol
    $file_label = "eml_control"

    rezol = ["T39L48_eml", "T39L24_eml", "T39L96_eml", "T79L48_eml", "T159L48_eml","T319L48_eml"]
    
    # total_precipitation_flux
    gphys_ary = []
    rezol.each{ |rezol_item|
      $rezol = rezol_item
      $ncfile_path = "/home/yukiko/work/ape/NetCDF/#{$rezol}/"
      @data = Ape.new("#{$ncfile_path}AGUforAPE-03a_SH_control.nc")
      g1 = @data.gphys_open("sh_cppn")
      g2 = @data.gphys_open("sh_dppn")
      gphys = (g1 + g2).rename("sh_tppn_zonal").
        set_att("ape_name", "total_precipitation_flux")
      gphys_ary.push(gphys.mean(0).
                       set_att("line_name",$rezol) )
    }

    file_name = "/home/yukiko/work/ape/GrADS/T639L24_eml_expID01/APE_T639L24_eml_expID01_cr_eft0.1d_6-16d_PRCP.nc"
    @data = Ape.new(file_name)
    gphys = @data.go("PRCP")          

    gphys_tmp = gphys[0,true,0].copy

    960.times{ |num|
      print "#{num}\n"
      gphys_tmp[num] = gphys[true,num,true].mean(0).mean(0).val
    }

#    rename("sh_tppn_zonal").
#      set_att("ape_name", "total_precipitation_flux")
    gphys_ary.push(gphys_tmp.
                     set_att("line_name","T639L24_eml") )

    mkfig_plot(gphys_ary)
  end
  
end




