bin/gpcat in gphys-1.2.2.1 vs bin/gpcat in gphys-1.4.3
- old
+ new
@@ -19,10 +19,16 @@
print this message.
:-v var, --variable var
variable name (required).
:-s sfmt, --slice sfmt
slice,thinnng (optional).
+:-m axis --mean axis
+ mean along axis (optional)
+:-d axis --stddev axis
+ stddev along axis (optional)
+:-e axis --eddy axis
+ eddy along axis (optional)
:-o file, --output file
output filename (optional). Default output filename is 'gphys.nc'.
= HISTORY
@@ -30,20 +36,21 @@
2005/05/17 S Takehiro (created)
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)
+ 2014/03/10 S Takehiro (big fix for ruby 1.9)
+ 2015/02/03 S Takehiro (option --mean, --stddev, --eddy added)
=end
require "numru/gphys"
require "numru/gphys/gpcommon"
include NumRu
require "getoptlong"
-
#-------------------- Slice parameter analysis --------------------
def parse_slice(arg_slice)
slice = Hash.new
thinning = Hash.new
@@ -54,11 +61,11 @@
dimname = $1
subset = $2
case subset
when /(.*):(.*):(.*)/
slice[dimname] = ($1.to_f)..($2.to_f)
- thinning[dimname] = {0..-1,$3.to_i}
+ thinning[dimname] = {0..-1=>$3.to_i}
when /(.*):(.*)/
slice[dimname] = ($1.to_f)..($2.to_f)
else
slice[dimname] = subset.to_f
end
@@ -78,17 +85,23 @@
#---------------------- Option Configuration ----------------------
parser = GetoptLong.new(
["--variable", "-v", GetoptLong::REQUIRED_ARGUMENT],
["--output", "-o", GetoptLong::REQUIRED_ARGUMENT],
["--slice", "-s", GetoptLong::REQUIRED_ARGUMENT],
+ ["--mean", "-m", GetoptLong::REQUIRED_ARGUMENT],
+ ["--stddev", "-d", GetoptLong::REQUIRED_ARGUMENT],
+ ["--eddy", "-e", GetoptLong::REQUIRED_ARGUMENT],
["--help", "-h", GetoptLong::NO_ARGUMENT ])
begin
parser.each{|opt, arg|
case opt
when "--variable" then eval "$OPT_var='#{arg}'"
when "--output" then eval "$OPT_output='#{arg}'"
when "--slice" then eval "$OPT_slice='#{arg}'"
+ when "--mean" then eval "$OPT_mean='#{arg}'"
+ when "--stddiv" then eval "$OPT_stddev='#{arg}'"
+ when "--eddy" then eval "$OPT_eddy='#{arg}'"
when "--help" then eval "$HELP=true"
else
raise "must not happen"
end
}
@@ -137,9 +150,37 @@
#------------------- Slice/thinning gphys variable --------------------
gphys = gphys.cut(slice) if slice
gphys = gphys[thinning] if thinning
+
+#------------------- mean/eddy gphys variable --------------------
+## mean along any axis
+if ($OPT_mean)
+ dims_mean = ($OPT_mean).split(/\s*,\s*/)
+ dims_mean = dims_mean.map{|dim| dim.to_i.to_s == dim ? dim.to_i : dim}
+ dims_mean.each{|dim|
+ gphys = gphys.mean(dim)
+ }
+end
+
+## standard deviation along any axis
+if ($OPT_stddev)
+ dims_stddev = ($OPT_stddev).split(/\s*,\s*/)
+ dims_stddev = dims_stddev.map{|dim| dim.to_i.to_s == dim ? dim.to_i : dim}
+ dims_stddev.each{|dim|
+ gphys = gphys.stddev(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|
+ gphys = gphys.eddy(dim)
+ }
+end
#---------------------- Output GPhys variable ------------------------
GPhys::IO.write( outncfile, gphys )
NetCDF_Conventions.add_history(outncfile, File.basename($0)+" "+ARGV[0])
outncfile.close