File: demo4-copy.rb

package info (click to toggle)
ruby-netcdf 0.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,192 kB
  • sloc: ansic: 3,968; ruby: 1,661; makefile: 9; csh: 6
file content (32 lines) | stat: -rw-r--r-- 704 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
=begin

=demo4-copy.rb

Make a copy of a NetCDF file

==Usage

% ruby demo4-copy.rb filename_from filename_to

=end

def usage
"\n\nUSAGE:\n% ruby #{$0} filename_from filename_to\n"
end

require "numru/netcdf"
include NumRu
raise usage if ARGV.length != 2
filename_from, filename_to = ARGV
from = NetCDF.open(filename_from)
to = NetCDF.create(filename_to)
from.each_dim{|dim| to.def_dim( dim.name, dim.length_ul0 )}
from.each_att{|att| to.put_att( att.name, att.get )}    ## global attributes
from.each_var{|var|
  newvar = to.def_var( var.name, var.ntype, var.dim_names )
  var.each_att{|att| newvar.put_att( att.name, att.get )}
}
to.enddef
from.each_var{|var| to.var(var.name).put(var.get)}
to.close