Sha256: ff39067ee4c9998683cea9911e7c14fc1f769b6a94a906d7612a4e26671701ba

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

=begin
=gpcommon.rb

 This library provides common methods used in gp* command. 

==METHOD LIST

  * help                           : print help message

  * NumRu::Netcdf.copy_global_att  : Copy global attributes from a Gphys 
                                     variable. It operates only when a gphys 
                                     variable consist of a NetCDF file.

==HISTORY

  2005/08/23  S Takehiro (created)
  2008/02/14  S Takehiro (copy_global_att can deal with GPhys 
                          which consists of multiple files)
  2015/09/06  H Kashimura && S Takehiro (fixed for installation by gem)

=end

#------------------------ print help message ------------------------
def help
  begin 
    file = File.open(Gem.bin_path("gphys",File.basename($0)))
  rescue
    file = File.open($0)
  end
#  file = File.open($0)
  after_begin = false
  after_end = false
  while (line = file.gets)
    after_end = true if /^=end/ =~ line
    print line if after_begin && !after_end
    after_begin = true if /^=begin/ =~ line
  end
  file.close
end

#------------- Copy global attributes (only for NetCDF file) --------
class NumRu::NetCDF
  def copy_global_att(gp)
    ncfiles = gp.data.file 
    # for gphys consisting of multiple files 
    if /NArray/  =~ ncfiles.class.to_s  
      ncfile = ncfiles[0]
    else
      ncfile = ncfiles
    end
    # Check whether gphys is a NetCDF file or not
    if /NetCDF/  =~ ncfile.class.to_s
      ncfile.each_att{|att|
        att.copy(self)
      }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gphys-1.5.6 lib/numru/gphys/gpcommon.rb
gphys-1.5.5 lib/numru/gphys/gpcommon.rb
gphys-1.5.4 lib/numru/gphys/gpcommon.rb
gphys-1.5.3 lib/numru/gphys/gpcommon.rb
gphys-1.5.2 lib/numru/gphys/gpcommon.rb
gphys-1.5.1 lib/numru/gphys/gpcommon.rb
gphys-1.5.0 lib/numru/gphys/gpcommon.rb