bin/gpcut in gphys-1.2.2.1 vs bin/gpcut in gphys-1.4.3

- old
+ new

@@ -16,10 +16,12 @@ :-h, --help print this message. :-m dim, --mean dim average along dim axis (optional). +:-e dim, --eddy dim: + deviation from mean along dim axis (optional). :-o file, --output file output filename (optional). Default output filename is 'gphys.nc'. = HISTORY @@ -29,10 +31,11 @@ 2005/08/10 S Takehiro (utilize internal function for printing help message) 2005/08/21 S Takehiro (global attributes copied to the output file) 2005/08/23 S Takehiro (common methods to gp* command moved to gpcommon.rb) 2010/03/10 Y SASAKI (change help block into RD format) 2012/02/19 S Takehiro (description for gturl format updated) + 2014/04/23 S Takehiro (add --eddy option) =end require "numru/gphys" require "numru/gphys/gpcommon" @@ -45,16 +48,18 @@ URLfmt = "path[@|/]varname[,dimname=pos1[:pos2[:thinning_intv]][,dimname=...]]" #---------------------- Option Configuration ---------------------- parser = GetoptLong.new( ["--mean", "-m", GetoptLong::REQUIRED_ARGUMENT], + ['--eddy', "-e", GetoptLong::REQUIRED_ARGUMENT], ["--output", "-o", GetoptLong::REQUIRED_ARGUMENT], ["--help", "-h", GetoptLong::NO_ARGUMENT ]) begin parser.each{|opt, arg| case opt when "--mean" then eval "$OPT_mean='#{arg}'" + when "--eddy" then eval "$OPT_eddy='#{arg}'" when "--output" then eval "$OPT_output='#{arg}'" when "--help" then eval "$OPT_help=true" else raise "must not happen" end @@ -84,14 +89,25 @@ gturl = ARGV[0] gphys = GPhys::IO.open_gturl(gturl) outncfile.copy_global_att(gphys) # Copy global attributes (only for NetCDF) #----------------------- mean along any axis ------------------------- +## mean along any axis if ($OPT_mean) dims = ($OPT_mean).split(/\s*,\s*/) dims.each{|dim| dim = dim.to_i if dim.to_i.to_s == dim gphys = gphys.mean(dim) + } +end + +## deviation from mean along any axis +if ($OPT_eddy) + dims_eddy = ($OPT_eddy).split(/\s*,\s*/) + dims_eddy = dims_eddy.map{|dim| dim.to_i.to_s == dim ? dim.to_i : dim} + dims_eddy.each{|dim| + dim = dim.to_i if dim.to_i.to_s == dim + gphys = gphys.eddy(dim) } end #---------------------- Output GPhys variable ------------------------