ruby-netcdf-0.7.2/0000755000175000017500000000000012772251340013601 5ustar uwabamiuwabamiruby-netcdf-0.7.2/test/0000755000175000017500000000000012772251340014560 5ustar uwabamiuwabamiruby-netcdf-0.7.2/test/create_tmp.rb0000644000175000017500000000044212772251340017230 0ustar uwabamiuwabamirequire 'numru/netcdf' $DEBUG = true include NumRu file = NetCDF.create_tmp file.def_dim('x',5) file.put_att("history", __FILE__ ) p file.path p file.att("history").get print "environment variable TEMP ="+(ENV['TEMP'] || '')+"\n" file2=file print "000\n" file.close GC.start print "aaa\n" ruby-netcdf-0.7.2/test/test.rb0000644000175000017500000001335112772251340016067 0ustar uwabamiuwabamirequire 'numru/netcdf' ## // to test before make install --> #require 'narray' #require '../netcdfraw' #require '../lib/netcdf' ## <-- to test before make install // include NumRu filename = "test.nc" print "creating ",filename,"...\n" file=NetCDF.create(filename,false,false) dimx=file.def_dim("x",15) dimy=file.def_dim("y",10) dimz=file.def_dim("z",10) batt = file.put_att("type_byte",5,"byte") file.put_att("type_short",[222,333,444],"sint") file.put_att("type_int",[2222,3333,4444]) file.put_att("type_float",[2.22,3.33,4.44],"sfloat") file.put_att("type_double",[2.222,3.333,4.444]) string = file.put_attraw("string","netCDF for Ruby","string") batt.put(6,"byte") sint_var=file.def_var("test_sint","sint",["x"]) byte_var=file.def_var("test_byte","byte",["y"]) byte_var2=file.def_var("test_byte2","byte",[dimy,dimz]) int_var=file.def_var("test_int","int",["y"]) sfloat_var=file.def_var("test_sfloat","sfloat",["z"]) float_var=file.def_var("test_float","float",["y"]) a=NArray.sint(10).indgen b=NArray.sint(10).fill(7) c=NArray.byte(10).indgen d=NArray.int(10).indgen e=NArray.sfloat(10).fill(1.111) f=NArray.float(10).fill(5.5555555) file.enddef file2 = file (file2 == file) byte_var.put_var_byte(c) int_var.put_var_int(d) sfloat_var.put_var_sfloat(e) float_var.put_var_float(f) file.redef byte_vara=file.def_var("test_byte_vara","byte",[dimy,dimz]); sint_vara=file.def_var("test_sint_vara","sint",["y","z"]); int_vara=file.def_var("test_int_vara","int",["y","z"]); sfloat_vara=file.def_var("test_sfloat_vara","sfloat",["y","z"]); float_vara=file.def_var("test_float_vara","float",["y","z"]); file.enddef byte_vara2 = byte_vara (byte_vara2 == byte_vara) g=NArray.byte(10,10).indgen h=NArray.byte(2,3).indgen gh=NArray.byte(1,1).fill(33) k=NArray.sint(10,10).indgen l=NArray.sint(2,3).indgen kl=NArray.sint(1,1).fill(44) m=NArray.int(10,10).indgen n=NArray.int(2,3).indgen mn=NArray.int(1,1).fill(55) o=NArray.sfloat(10,10).fill(1.234567) p=NArray.sfloat(2,3).fill(2.345678) op=NArray.int(1,1).fill(3.4) q=NArray.float(10,10).fill(1.234) r=NArray.float(2,3).fill(2.345) qr=NArray.float(1,1).fill(4.5) s=NArray.float(2,2).fill(10.0) byte_vara.put(g) byte_vara.put(h,{"start"=>[3,5]}) byte_vara.put(g,{"start"=>[0,0],"end"=>[9,9]}) byte_vara.put(h,{"start"=>[-8,2]}) byte_vara.put(h,{"start"=>[0,0],"stride"=>[2,3]}) byte_vara.put(h,{'start'=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) byte_vara.put(gh,{"index"=>[4,7]}) sint_vara.put(k) sint_vara.put(l,{"start"=>[3,5]}) sint_vara.put(k,{"start"=>[0,0],"end"=>[9,9]}) sint_vara.put(l,{"start"=>[-8,2]}) sint_vara.put(l,{"start"=>[0,0],"stride"=>[2,3]}) sint_vara.put(l,{"start"=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) sint_vara.put(kl,{"index"=>[4,7]}) int_vara.put(m) int_vara.put(n,{"start"=>[3,5]}) int_vara.put(m,{"start"=>[0,0],"end"=>[9,9]}) int_vara.put(n,{"start"=>[-8,2]}) int_vara.put(n,{"start"=>[0,0],"stride"=>[2,3]}) int_vara.put(n,{"start"=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) int_vara.put(mn,{"index"=>[4,7]}) sfloat_vara.put(o) sfloat_vara.put(p,{"start"=>[3,5]}) sfloat_vara.put(o,{"start"=>[0,0],"end"=>[9,9]}) sfloat_vara.put(p,{"start"=>[-8,2]}) sfloat_vara.put(p,{"start"=>[0,0],"stride"=>[2,3]}) sfloat_vara.put(p,{"start"=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) sfloat_vara.put(op,{"index"=>[4,7]}) float_vara.put(q) float_vara.put(r,{"start"=>[3,5]}) float_vara.put(q,{"start"=>[0,0],"end"=>[9,9]}) float_vara.put(r,{"start"=>[-8,2]}) float_vara.put(r,{"start"=>[0,0],"stride"=>[2,3]}) float_vara.put(r,{"start"=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) float_vara.put(qr,{"index"=>[4,7]}) float_vara.dim_names na_aaa=byte_vara.get({"start"=>[3,5]}) na_aab=byte_vara.get({"start"=>[0,0],"end"=>[9,9]}) na_aac=byte_vara.get({"start"=>[-8,2]}) na_aad=byte_vara.get({"start"=>[0,0],"stride"=>[2,3]}) na_aae=byte_vara.get({'start'=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) na_aaf=byte_vara.get({"index"=>[4,7]}) na_aag=byte_vara.get na_bba=sint_vara.get({"start"=>[3,5]}) na_bbb=sint_vara.get({"start"=>[0,0],"end"=>[9,9]}) na_bbc=sint_vara.get({"start"=>[-8,2]}) na_bbd=sint_vara.get({"start"=>[0,0],"stride"=>[2,3]}) na_bbf=sint_vara.get({"start"=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) na_bbg=sint_vara.get({"index"=>[4,7]}) na_bbh=sint_vara.get na_cca=int_vara.get({"start"=>[3,5]}) na_ccb=int_vara.get({"start"=>[0,0],"end"=>[9,9]}) na_ccc=int_vara.get({"start"=>[-8,2]}) na_ccd=int_vara.get({"start"=>[0,0],"stride"=>[2,3]}) na_cce=int_vara.get({"start"=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) na_ccf=int_vara.get({"index"=>[4,7]}) na_ccg=int_vara.get na_dda=sfloat_vara.get({"start"=>[3,5]}) na_ddb=sfloat_vara.get({"start"=>[0,0],"end"=>[9,9]}) na_ddc=sfloat_vara.get({"start"=>[-8,2]}) na_ddd=sfloat_vara.get({"start"=>[0,0],"stride"=>[2,3]}) na_dde=sfloat_vara.get({"start"=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) na_ddf=sfloat_vara.get({"index"=>[4,7]}) na_ddg=sfloat_vara.get na_eea=float_vara.get({"start"=>[3,5]}) na_eeb=float_vara.get({"start"=>[0,0],"end"=>[9,9]}) na_eec=float_vara.get({"start"=>[-8,2]}) na_eed=float_vara.get({"start"=>[0,0],"stride"=>[2,3]}) na_eee=float_vara.get({"start"=>[1,1],"end"=>[3,7],"stride"=>[2,3]}) na_eef=float_vara.get({"index"=>[4,7]}) na_eeg=float_vara.get file.redef copy_byte = string.copy(byte_vara) copy_byte.put([0,20],"byte") copy_byte.name="new_name" copy_byte2 = copy_byte (copy_byte2 == copy_byte) copy_sint = string.copy(sint_vara) copy_sint.put("%%%%%") copy_int = string.copy(int_vara) copy_int.put([0,60],"int") copy_sfloat = string.copy(sfloat_vara) copy_sfloat.put([0.01,5.5],"sfloat") copy_float = string.copy(float_vara) copy_float.put([0.0001,5.5555],"float") file.enddef nm = copy_byte.name att0 = string.get att1 = copy_byte.get att2 = copy_sint.get att3 = copy_int.get att4 = copy_sfloat.get att5 = copy_float.get file.fill(true) file.fill(false) float_vara.dim_names float_vara.att_names file.close exit(0) ruby-netcdf-0.7.2/test/def_var_with_dim.rb0000644000175000017500000000065612772251340020406 0ustar uwabamiuwabamirequire 'numru/netcdf' include NumRu file = NetCDF.create("tmp.nc") var1 = file.def_var_with_dim("var1","sfloat",[6],["x"]) var2 = file.def_var_with_dim("var2","sfloat",[6,3],["x","y"]) var3 = file.def_var_with_dim("var3","sfloat",[3],["y"]) var3 = file.def_var_with_dim("var4","sfloat",[0],["t"]) att = var1.put_att("long_name","test") file.close p var1 == nil p file == nil p att == nil p att == att, var1 ==var1, file == file ruby-netcdf-0.7.2/test/test.cdl0000644000175000017500000000150612772251340016225 0ustar uwabamiuwabaminetcdf test { dimensions: x = 15 ; y = 10 ; z = 10 ; variables: short test_sint(x) ; byte test_byte(y) ; byte test_byte2(z, y) ; int test_int(y) ; float test_sfloat(z) ; double test_float(y) ; byte test_byte_vara(z, y) ; test_byte_vara:min to max of byte_vara = 0b, 20b ; short test_sint_vara(z, y) ; test_sint_vara:string = "%%%%%" ; int test_int_vara(z, y) ; test_int_vara:min to max of int_vara = 0, 60 ; float test_sfloat_vara(z, y) ; test_sfloat_vara:min to max of float_vara = 0.01f, 5.5f ; double test_float_vara(z, y) ; test_float_vara:min_to max of double_vara = 0.0001, 5.5555 ; // global attributes: :type_byte = 6b ; :type_short = 222s, 333s, 444s ; :type_int = 2222s, 3333s, 4444s ; :type_float = 2.22f, 3.33f, 4.44f ; :type_double = 2.222, 3.333, 4.444 ; :string = "netCDF for Ruby" ; } ruby-netcdf-0.7.2/test/type.rb0000644000175000017500000000040212772251340016062 0ustar uwabamiuwabamirequire 'numru/netcdf' include NumRu s = 'tmp.nc' f = NetCDF.create(s) d = f.def_dim('x',2) v = f.def_var('x','sfloat',[d]) p v.vartype, v.ntype v = f.def_var('x1','sint',[d]) p v.vartype, v.ntype v = f.def_var('x2','byte',[d]) p v.vartype, v.ntype f.close ruby-netcdf-0.7.2/test/putatt.cdl0000644000175000017500000000074312772251340016571 0ustar uwabamiuwabaminetcdf tmp { dimensions: x = 5 ; variables: float x(x) ; x:long_name = "test variable" ; x:int_att = 123s ; x:float_att = 0.333333333333333 ; x:float_array = 0.1, 0.2, 30. ; x:sfloat_narray = 0.f, 0.3333333f, 0.6666667f ; x:float_narray = 0., 1., 2. ; x:sint_narray = 0s, 1s, 2s ; x:int2float = 10. ; x:changed = "changed to text" ; // global attributes: :history = "2001-12-23" ; :int_att = 123s ; :sfloat_att = 0.3333333f ; data: x = _, _, _, _, _ ; } ruby-netcdf-0.7.2/test/aref_aset.rb0000644000175000017500000000132512772251340017037 0ustar uwabamiuwabamirequire 'numru/netcdf' include NumRu s = 'tmp.nc' f = NetCDF.create(s) f.redef dx = f.def_dim('x',5) dy = f.def_dim('y',3) v = f.def_var('x','sfloat',[dx]) v2 = f.def_var('x2',NArray::SFLOAT,[dx]) vxy = f.def_var('xy','sfloat',[dx,dy]) f.enddef v.put([1,2,3,4,5]) p 'testing []= ...' v[{0..3=>2}]=[100,500] v[1]=999 v[3..4]=[-99,-99] v2.put(666) v2[0..2]=777 vxy.put(NArray.sfloat(5,3).indgen!) vxy[[2,0],[0,2,1]] = [[1,2],[3,4],[5,6]] vxy[1,[2,0,1]] = [10,20,30] vxy[[4,3],2] = [100,200] f.close f = NetCDF.open(s) v = f.var('x') p 'testing [] ...' p '*0*',v[{0..3=>2}] p '*1*',v[1] p '*2*',v[3..4],v.rank p '*3*',v[[2,0,0]] vxy = f.var('xy') p '*4*',vxy[[2,0],[0,2,1]] p '*5*',vxy[1,[2,0,1]] p '*6*',vxy[[4,3],2] f.close ruby-netcdf-0.7.2/test/putatt.rb0000644000175000017500000000274612772251340016437 0ustar uwabamiuwabamirequire 'numru/netcdf' include NumRu s = 'tmp.nc' f = NetCDF.create(s) d = f.def_dim('x',5) v = f.def_var('x','sfloat',[d]) require 'date' att = f.put_att("history", Date.today.to_s ) p att.get, f.att("history").get att = f.put_att("int_att",123) att = f.put_att("sfloat_att",1.0/3.0,'sfloat') att = f.put_att("sfloat_att2",2.0/3.0,NArray::SFLOAT) att = v.put_att("long_name",'test variable') att = v.put_att("int_att",123) p att.get, v.att("int_att").get att = v.put_att("float_att",1.0/3.0) att = v.put_att("float_array",[0.1, 0.2, 30]) att = v.put_att("sfloat_narray",NArray.sfloat(3).indgen!/3) att = v.put_att("float_narray",NArray.float(3).indgen!) att = v.put_att("sint_narray",NArray.sint(3).indgen!) att = v.put_att("int2float",10,'float') att = att = v.put_att("dummy",10,'float') att.put('changed to text') att.name = 'changed' begin v.put_att("destined_to_fail",9.8,'complex') rescue print "*1* exception raised as expected -- (", __FILE__,":",__LINE__,") ", $!,"\n" end begin v.put_att("destined_to_fail",9.8,'string') rescue print "*2* exception raised as expected -- (", __FILE__,":",__LINE__,") ", $!,"\n" end begin v.put_att("destined_to_fail",'hello','int') rescue print "*3* exception raised as expected -- (", __FILE__,":",__LINE__,") ", $!,"\n" end begin v.put_att("destined_to_fail",[10,30,'sss']) rescue print "*4* exception raised as expected -- (", __FILE__,":",__LINE__,") ", $!,"\n" end f.close print `ncdump tmp.nc` ruby-netcdf-0.7.2/test/char_var.rb0000644000175000017500000000072212772251340016673 0ustar uwabamiuwabami## test of "char" variables require 'numru/netcdf' include NumRu s = 'tmp.nc' f = NetCDF.create(s) d = f.def_dim('x',5) v = f.def_var('x','char',[d]) tv = f.def_var('text','char',[d]) f.enddef v.put( NArray.byte(5).indgen! ) tv.put( NArray.to_na("hello","byte",5) ) tv.put( NArray.to_na("LO","byte",2), 'start'=>[3] ) tv.put( NArray.to_na("H","byte",1), 'index'=>[0] ) f.close f = NetCDF.open(s) v = f.var('x') p v.get tv = f.var('text') p tv.get p tv.get.to_s ruby-netcdf-0.7.2/test/clone.rb0000644000175000017500000000145712772251340016214 0ustar uwabamiuwabamirequire 'numru/netcdf' include NumRu s = 'tmp.nc' #f = NetCDF.new(s,'rw') f = NetCDF.create(s) f.redef d = f.def_dim('x',3) v = f.def_var('x','sfloat',[d]) a = f.put_att('long_name','xx') f.enddef v.put([1,2,3]) f.taint f.freeze f2 = f.clone p 'netcdf clone' p f.path, f2.path p f.tainted?, f2.tainted?, f.frozen?, f2.frozen? p 'netcdf dup' f3 = f.dup p f.tainted?, f3.tainted?, f.frozen?, f3.frozen? p 'netcdfdim' d.taint d2 = d.clone d3 = d.dup p d.tainted?, d2.tainted?, d3.tainted? p 'netcdfvar' v.taint v2 = v.clone v3 = v.dup p v.tainted?, v2.tainted?, v3.tainted? p 'netcdfatt' a.taint a2 = a.clone a3 = a.dup p a.tainted?, a2.tainted?, a3.tainted? f.close p 'narray (for reference)' a = NArray.float(3) a.taint b = a.clone p a.tainted?, b.tainted? b = a.dup p a.tainted?, b.tainted? ruby-netcdf-0.7.2/test/factor_offset.rb0000644000175000017500000000206312772251340017732 0ustar uwabamiuwabamirequire 'numru/netcdf' include NumRu s = 'tmp.nc' f = NetCDF.create(s) nx = 10 d = f.def_dim('x',nx) v1 = f.def_var('v1','sint',[d]) v2 = f.def_var('v2','sint',[d]) v3 = f.def_var('v3','int',[d]) v1.put_att('scale_factor',0.1,'sfloat') v1.put_att('add_offset',100.0,'sfloat') v2.put_att('scale_factor',0.1,'sfloat') v2.put_att('add_offset',100.0,'sfloat') v3.put_att('scale_factor',0.1,'sfloat') v3.put_att('add_offset',100.0,'sfloat') f.enddef v1.put( NArray.sint(nx).indgen!+100 ) v2.scaled_put( NArray.float(nx).indgen!+100 ) v3.scaled_put( NArray.float(nx).indgen!+100 ) f.close print "** originally unscaled\n" f = NetCDF.open(s) v1 = f.var('v1') v11 = v1.get v12 = v1.scaled_get p v11 p v12 print "** originally scaled\n" v2 = f.var('v2') v21 = v2.get v22 = v2.scaled_get p v21 p v22 print "** originally sclaed (int --> double)\n" v3 = f.var('v3') v31 = v3.get v32 = v3.scaled_get p v31 p v32 print "** unpack type fixed to sfloat\n" NetCDFVar.unpack_type = NArray::SFLOAT v33 = v3.scaled_get p v33 NetCDFVar.unpack_type = NArray::INT v33 = v3.scaled_get p v33 ruby-netcdf-0.7.2/ruby-netcdf.gemspec0000644000175000017500000000230012772251340017363 0ustar uwabamiuwabami# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'numru/netcdf/version' Gem::Specification.new do |spec| spec.name = "ruby-netcdf" spec.version = NumRu::NetCDF::VERSION spec.authors = ["Takeshi Horinouchi", "Tsuyoshi Koshiro",\ "Shigenori Otsuka", "Seiya Nishizawa", "T Sakakima"] spec.email = ['eriko@gfd-dennou.org'] spec.summary = %q{Ruby interface to NetCDF} spec.description = %q{RubyNetCDF is the Ruby interface to the NetCDF library built on the NArray library, which is an efficient multi-dimensional numeric array class for Ruby. This version works with Ruby2.0.} spec.homepage = 'http://www.gfd-dennou.org/arch/ruby/products/ruby-netcdf/' spec.licenses = ["BSD-2-Clause"] spec.files = `git ls-files -z`.split("\x0") spec.test_files = spec.files.grep(%r{^(test|demo)/}) spec.require_paths = ["ext","lib"] spec.extensions << "ext/numru/extconf.rb" spec.required_ruby_version = Gem::Requirement.new(">= 1.8") spec.add_runtime_dependency(%q, [">= 0"]) spec.add_runtime_dependency(%q, [">= 0"]) end ruby-netcdf-0.7.2/INSTALL0000644000175000017500000000357012772251340014637 0ustar uwabamiuwabamiInstallation 0. The following must have been installed in advance. * Ruby, of course . * NArray: a multi-dimensional numeric array class for Ruby. * NetCDF ver 3. (Fortran and C++ interfaces are not needed, so you can ignore it if their installation does not succeed.) * (OPTIONAL) NArrayMiss, which is require to use NetCDFVar#get_with_miss etc by require 'numru/netcdf_miss' NArrayMiss does not have to be installed in advance. 1. Change to the top directory such as by: % cd ruby-netcdf-0.5.3 Here, "%" is a "prompt". Do not type it. The directory name depends on the version of RubyNetCDF 2. Configure your setting to create Makefile. % ruby extconf.rb NOTE: By default, the two headers narray.h and narray_config.h in the narraypackage are assumed to have been copied to $(sitearchdir), which is normally /usr/local/lib/ruby/site_ruby/1.6/$(arch)/ if you are using Unix, where $(arch) is something like sparc-solaris2.6, a combination of CPU and OS. To specify the directory that contains these files explicitly, use instead the following: % ruby extconf.rb --with-narray-include=/narraydir/include Similarly, you can specify the directory you installed netcdf with the following: % ruby extconf.rb --with-netcdf-include=/netcdfdir/include \ --with-netcdf-include=/netcdfdir/lib or % ruby extconf.rb --with-netcdf-dir=/netcdfdir 3. Compile source codes and create a shared library. % make 4. Optionally, you can run a test program by the following: % make test 5. Installs it into your site-specific library path for Ruby. % make site-install ruby-netcdf-0.7.2/LICENSE.txt0000644000175000017500000000513112772251340015424 0ustar uwabamiuwabamiRuby/NetCDF is copyrighted free software by Takeshi Horinouchi and the GFD Dennou Club. You can redistribute it and/or modify it under either the terms of the GPL, or the conditions below, which is idential to Ruby's license (http://www.ruby-lang.org/en/LICENSE.txt): 1. You may make and give away verbatim copies of the source form of the software without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may modify your copy of the software in any way, provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or by allowing the author to include your modifications in the software. b) use the modified software only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided. d) make other distribution arrangements with the author. 3. You may distribute the software in object code or executable form, provided that you do at least ONE of the following: a) distribute the executables and library files of the software, together with instructions (in the manual page or equivalent) on where to get the original distribution. b) accompany the distribution with the machine-readable source of the software. c) give non-standard executables non-standard names, with instructions on where to get the original software distribution. d) make other distribution arrangements with the author. 4. You may modify and include the part of the software into any other software (possibly commercial). But some files in the distribution are not written by the author, so that they are not under this terms. They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some files under the ./missing directory. See each file for the copying condition. 5. The scripts and library files supplied as input to or produced as output from the software do not automatically fall under the copyright of the software, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this software. 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ruby-netcdf-0.7.2/.ChangeLog.until201501170000644000175000017500000004437212772251340017416 0ustar uwabamiuwabamiTue Jan 27 2015 T Horinouchi * ruby-netcdf-0.7.1 released (relase tag: ruby-netcdf-0_7_1) Tue Jan 27 2015 T Horinouchi * doc/ updated * demo/demo5-netcdf4.rb: created * netcdfraw.c: * added new NetCDF-4 methods: * NetCDFVar::deflate : to set compression * NetCDFVar::deflate_params : returns current values of compression parameters * NetCDFVar::endian= : set (change) the endian * NetCDFVar::endian : returns the current endian setting * added new constants: NC_ENDIAN_NATIVE (=0), NC_ENDIAN_LITTLE (=1), NC_ENDIAN_BIG (=2) * updated the safe-level condition, which was missed in the change on Jan 22. Fri Jan 23 2015 T Horinouchi * doc/ updated Thu Jan 22 2015 T Horinouchi * ruby-netcdf-0.7.0 released (relase tag: ruby-netcdf-0_7_0) Thu Jan 22 2015 T Horinouchi * netcdfraw.c: * revised based on the patch posted by seiya with [dennou-ruby:003705] but adopted the typedef in the latest narray-bigmem (namely, used na_shape_t). * changed rb_secure(4) to rb_secure(3), since security level 4 is abolished in ruby 2. * further type update to na_shape_t (not covered by the patch) * deleted the unused variable nc_tlen in many methods. * lib/netcdf.rb: revised along the patch [dennou-ruby:003705]. * extconf.rb: supported to configure gem-installed narray Mon Sep 8 2014 T Horinouchi * lib/netcdf.rb: Tentative treatment of the very slow netcdf-4's strided reading. Sat Sep 6 2014 T Horinouchi * netcdfraw.c: Added constants such as NC_NETCDF4; This enables one to individually specify the creation format by using the low level interface NetCDF.nc_create * lib/netcdf.rb: Supported the "default" file creation format by adding NetCDF.creation_format= and NetCDF.creation_format. * lib/netcdf.rb: Refactoring of NetCDF#simple_get. Sat Sep 6 2014 T Horinouchi * extconf.rb * introduced the macro NCVER * changed to give a higer priority to NetCDF 4; * added $vendorarchdir to dir_config * netcdfraw.c: Added the class method NetCDF.libvers (<- nc_inq_libvers) * lib/netcdf.rb: Added the class constant NCVERSION (<- NetCDF.libvers) Mon Aug 25 2014 T Horinouchi * netcdfraw.c: to avoid a compile error when -Werror=format-security Sun Feb 19 2011 T Horinouchi * ruby-netcdf-0.6.6 released (relase tag: ruby-netcdf-0_6_6) * lib/netcdf.rb: method pack: debug of enbug made when 1.1 -> 1.2 (cvs tag) commited in Jan 2010. * netcdfraw.c: Added macro NC_RAISE2. Enhanced error messaging in NetCDF_open and NetCDF_create to show file name. Thu Feb 17 2011 T Horinouchi * ruby-netcdf-0.6.5 released (relase tag: ruby-netcdf-0_6_5) Thu Feb 17 2011 T Horinouchi * extconf.rb: Debug to have the --disable-opendap option really work Sat Feb 12 2011 T Horinouchi * ruby-netcdf-0.6.5 preview release. Thu Dec 23 2010 T Koshiro * test/aref_aset.rb : updated for Ruby 1.9.2 * lib/netcdf.rb: NetCDF.clean_tmpfile : lambda -> proc * verified that all test programs work fine with Ruby 1.9.2. Tue Dec 14 2010 T Koshiro * netcdfraw.c : nctype2natype : char* -> const char* * test/aref_aset.rb, test/factor_offset.rb : bug fix. Mon Dec 13 2010 T Koshiro * netcdfraw.c : patch for Ruby 1.9.2 - by S Kouketsu (dennou-ruby:003191) - by T Koshiro (dennou-ruby:003226) Mon Mar 15 2010 T Horinouchi * ruby-netcdf-0.6.4 released (relase tag: ruby-netcdf-0_6_4) Thu Jan 14 2010 T Horinouchi < T Koshiro * netcdfraw.c : patch for Ruby 1.9.1 (dennou-ruby:003138) * extconf.rb : patch for NetCDF-4.1-beta2 (dcdvlop Nov 20, 2009) Fri Aug 15 2008 T Horinouchi * lib/netcdf_miss.rb: in __interpret_missing_params, changed just to warn, not to raise an exception, if the missing value or fill value is within the valid range (warning can be suppressed by $VERBOSE = nil) Thu Jul 17 2008 T Horinouchi * lib/netcdf.rb: NetCDFVar's private method pack : to take round if the type of self is integer. * lib/netcdf_miss.rb: debug in the handling of missing data specification using the external data type. Wed Jul 16 2008 T Horinouchi < M Otsuka * netcdfraw.c : patch for Ruby 1.9 Tue Dec 25 2007 T Horinouchi * ruby-netcdf-0.6.3 released * netcdfra.c : (kind of) bugfix. (default attribute type for Fixnum and Bignum was changed from NA_SINT to NA_LINT). * lib/netcdf_miss.rb: improved to judge missing_value validity considering its typecode. Thu Jun 30 2005 * netcdf.rb: NetCDFVar#[] : debug for Array/NArray indices Thu Jun 23 2005 T Horinouchi < S Koshiro * ruby-netcdf-0.6.2 re-released (I am really sorry about that) * extconf.rb: updated to configure the prefix for DODS (useful if the DODS is installed in a non-standard path) Wed Jun 22 2005 T Horinouchi * ruby-netcdf-0.6.2 released * extconf.rb: updated to support opendap 3.5 Fri May 13 2005 T Horinouchi * ruby-netcdf-0.6.1 released Mon Apr 11 2005 Takeshi Horinouchi * netcdfraw.c: changed global variables such as mNumRu to file locale. Tue Mar 15 2005 Takeshi Horinouchi * netcdfraw.c: debug: changed the type of c_stride from size_t to ptrdiff_t. Removed unsuned variables. Mon Mar 14 2005 Takeshi Horinouchi * ruby-netcdf-0.6.0 released * netcdfraw.c: NetCDF_get_var*_*: debug for rank-zero scalar NetCDFVar. It used to SEGV. NetCDF_get_var_*, which reads the whole variable, is modified to return in a NArray of shape==[1]. On the other hand, subset reading by NetCDF_get_var[s1]_* is prohibited for rank-zero scalars by raising an exception. * lib/netcdf.rb: minor modification in [], to support its call without arguments of a rank-zero scalar. * netcdfraw.c: debug: changed size_t to int when NArray functions are called (for 64-bit machines). * extconf.rb: minor change in opendap configuration. Thu Mar 10 2005 Takeshi Horinouchi * extconf.rb: to link OPeNDAP/DODS-enabled version of NetCDF if available and if --disable-opendap is not specified. * lib/netcdf.rb: created pack and unpack by separating from scaled_put and scaled_get, respectvely. Changed type to unpack in to follow the coerce mechanism, so the upacked type depend on the type of scale_factor and add_offset. Renamed NetCDFVar.scaled_get_type[=] to NetCDFVar.unpack_type[=]. * lib/netcdf_miss.rb: revised [put|get]_with_miss_and_scaling: Now, missing data handling using valid_* / missing_value is applied basically to packed data, which is consistent with most conventions. However, it is applied to unpacked data if and only if the type of valid_* / missing_value is not the same as the packed data and is the samed as the unpacked data. * doc/ Updated in response to the modification. Mon Jun 7 2004 Takeshi Horinouchi * ruby-netcdf-0.5.5 released Wed Apr 28 2004 Takeshi Horinouchi < S. Nishizawa * lib/netcdf.rb: minor debug in [](l.662) and []= (l.733 & l.736) to avoid error with NArrayMiss. Mon Mar 8 2004 Takeshi Horinouchi * ruby-netcdf-0.5.4 released * lib/netcdf.rb: created NetCDFVar.scaled_get_type= and NetCDFVar.scaled_get_type Mon Feb 23 2004 Takeshi Horinouchi * lib/netcdf_miss.rb: debug in __interpret_missing_params Tue Oct 28 2003 Takeshi Horinouchi * lib/netcdf.rb: support empty [], []=. Debug in []=. Fri Oct 2 2003 Takeshi Horinouchi * ruby-netcdf-0.5.3 released * lib/netcdf.rb: (by S Nishizawa) enhanced NetCDF#[]= to support array indices. * lib/netcdf.rb: supported the rubber dimension (=false) in NetCDF#[] and NetCDF#[]=. * doc/*rd: updated for NetCDF#[] and NetCDF#[]= * INSTALL: updated Thu Oct 2 2003 Takeshi Horinouchi < S Nishizawa * lib/netcdf.rb: enhanced NetCDF#[] to support array indices. Tue Sep 23 2003 Takeshi Horinouchi * extconf.rb: debug for windows (by T Koshiro) * lib/netcdf_miss.rb: debug get_with_miss_* Wed Aug 27 2003 Takeshi Horinouchi * ruby-netcdf-0.5.2 released * Verified that all test programs work fine with Ruby 1.8.0. * netcdfraw.c: functions NetCDF_dim, NetCDF_var (methods NetCDF#dim, NetCDF#var). Changed behavior back to return nil if not found (by name), as opposed to the change on Feb 3 2003. Debug NetCDF_att_rename (NetCDFAtt#name=). Init_netcdfraw: No longer asks whether NumRu has been defined -- ok for Ruby 1.6.5 or so or later * doc/Ref_man.rd,doc/Ref_man_jp.rd: updated for the changes above * test/test.rb updated for the debug of NetCDFAtt#name=. * lib/netcdf.rb: editted NetCDF#vars and NetCDF#dims not to change the behavior despite the change above. Corrected exception types to raise where needed. Tue Aug 19 2003 Takeshi Horinouchi * demo/demo4-copy.rb: created Tue Aug 12 2003 Takeshi Horinouchi * ruby-netcdf-0.5.1 released * extconf.rb: do not edit "install:" anymore (for Ruby 1.8; works with 1.6 too.) / Debug * doc/Ref_man.rd,doc/Ref_man_jp.rd: corrected a few typos. Tue Aug 12 2003 Takeshi Horinouchi * ruby-netcdf-0.5.0 released * lib/netcdf_miss.rb: created. handles data missing by NArrayMiss. * doc/Ref_man.rd,doc/Ref_man_jp.rd: updated. Mon Aug 11 2003 Takeshi Horinouchi * extconf.rb: modification to cover Cygwin * netcdfraw.c: extern -> EXTERN * lib/netcdf.rb: renamed get|put as simple_(get|put) and made get|put aliased to them. Changed scaled_(get|put) to depend on simple_(put|get). This is to allow the user to redefine get|put, if he/she likes, as: alias get scaled_get alias put scaled_put Or (by using singleton methods) def a_ncvar.get(*arg) scaled_get(*arg) end def a_ncvar.put(*arg) scaled_put(*arg) end Now these do not cause recurrence. By doing so, one can also change the behavior of [] and []=. Sat Mar 24 2003 Takeshi Horinouchi * ruby-netcdf-0.4.0 released Sat Mar 22 2003 Takeshi Horinouchi * lib/netcdf.rb: NetCDFVar#[]: behavior changed -- to eliminate the dimensions designated by Integer's (for better agreement with NArray#[]) * doc/: correct the description of the IO mode for NetCDF.open Fri Mar 21 2003 Takeshi Horinouchi * ruby-netcdf-0.3.9 released Wed Mar 19 2003 Takeshi Horinouchi * netcdfraw.c: changed return values of NetCDF#redef and NetCDF#enddef (NetCDF_redef, NetCDF_enddef) --- return true if succesful and nil if not (the latter means that the file is already in define mode for redef and that it is already in the data mode for enddef). Previously, these methods always retuned nil. * doc/: updated * lib/netcdf.rb: DEBUG [] and []= : treatment of the end of ranges. Tue Mar 18 2003 Takeshi Horinouchi * netcdfraw.c: added NetCDF#define_mode? (NetCDF_whether_in_define_mode) Mon Mar 17 2003 Takeshi Horinouchi * ruby-netcdf-0.3.8 released * netcdfraw.c: deleted function NetCDF_put_var1_long, which was unnecessary (not called by anything). * netcdfraw.c: added methods NetCDFVar#typcode, NetCDFAtt#typcode (functions NetCDF_var_typecode, NetCDF_att_typecode) * netcdfraw.c: NetCDFVar#def_var(NetCDF_def_var) functionarity enhanced to accept NArray's typcodes to specifiy a variable type (vartye). * netcdfraw.c:put_var_*(NetCDF_put_var_*),put_vars_*(NetCDF_put_vars_*) functionality enhanced to accept scalar values to set uniform values * lib/netcdf.rb alias rank ndims (in NetCDFVar) * doc/Ref_man* updated accordingly Fri Mar 14 2003 Takeshi Horinouchi * ruby-netcdf-0.3.7 released Mon Feb 5 2003 Takeshi Horinouchi * doc/Ref_man.rd,doc/Ref_man_jp.rd update (added [] and []= methods) Mon Feb 3 2003 Takeshi Horinouchi * netcdf.rb: added NetCDF#dims, NetCDF#vars * netcdfraw.f: functions NetCDF_dim, NetCDF_var (methods NetCDF#dim, NetCDF#var). Changed behavior to raise exception if not found (by name). Thu Jan 30 2003 Takeshi Horinouchi * ruby-netcdf-0.3.6 released * netcdfraw.c: debug NetCDF_free and NetCDF_close not to close a file that has already been closed * netcdfraw.c: debug nc_mark_obj -- incorrect typing (though in many cases innocuous) * demo/: deleted *_withAdvancedDCL.rb (obsolete) Tue Jun 11 2002 Takeshi Horinouchi * ruby-netcdf-0.3.5 released * netcdfraw.rb: eliminated references to char *na_typestring[] (to make the source compilable with narray-0.5.6p2) * lib/netcdf.rb: eliminated uri methods: this is for a future incorpolation of DODS * demo/demo[23]*:written to use RubyDCL directly instead of AdvancedDCL Tue Feb 26 2002 Takeshi Horinouchi * ruby-netcdf-0.3.4 released Sun Feb 24 2002 Takeshi Horinouchi * lib/netcdf.rb: NetCDF#open minor debug Thu Dec 27 2001 Takeshi Horinouchi * extconf.rb: corrected an error message Thu Dec 26 2001 Takeshi Horinouchi * ruby-netcdf-0.3.3 released * lib/netcdf.rb: changes are made to get around a bug in NArray. Should be re-changed to the original if the bug is fixed. (The changed pars are marked by "TEMPORARY CHANGE 2001/12/27" in the source code) * netcdfraw.c: debug NetCDF_get_vars_sint * doc/Ref_man*rd: added the usage section. Thu Dec 26 2001 Takeshi Horinouchi * ruby-netcdf-0.3.2 released * doc/Ref_man*rd: added a "Data Type" section. Plus, some updates * lib/netcdf.rb: added NetCDF#scaled_put and NetCDF#scaled_get * netcdfraw.c,lib/netcdf.rb: added methods to treat the "char" type Thu Dec 26 2001 Takeshi Horinouchi * ruby-netcdf-0.3.1 released * doc/Ref_man*rd: updated * lib/netcdf/rb: added NetCDF#def_var_with_dim * netcdfraw.c: NetCDF*_eql: debug / do not redefine eql?, since the hash method is not refefined * lib/netcdf/rb: added NetCDFDim#length_ul0 * netcdfraw.c: NetCDF#close: error will not be raised on NetcdfBadid * lib/netcdf/rb: added NetCDFVar#shape_current, NetCDFVar#shape_ul0 * lib/netcdf/rb: added NetCDF.create_tmp -- temporary file * lib/netcdf/rb: NetCDFVar#uri returns path+'?var='+name instead of path+'?'+name Thu Dec 23 2001 Takeshi Horinouchi * ruby-netcdf-0.3.0 released * netcdfraw.c: NetCDFVar#vartype is aliased to NetCDFVar#ntype * INSTALL: updated * extconf.rb: updated thoroughly (better handling of dependent libs) * lib/netcdr.rb: NetCDF.open: changed mode specification -- it became much closer to that for the File class (Also, NetCDF.create was changed a little -- but no effect for users) * netcdfraw.c: NetCDF_open was modified to be a simple wrapper only of nc_open. * netcdfraw.c: completely renew NetCDF_put_att__ --> NArray available (accordingly changed are NetCDF_(put_att|put_att_var|att_put), and lib/netcdf.rb:NetCDF(|Var)#put_att,NetCDFAtt#put) * netcdfraw.c: minor debug -- eliminate global variables rb_cNetCDF* * netcdfraw.c: initialization of mNumRu was improved Thu Dec 7 2001 Takeshi Horinouchi * ruby-netcdf-0.2.0 released * lib/netcdf.rb: debug NetCDFVar#[], NetCDFVar#[]= * doc/Ref_man[_jp].rd: updated * netcdfraw.c: added clone methods * netcdfraw.c: added security check nc_open, nc_create: Check_SafeStr(filename) file modifying methods: rb_secure(4) file reading methods: taint return values * netcdfraw.c: remove unused def of "new" (it's in netcdf.rb) Thu Dec 6 2001 Takeshi Horinouchi * ruby-netcdf-0.1.10 released * demo/demo2-graphic.rb adapted to advanceddcl-0.2.0 * demo/demo3-ncepclim.rb minor change * netcdfraw.c: rename mNum as mNumRu; initialize it only at first time * mkdir test/; mv test.rb test/; and updated test.rb (to include NumRu) * correctet ChangeLog ?? Nov? ?? 2001 Naoki Kawanabe (log added by Horinouchi) * netcdf.rb added NetCDFVar#[] and NetCDFVar#[]= Sat Nov 16 2001 Takeshi Horinouchi * netcdf.rb: added NetCDFVar.new, NetCDFVar.open (these are the same) Sat Nov ?? 2001 Naoki Kawanabe (log added by Horinouchi) * ruby-netcdf-0.1.9 released * extconf.rb debug Sat Nov 03 2001 Naoki Kawanabe * ruby-netcdf-0.1.7 released (memo by Horinouchi: this should be 0.1.8) * changed install directry (require 'netcdf' -> require 'numru/netcdf') * added module 'NumRu' * changed class name (NetCDF -> NumRu::NetCDF etc.) * demo program renewed Thu Oct 25 2001 Takeshi Horinouchi * ruby-netcdf-0.1.7 released * doc/Ref_man.rd Created (English translation) * doc/Ref_man_jp.rd Revised * netcdfraw.c, NetCDF_att_copy: support file as a destination (global attribute) Thu Oct 23 2001 Takeshi Horinouchi * doc/Ref_man_jp.html regenerated from doc/Ref_man_jp.rd * doc/Ref_man_jp.rd Revised. * doc/Ref_man_jp.rd index added. Thu Oct 23 2001 Takeshi Horinouchi * ruby-netcdf-0.1.6 released * NetCDFruby is renamed to RubyNetCDF. Documents are changed accordingly. * INSTALL was made * Ref_man_jp.rd: a bit modified * documents moved to doc/ * Ref_man_jp.[doc|pdf] is renamed to Ref_man_jp_obsolete.[doc|pdf] Will not be maintained any more. Fri Oct 05, 2001 Naoki Kawanabe * version 0.1.5 released * added Ref_man_jp.rd and Ref_man_jp.html (in Japanese) Wed Sep 21, 2001 Takeshi Horiouchi * version 0.1.4 released * netcdfraw.c: debug get_var_ correct dimension order * test.rb truely get rid of xmp Wed Sep 20, 2001 Takeshi Horiouchi * version 0.1.3 released * README_JP.txt modified accordingly * extconf.rb modifyed (support the "test" target) * netcdf.rb: debug (NetCDFAtt#put) * netcdfraw.c: debug (NetCDF_put_att, NetCDF_put_att_var) * test.rb --> debug (usage of NetDCFAtt#put) * test.rb --> do not use xmp. Accordingly, xmp.rb is removed from the package Wed Sep 20, 2001 Takeshi Horiouchi * version 0.1.2 re-released * xmp.rb (an almost standard program) is copied to the top directory * version 0.1.2 released * changed extconf.rb use standard mkmf.rb Makefile modified after creation by mkmf * mv netcdf.rb lib/netcdf.rb Wed Sep 19, 2001 Takeshi Horiouchi * started ToDo list Wed Sep 19, 2001 Takeshi Horiouchi * version 0.1.1 released * Reference manual (in japanese) updated and renamed to Ref_man_jp* * mkmf.rb changed (*.nc included for cleaning), README_JP.txt changed accordingly * demo directly added: demo/demo1-create-alt.rb demo/demo1-create.rb demo/demo2-graphic.rb demo/demo2-graphic_old.rb demo/demo3-ncepclim.rb * netcdfraw.c: NetCDFDim#unlimdim? added * (acutally on Sep 12) netcdf.rb: NetCDFVar#put_att added NetCDF#put_att debug * (acutally on Sep 12) netcdfraw.c: a number of debug, NetCDF_put_att_var (NetCDFVar#put_attraw) added Wed Sep 19, 2001 Toshihiro Sakakima * version 0.01 released ruby-netcdf-0.7.2/ToDo0000644000175000017500000000002112772251340014362 0ustar uwabamiuwabami* none currently ruby-netcdf-0.7.2/lib/0000755000175000017500000000000012772251340014347 5ustar uwabamiuwabamiruby-netcdf-0.7.2/lib/numru/0000755000175000017500000000000012772251340015515 5ustar uwabamiuwabamiruby-netcdf-0.7.2/lib/numru/netcdf.rb0000644000175000017500000005135512772251340017316 0ustar uwabamiuwabamirequire 'narray' require 'numru/netcdf/version' require 'numru/netcdfraw' if NArray.const_defined?(:SUPPORT_BIGMEM) && NArray::SUPPORT_BIGMEM unless NumRu::NetCDF::SUPPORT_BIGMEM raise "Ruby-NetCDF was compiled with NArray with big memory supoort " + "(NArray-bigmem). However the NArray loaded is not NArray-bigmem." end else if NumRu::NetCDF::SUPPORT_BIGMEM raise "Ruby-NetCDF was compiled with NArray without big memory support. " + "However the NArray loaded is with the support (NArray-bigmem)." end end module NumRu class NetCDF Max_Try = 100 NCVERSION = NetCDF.libvers if NCVERSION[0..0] >= "4" @@nc4 = true else @@nc4 = false end def NetCDF.nc4? @@nc4 end @@cr_format = 0 def NetCDF.creation_format=(cmode) raise("This method is available only for NetCDF >= 4") unless @@nc4 case cmode when 0, nil, NC_CLASSIC_MODEL, /^CLASSIC$/i, NC_FORMAT_CLASSIC # classic netcdf ver 3 fmt @@cr_format = 0 when NC_64BIT_OFFSET, /^64BIT_OFFSET$/i, NC_FORMAT_64BIT @@cr_format = NC_64BIT_OFFSET when NC_NETCDF4, /^NETCDF4$/i, NC_FORMAT_NETCDF4 @@cr_format = NC_NETCDF4 when ( NC_NETCDF4 | NC_CLASSIC_MODEL), /^NETCDF4_CLASSIC$/i, NC_FORMAT_NETCDF4_CLASSIC # NetCDF4 but disabling new data models @@cr_format = NC_NETCDF4 | NC_CLASSIC_MODEL else raise ArgumentError, "Unsupported creation mode: #{cmod.to_s}" end end def NetCDF.creation_format raise("This method is available only for NetCDF >= 4") unless @@nc4 case @@cr_format when 0 "TRADITIONAL" when NC_64BIT_OFFSET "64BIT_OFFSET" when NC_NETCDF4 "NETCDF4" when (NC_NETCDF4 | NC_CLASSIC_MODEL) "NETCDF4_CLASSIC" end end def NetCDF.open(filename,mode="r",share=false) call_create=false # false-> nc_open; true->nc_create case(mode) when "r","rb" # read only mode=NC_NOWRITE when "w","w+","wb","w+b" # overwrite if exits call_create=true mode=NC_CLOBBER when "a","a+","r+","ab","a+b","r+b" # append if exits if( File.exists?(filename) ) mode=NC_WRITE else call_create=true #(nonexsitent --> create) mode=NC_CLOBBER end else raise NetcdfError, "Mode #{mode} is not supported" end case(share) when false share=0 when true share=NC_SHARE else raise NetcdfError, "We can't use the sharing mode you typed" end omode = mode | share if(!call_create) nc_open(filename,omode) else nc_create(filename,omode) end end class << NetCDF alias new open end def NetCDF.create(filename,noclobber=false,share=false) case(noclobber) when false noclobber=NC_CLOBBER when true noclobber=NC_NOCLOBBER else raise NetcdfError,"noclobber (2nd argument) must be true or false" end case(share) when false share=0 when true share=NC_SHARE else raise NetcdfError,"share (3rd argument) must be true or false" end cmode=noclobber | share | @@cr_format nc_create(filename,cmode) end class << NetCDF def clean_tmpfile(path) proc { print "removing ", path, "..." if $DEBUG if File.exist?(path) File.unlink(path) end print "done\n" if $DEBUG } end protected :clean_tmpfile end def NetCDF.create_tmp(tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'.', share=false) basename = 'temp' if $SAFE > 0 and tmpdir.tainted? tmpdir = '.' end n = 0 while true begin tmpname = sprintf('%s/%s%d_%d.nc', tmpdir, basename, $$, n) unless File.exist?(tmpname) netcdf = NetCDF.create(tmpname, true, share) ObjectSpace.define_finalizer(netcdf, NetCDF.clean_tmpfile(tmpname)) break end rescue raise NetcdfError, "cannot generate tempfile `%s'" % tmpname if n >= Max_Try end n += 1 end netcdf end def put_att(attname,val,atttype=nil) put_attraw(attname,val,atttype) end def def_var_with_dim(name, vartype, shape_ul0, dimnames) # Same as def_var but defines dimensions first if needed. # Use zero in shape to define an unlimited dimension. if (shape_ul0.length != dimnames.length ) then raise ArgumentError, 'lengths of shape and dimnames do not agree' end dims = [] dimnames.each_index{ |i| dim = self.dim( dimnames[i] ) if ( dim != nil ) then # dim exists --> check the length if (shape_ul0[i] != dim.length_ul0 ) then raise ArgumentError, "dimension length do not agree: #{i}th dim: "+\ "#{shape_ul0[i]} and #{dim.length_ul0}" end dims.push(dim) else # dim does not exist --> define it dims.push( def_dim( dimnames[i], shape_ul0[i] ) ) end } def_var(name, vartype, dims) end # Iterators: def each_dim num_dim=ndims() for dimid in 0..num_dim-1 obj_Dim=id2dim(dimid) yield(obj_Dim) end end def each_var num_var=nvars() for varid in 0..num_var-1 obj_Var=id2var(varid) yield(obj_Var) end end def each_att num_att=natts() for attnum in 0..num_att-1 obj_Att=id2att(attnum) yield(obj_Att) end end def dims( names=nil ) # return all if names==nil if names == nil dims = (0..ndims()-1).collect{|dimid| id2dim(dimid)} else raise TypeError, "names is not an array" if ! names.is_a?(Array) dims = names.collect{|name| dim(name)} raise ArgumentError, "One or more dimensions do not exist" if dims.include?(nil) end dims end def vars( names=nil ) # return all if names==nil if names == nil vars = (0..nvars()-1).collect{ |varid| id2var(varid) } else raise TypeError, "names is not an array" if ! names.is_a?(Array) vars = names.collect{|name| var(name)} raise ArgumentError, "One or more variables do not exist" if vars.include?(nil) end vars end def dim_names num_dim=ndims() names=[] for dimid in 0..num_dim-1 obj_Dim=id2dim(dimid) names=names+[obj_Dim.name] end return names end def var_names num_var=nvars() names=[] for varid in 0..num_var-1 obj_Var=id2var(varid) names=names+[obj_Var.name] end return names end def att_names num_att=natts() names=[] for attnum in 0..num_att-1 obj_Att=id2att(attnum) names=names+[obj_Att.name] end return names end def inspect "NetCDF:"+path end end class NetCDFVar class << NetCDFVar def new(file,varname,mode="r",share=false) if(file.is_a?(String)) file = NetCDF.open(file,mode,share) elsif(!file.is_a?(NetCDF)) raise TypeError, "1st arg must be a NetCDF (file object) or a String (path)" end file.var(varname) end alias open new end alias :rank :ndims def each_att num_att=natts() for attnum in 0..num_att-1 obj_Att=id2att(attnum) yield(obj_Att) end end def dim_names ary = Array.new() dims.each{|dim| ary.push(dim.name)} ary end def att_names num_att=natts() names=[] for attnum in 0..num_att-1 obj_Att=id2att(attnum) names=names+[obj_Att.name] end return names end def put_att(attname,val,atttype=nil) put_attraw(attname,val,atttype) end def shape_ul0 sh = [] dims.each{|d| if d.unlimited? then sh.push(0) else sh.push(d.length) end } sh end def shape_current sh = [] dims.each{|d| sh.push(d.length) } sh end # The put and get methods in the NetCDFVar class def pack(na) sf = att('scale_factor') ao = att('add_offset') if ( sf == nil && ao == nil ) then na else na = NArray.to_na(na) if na.is_a?(Array) if sf csf = sf.get raise NetcdfError,"scale_factor is not a numeric" if csf.is_a?(String) raise NetcdfError, "scale_factor is not unique" if csf.length != 1 raise NetcdfError, "zero scale_factor" if csf[0] == 0 else csf = nil end if ao cao = ao.get raise NetcdfError, "add_offset is not a numeric" if cao.is_a?(String) raise NetcdfError, "add_offset is not unique" if cao.length != 1 else cao = nil end if csf and cao packed = (na - cao) / csf elsif csf packed = na / csf elsif cao packed = na - cao end if self.typecode <= NArray::LINT packed = packed.round end packed end end def scaled_put(var,hash=nil) simple_put( pack(var), hash) end @@unpack_type = nil class << NetCDFVar def unpack_type @@unpack_type end def unpack_type=(na_type) if [NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, NArray::FLOAT, nil].include?(na_type) @@unpack_type = na_type else raise ArgumentError, "Arg must be one of NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, NArray::FLOAT" end end end def unpack(na) sf = att('scale_factor') ao = att('add_offset') if ( sf == nil && ao == nil ) then na else if sf csf = sf.get raise NetcdfError,"scale_factor is not a numeric" if csf.is_a?(String) raise NetcdfError, "scale_factor is not unique" if csf.length != 1 raise NetcdfError, "zero scale_factor" if csf[0] == 0 else csf =nil end if ao cao = ao.get raise NetcdfError, "add_offset is not a numeric" if cao.is_a?(String) raise NetcdfError, "add_offset is not unique" if cao.length != 1 else cao = nil end if csf and cao una = na * csf + cao # csf & cao are NArray -> coerced to their types elsif csf una = na * csf elsif cao una = na + cao end una = una.to_type(@@unpack_type) if @@unpack_type una end end def scaled_get(hash=nil) unpack( simple_get(hash) ) end def simple_put(var,hash=nil) if hash==nil if self.vartype == "char" put_var_char(var) elsif self.vartype == "byte" put_var_byte(var) elsif self.vartype == "sint" put_var_sint(var) elsif self.vartype == "int" put_var_int(var) elsif self.vartype == "sfloat" put_var_sfloat(var) elsif self.vartype == "float" put_var_float(var) else raise NetcdfError,"variable type isn't supported in netCDF" end elsif hash.key?("index")==true if self.vartype == "char" put_var1_char(var,hash["index"]) elsif self.vartype=="byte" put_var1_byte(var,hash["index"]) elsif self.vartype=="sint" put_var1_sint(var,hash["index"]) elsif self.vartype == "int" put_var1_int(var,hash["index"]) elsif self.vartype == "sfloat" put_var1_sfloat(var,hash["index"]) elsif self.vartype == "float" put_var1_float(var,hash["index"]) else raise NetcdfError,"variable type isn't supported in netCDF" end elsif hash.key?("start")==true if hash.key?("end")==false && hash.key?("stride")==false if self.vartype == "char" put_vars_char(var,hash["start"],nil,nil) elsif self.vartype=="byte" put_vars_byte(var,hash["start"],nil,nil) elsif self.vartype=="sint" put_vars_sint(var,hash["start"],nil,nil) elsif self.vartype=="int" put_vars_int(var,hash["start"],nil,nil) elsif self.vartype=="sfloat" put_vars_sfloat(var,hash["start"],nil,nil) elsif self.vartype=="float" put_vars_float(var,hash["start"],nil,nil) else raise NetcdfError, "variable type isn't supported in netCDF" end elsif hash.key?("end")==true && hash.key?("stride") == false if self.vartype == "char" put_vars_char(var,hash["start"],hash["end"],nil) elsif self.vartype=="byte" put_vars_byte(var,hash["start"],hash["end"],nil) elsif self.vartype=="sint" put_vars_sint(var,hash["start"],hash["end"],nil) elsif self.vartype=="int" put_vars_int(var,hash["start"],hash["end"],nil) elsif self.vartype == "sfloat" put_vars_sfloat(var,hash["start"],hash["end"],nil) elsif self.vartype =="float" put_vars_float(var,hash["start"],hash["end"],nil) else raise NetcdfError, "variable type isn't supported in netCDF" end elsif hash.key?("end")==false && hash.key?("stride")==true if self.vartype == "char" put_vars_char(var,hash["start"],nil,hash["stride"]) elsif self.vartype=="byte" put_vars_byte(var,hash["start"],nil,hash["stride"]) elsif self.vartype=="sint" put_vars_sint(var,hash["start"],nil,hash["stride"]) elsif self.vartype=="int" put_vars_int(var,hash["start"],nil,hash["stride"]) elsif self.vartype=="sfloat" put_vars_sfloat(var,hash["start"],nil,hash["stride"]) elsif self.vartype=="float" put_vars_float(var,hash["start"],nil,hash["stride"]) else raise NetcdfError, "variable type isn't supported in netCDF" end else hash.key?("end")==true && hash.key?("stride")==true if self.vartype == "char" put_vars_char(var,hash["start"],hash["end"],hash["stride"]) elsif self.vartype=="byte" put_vars_byte(var,hash["start"],hash["end"],hash["stride"]) elsif self.vartype=="sint" put_vars_sint(var,hash["start"],hash["end"],hash["stride"]) elsif self.vartype=="int" put_vars_int(var,hash["start"],hash["end"],hash["stride"]) elsif self.vartype=="sfloat" put_vars_sfloat(var,hash["start"],hash["end"],hash["stride"]) elsif self.vartype=="float" put_vars_float(var,hash["start"],hash["end"],hash["stride"]) else raise NetcdfError, "variable type isn't supported in netCDF" end end else raise ArgumentError,"{'start'}=>[ARRAY] or {'index'}=>[ARRAY] is needed" end end alias put simple_put def simple_get(hash=nil) t_var = self.vartype if hash == nil if t_var == "char" get_var_char elsif t_var == "byte" get_var_byte elsif t_var == "sint" get_var_sint elsif t_var == "int" get_var_int elsif t_var == "sfloat" get_var_sfloat elsif t_var == "float" get_var_float else raise NetcdfError, "variable type #{t_var} isn't supported in netCDF" end elsif hash.key?("index")==true ind = hash["index"] if t_var == "char" get_var1_char(ind) elsif t_var == "byte" get_var1_byte(ind) elsif t_var == "sint" get_var1_sint(ind) elsif t_var == "int" get_var1_int(ind) elsif t_var == "sfloat" get_var1_sfloat(ind) elsif t_var == "float" get_var1_float(ind) else raise NetcdfError,"variable type #{t_var} isn't supported in netCDF" end elsif hash.key?("start")==true h_sta = hash["start"] h_end = hash["end"] # can be nill h_str = hash["stride"] # can be nill if NetCDF.nc4? && h_str && ((xstr=h_str[0]) != 1) # Tentative treatment for the very slow netcdf-4 reading with step. # Reading with step is generally slow with NetCDF 4, but it is # particularly so for the first dimension. # Ref: http://www.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/2013/msg00311.html h_str[0] = 1 nc4remedy = true else nc4remedy = false end if t_var == "char" v = get_vars_char(h_sta,h_end,h_str) elsif t_var == "byte" v = get_vars_byte(h_sta,h_end,h_str) elsif t_var == "sint" v = get_vars_sint(h_sta,h_end,h_str) elsif t_var == "int" v = get_vars_int(h_sta,h_end,h_str) elsif t_var == "sfloat" v = get_vars_sfloat(h_sta,h_end,h_str) elsif t_var == "float" v = get_vars_float(h_sta,h_end,h_str) else raise NetcdfError, "variable type #{t_var} isn't supported in netCDF" end if nc4remedy idx = [] (0...v.shape[0]).step(xstr){|k| idx.push(k)} v = v[idx,false] end v else raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed" end end alias get simple_get def __rubber_expansion( args ) if (id = args.index(false)) # substitution into id # false is incuded alen = args.length if args.rindex(false) != id raise ArguemntError,"only one rubber dimension is permitted" elsif alen > rank+1 raise ArgumentError, "too many args" end ar = ( id!=0 ? args[0..id-1] : [] ) args = ar + [true]*(rank-alen+1) + args[id+1..-1] elsif args.length == 0 # to support empty [], []= args = [true]*rank end args end private :__rubber_expansion def [](*a) if a.length == 0 return self.get end a = __rubber_expansion(a) first = Array.new last = Array.new stride = Array.new set_stride = false a.each{|i| if(i.is_a?(Fixnum)) first.push(i) last.push(i) stride.push(1) elsif(i.is_a?(Range)) first.push(i.first) last.push(i.exclude_end? ? i.last-1 : i.last) stride.push(1) elsif(i.is_a?(Hash)) r = (i.to_a[0])[0] s = (i.to_a[0])[1] if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) ) raise TypeError, "Hash argument must be {a_Range, step}" end first.push(r.first) last.push(r.exclude_end? ? r.last-1 : r.last) stride.push(s) set_stride = true elsif(i.is_a?(TrueClass)) first.push(0) last.push(-1) stride.push(1) elsif( i.is_a?(Array) || i.is_a?(NArray)) a_new = a.dup at = a.index(i) i = NArray.to_na(i) if i.is_a?(Array) for n in 0..i.length-1 a_new[at] = i[n]..i[n] na_tmp = self[*a_new] if n==0 then k = at if at > 0 a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end} end shape_tmp = na_tmp.shape shape_tmp[k] = i.length na = na_tmp.class.new(na_tmp.typecode,*shape_tmp) index_tmp = Array.new(shape_tmp.length,true) end index_tmp[k] = n..n na[*index_tmp] = na_tmp end return na else raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray" end } if(set_stride) na = self.get({"start"=>first, "end"=>last, "stride"=>stride}) else na = self.get({"start"=>first, "end"=>last}) end shape = na.shape (a.length-1).downto(0){ |i| shape.delete_at(i) if a[i].is_a?(Fixnum) } na.reshape!( *shape ) na end def []=(*a) val = a.pop a = __rubber_expansion(a) first = Array.new last = Array.new stride = Array.new set_stride = false a.each{|i| if(i.is_a?(Fixnum)) first.push(i) last.push(i) stride.push(1) elsif(i.is_a?(Range)) first.push(i.first) last.push(i.exclude_end? ? i.last-1 : i.last) stride.push(1) elsif(i.is_a?(Hash)) r = (i.to_a[0])[0] s = (i.to_a[0])[1] if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) ) raise ArgumentError, "Hash argument must be {first..last, step}" end first.push(r.first) last.push(r.exclude_end? ? r.last-1 : r.last) stride.push(s) set_stride = true elsif(i.is_a?(TrueClass)) first.push(0) last.push(-1) stride.push(1) elsif(i.is_a?(Array) || i.is_a?(NArray)) a_new = a.dup at = a.index(i) i = NArray.to_na(i) if i.is_a?(Array) val = NArray.to_na(val) if val.is_a?(Array) rank_of_subset = a.dup.delete_if{|v| v.is_a?(Fixnum)}.length if val.rank != rank_of_subset raise "rank of the rhs (#{val.rank}) is not equal to the rank "+ "of the subset specified by #{a.inspect} (#{rank_of_subset})" end k = at a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end} if i.length != val.shape[k] raise "length of the #{k+1}-th dim of rhs is incorrect "+ "(#{i.length} for #{val.shape[k]})" end index_tmp = Array.new(val.rank,true) if !val.is_a?(Numeric) #==>Array-like for n in 0..i.length-1 a_new[at] = i[n]..i[n] if !val.is_a?(Numeric) then index_tmp[k] = n..n self[*a_new] = val[*index_tmp] else self[*a_new] = val end end return self else raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray" end } if(set_stride) self.put(val, {"start"=>first, "end"=>last, "stride"=>stride}) else self.put(val, {"start"=>first, "end"=>last}) end end def inspect 'NetCDFVar:'+file.path+'?var='+name end end class NetCDFAtt def put(val,atttype=nil) putraw(val,atttype) end def inspect 'NetCDFAtt:'+name end end class NetCDFDim def inspect 'NetCDFDim:'+name end def length_ul0 if unlimited? 0 else length end end end end ruby-netcdf-0.7.2/lib/numru/netcdf_miss.rb0000644000175000017500000001377312772251340020353 0ustar uwabamiuwabamirequire "numru/netcdf" require "narray_miss" module NumRu class NetCDFVar def get_with_miss(*args) __interpret_missing_params if !defined?(@missval) data = simple_get(*args) if @vmin || @vmax if @vmin mask = (data >= @vmin) mask = mask.and(data <= @vmax) if @vmax else mask = (data <= @vmax) end data = NArrayMiss.to_nam(data, mask) elsif @missval # only missing_value is present. mask = (data.ne(@missval)) data = NArrayMiss.to_nam(data, mask) end data end def get_with_miss_and_scaling(*args) __interpret_missing_params if !defined?(@missval) data = simple_get(*args) if @vmin || @vmax if @vmin mask = (data >= @vmin) mask = mask.and(data <= @vmax) if @vmax else mask = (data <= @vmax) end data = NArrayMiss.to_nam(data, mask) elsif @missval # only missing_value is present. mask = (data.ne(@missval)) data = NArrayMiss.to_nam(data, mask) end data = unpack( data ) data end def put_with_miss(data, *args) if data.is_a?( NArrayMiss ) __interpret_missing_params if !defined?(@missval) if @missval simple_put(data.to_na(@missval), *args) else simple_put(data.to_na, *args) end else simple_put(data, *args) end end def put_with_miss_and_scaling(data, *args) if data.is_a?( NArrayMiss ) __interpret_missing_params if !defined?(@missval) if @missval data = pack( data ) data = data.to_na(@missval) else data = pack( data ) data = data.to_na end simple_put(data, *args) else scaled_put(data, *args) end end ######### private ########## def __interpret_missing_params # Interprets the specification of missing data, # either by valid_range, (valid_min and/or valid_max), or missing_value. # (unlike the NetCDF User's guide (NUG), missing_value is interpreted, # but valid_* has a higher precedence.) # Always sets @missval whether missing_value is defined or not, # since it will be used as a fill value for data missing. # @vmin = att('valid_min') @vmin = @vmin.get if @vmin # kept in a NArray(size==1) to consv type @vmax = att('valid_max') @vmax = @vmax.get if @vmax # kept in a NArray(size==1) to consv type vrange = att('valid_range') vrange = vrange.get if vrange if vrange vrange.sort! @vmin = vrange[0..0] # kept in... (same) @vmax = vrange[-1..-1] # kept in... (same) end @missval = att('missing_value') || att('_FillValue') @missval = @missval.get if @missval # kept in... (same) sf = att('scale_factor') ao = att('add_offset') if ( sf || ao ) ## Both NUG & CF conventions requires to specify the valid ## range with respect to the external (i.e. packed) values. ## However, some conventions require specification ## with respect to unpacked values. The following ## is to support such cases as well: thres_tp = [ self.typecode, NArray::LINT ].max @missval = pack(@missval) if @missval && @missval.typecode > thres_tp @vmin = pack(@vmin) if @vmin && @vmin.typecode > thres_tp @vmax = pack(@vmax) if @vmax && @vmax.typecode > thres_tp end if @missval if @vmin && @vmax if @vmin[0] <= @missval[0] && @missval[0] <= @vmax[0] warn "WARNING: missing_value #{@missval[0]} is in the valid range #{@vmin[0]}..#{@vmax[0]} --> will be ignored (#{__FILE__}:#{__LINE__})" end else if @vmin && @missval[0] >= @vmin[0] warn "WARNING: missing_value #{@missval[0]} >= valid min #{@vmin[0]} --> will be ignored (#{__FILE__}:#{__LINE__})" elsif @vmax && @missval[0] <= @vmax[0] warn "WARNING: missing_value #{@missval[0]} <= valid min #{@vmin[0]} --> will be ignored (#{__FILE__}:#{__LINE__})" end end else realtc = NArray::SFLOAT if @vmin if @vmin[0] >= 0 @missval = ( @vmin.typecode>=realtc ? 0.99*@vmin : @vmin-1 ) else @missval = ( @vmin.typecode>=realtc ? 1.01*@vmin : @vmin-1 ) end elsif @vmax if @vmax[0] >= 0 @missval = ( @vmax.typecode>=realtc ? 1.01*@vmax : @vmax+1 ) else @missval = ( @vmax.typecode>=realtc ? 0.99*@vmax : @vmax+1 ) end end end end private :__interpret_missing_params end end if $0 == __FILE__ include NumRu filename = "tmp.nc" print "creating ",filename,"...\n" file=NetCDF.create(filename) nx = 10 dimx = file.def_dim("x",nx) xf = file.def_var("xf","sfloat",[dimx]) xfn = file.def_var("xfn","sfloat",[dimx]) xf.put_att("valid_range",[-1e12,1e12]) f = 10 ** (2*NArray.sfloat(nx).indgen!) xr = file.def_var("xr","sint",[dimx]) xr.put_att("valid_max",[0.5]) xr.put_att("scale_factor",1e-4) xr.put_att("add_offset",0.5) xr2 = file.def_var("xr2","sint",[dimx]) xr2.put_att("valid_max",NArray.sint(1).fill!(1000)) xr2.put_att("scale_factor",1e-4) xr2.put_att("add_offset",0.5) r = NArray.sfloat(nx).indgen!/nx file.enddef xf.put(f) xfn.put(f) xr.scaled_put(r) file.close file = NetCDF.open(filename,'r+') xf = file.var('xf') xfn = file.var('xfn') p "f0" xf.get.each{|v| print "#{v} "} ; print "\n" p( 'f1', nam = xf.get_with_miss ) def xf.get(*args); get_with_miss(*args); end p( 'f12', xf[2..-3].to_na ) p( 'fn10', xfn.get_with_miss ) p( 'fn11', xfn.get_with_miss_and_scaling ) nam.invalidation([0,1]) p 'f2', nam xf.put_with_miss(nam) p( 'f3', xf.get_with_miss ) xr = file.var('xr') p "r0" xr.simple_get.each{|v| print "#{v} "} ; print "\n" p( 'r1', xr.get_with_miss_and_scaling ) def xr.get(*args); get_with_miss_and_scaling(*args); end def xr.put(*args); put_with_miss_and_scaling(*args); end #xr[0..3] = xr[0..3]*10 p( 'r2', xr.get_with_miss_and_scaling ) p 'r',r xr2.put_with_miss_and_scaling(r) p 'xr2',xr2.get_with_miss_and_scaling file.close print "** ncdump tmp.nc **\n", `ncdump tmp.nc` end ruby-netcdf-0.7.2/lib/numru/netcdf/0000755000175000017500000000000012772251340016760 5ustar uwabamiuwabamiruby-netcdf-0.7.2/lib/numru/netcdf/version.rb0000644000175000017500000000007612772251340020775 0ustar uwabamiuwabamimodule NumRu class NetCDF VERSION = "0.7.2" end end ruby-netcdf-0.7.2/doc/0000755000175000017500000000000012772251340014346 5ustar uwabamiuwabamiruby-netcdf-0.7.2/doc/Ref_man.html0000644000175000017500000017600212772251340016611 0ustar uwabamiuwabami Untitled

RubyNetCDF Reference Manual

RubyNetCDF version : 0.7.1

---------------------------------------------

Overview

RubyNetCDF is the Ruby interface of the NetCDF library. Ruby is a free object-oriented scripting language and is freely available from the Ruby homepage. To handle numeric data, RubyNetCDF uses NArray, which is the standard numeric multi-dimensional array class for Ruby. Thus, you have to have installed it before installing this library. An NArray object holds numeric data in a consecutive memory area pointed by a C pointer. Thus, it is computationally efficient. NArray is similar to NumPy for Python, but results of some benchmark tests suggests that NArray is more efficient than NumPy. Optionally, RubyNetCDF offers methods to handle data missing automatically. To use it, you will also need NArrayMiss. See Usage for details.

Currently, NetCDF-4 support is partial (the new data models have not been supported).

Structure

RubyNetCDF consists of the four classes in the following.

  • class NetCDF -- the file class

    An NetCDF object represents a NetCDF file

  • class NetCDFDim -- the dimension class

    Although in its C version a NetCDF dimension is represented by a combination of a file ID and a dimension ID, it is represented by only one NetCDFDim object in RubyNetCDF.

  • class NetCDFVar -- the variable class

    Although in its C version a NetCDF variable is represented by a combination of a file ID and a variable ID, it is represented by only one NetCDFVar object in RubyNetCDF.

  • class NetCDFAtt -- the attribute class

    Although in its C version a NetCDF attribute is represented by a combination of file ID, variable ID, and its name, it is represented by only one NetCDFAtt object in RubyNetCDF.

Data type

All the NetCDF variable types char, byte, short, int, float, and double are supported in this Ruby interface. These types are called, however, differently in it to adhere to the convention of Ruby, or, more specifically, of NArray. These types are named to as "char", "byte", "sint", "int", "sfloat", and "float", respectively. Therefore, the vartype (=ntype) method of the NetCDFVar class returns one of these strings. The def_var method of the NetCDF class also accepts one of them to define a variable. It should be noted especially that "float" in this library means the double in the NetCDF terminology. This is due to the convention of Ruby -- the predefined Float class corresponds to the double in C, not the float.

The "get" method of NetCDFVar class reads a variable in a NArray of the same type as in the file, except for the "char" type which is read into a "byte". This is because NArray does not have a "char" type. However, it not is not supposed to be a problem, since a byte NArray can easily handle string data.

Error handling

Errors are basically handled by raising exceptions. However, light errors in value-returning methods are handled by returning nil (e.g., if a non-existent attribute name is specified in attribute reading). Those methods that return nil on error are explicitly written as such in the following.

Security features

Security handling is done just as in the pre-defined File class.

Usage

To use the RubyNetCDF library, load the library first by placing the following line in your Ruby program to load the library:

require 'numru/netcdf'

If you want to use automatic data-missing-handling methods (of NetCDFVar class), use the following:

require 'numru/netcdf_miss'

This will call require 'numru/netcdf' inside at the beginning, so you do not have to call the both. The missing-data handling is done with NArrayMiss, so you have have installed it. This is, however, not needed if you only call require 'numru/netcdf'.

Here, 'numru', which stands for "Numerical Ruby", is the name of the subdirectory in the user's load path where the RubyNetCDF library is placed. Then, it can be used as in the following:

file = NumRu::NetCDF.create('tmp.nc')
x = file.def_dim('x',10)
y = file.def_dim('y',10)
v = file.def_var('v','float',[x,y])
file.close

Here, NumRu is the module that has the library in it. The reason why NetCDF library is wrapped in such a module is to avoid conflicts in the name space. Without this kind of treatment, problems happen if the user wants to use a library that happens to have a class or module with the same name as even one of the classes in this library.

If such a problem is not expected to happen, the prefix "NumRu::" can be eliminated by "including" the NumRu module as in the following, so that to place "NumRu::" is not needed anymore in the current scope:

include NumRu
file = NetCDF.create('tmp.nc')
...

For more examples, see demo and test programs included in the distribution package.

---------------------------------------------

How to read this manual

method_name(argument1, argument2, ...) -- arguments that can be omitted are expressed as Argument_name=Default_value

Explanation of its function

Arguments

  • name of argument1 (its class or possible values): explanation
  • name of argument2 (its class or possible values): explanation
  • ...

Return value

  • Explanation of the return value

Corresponding (dependent) function(s) in the C library of NetCDF

  • Name(s) in NetCDF ver 3. The function equivalent to the current method, if not in parenthesis. If no direct correspondence, dependent functions are listed in parentheses.

---------------------------------------------

Method Index

  • class NetCDF

    Class Methods

    Instance Methods

    • close Closes the file.
    • ndims Returns the number of dimensions in the file
    • nvars Returns the number of variables in the file
    • natts Returns the number of global attributes in the file
    • unlimited Returns the unlimited dimension in the file
    • path Returns the path of the file (contents of the filename specified when opened/created)
    • redef Switches to the define mode. Does nothing if already in it (nil returned).
    • enddef Switches to the data mode. Does nothing if already in it (nil returned).
    • define_mode? Inquire whether the file is in the define mode.
    • sync Synchronizes the disk copy of a netCDF dataset with in-memory buffer
    • def_dim Define a dimension
    • put_att Sets a global attribute
    • def_var Defines a variable
    • def_var_with_dim Same as def_var but defines dimensions first if needed
    • var Opens an existing variable in the file
    • vars Opens existing variables in the file
    • dim Opens an existing dimension in the file
    • dims Opens existing dimensions in the file
    • att Opens an existing global attribute in the file
    • fill= Sets a fill mode. (Default behavior of NetCDF is FILL.)
    • each_dim Iterator regarding the dimensions in the file.
    • each_var Iterator regarding the variables in the file.
    • each_att Iterator regarding the global attributes of the file.
    • dim_names Returns the names of all dimensions in the file
    • var_names Returns the names of all variables in the file
    • att_names Returns the names of all the global attributes of the file
  • class NetCDFDim

    Class Methods

    Instance Methods

    • length Returns the length of the dimension
    • length_ul0 Same as length but returns 0 for the unlimited dimension
    • name= Rename the dimension
    • name Returns the name of the dimension
    • unlimited? Inquires whether the dimension is unlimited or not
  • class NetCDFVar

    Class Methods

    Instance Methods

    • deflate Sets "deflation" (compression). (netCDF-4 only)
    • deflate_params Retuns present deflation parameters. (netCDF-4 only)
    • endian= Sets (changes) the endian. (netCDF-4 only)
    • endian Retunrs the present endian setting. (netCDF-4 only)
    • dim Inquires the dim_num-th dimension of the variable (dim_num=0,1,2,..)
    • dims Returns an array of all the dimensions of the variable
    • shape_ul0 Returns the shape of the variable, but the length of the unlimited dimension is set to zero.
    • shape_current Returns the current shape of the variable.
    • each_att Iterator regarding the global attributes of the variables.
    • dim_names Returns the names of all the dimensions of the variable
    • att_names Returns the names of all the attributes of the variable
    • name Returns the name of the variable
    • name= Rename the variable
    • ndims Number of dimensions of the variable (which is rank of the variable).
    • rank aliased to ndims
    • ntype Aliased to vartype
    • vartype Inquires the data value type of the variable
    • typecode Inquires the data type of the variable (returns a typecode of NArray)
    • natts Returns the number of the attributes of the variable
    • file Inquires the file that the variable is in
    • att Returns the attribute specified by its name
    • put_att Sets an attribute
    • put Aliased to simple_put
    • simple_put Set the values of the variable
    • pack Pack a NArray (etc) using the attributes scale_factor and/or add_offset of self.
    • scaled_put Same as simple_put but interprets the attributes scale_factor and/or add_offset using pack.
    • get Aliased to simple_get
    • simple_get Returns values of the variable
    • unpack Unpack a NArray (etc) using the attributes scale_factor and/or add_offset of self.
    • scaled_get Same as simple_get but interprets the attributes scale_factor and/or add_offset using unpack.
    • [] Same as NetCDFVar#get but a subset is specified as in the method [] of NArray.
    • []= Same as NetCDFVar#put but a subset is specified as in the method []= of NArray.

    Instance Methods added by requiring "numru/netcdf_miss"

  • class NetCDFAtt

    Class Methods

    Instance Methods

    • name Returns the name of the attribute
    • name= Rename the attribute
    • copy Copies an attribute to a variable or a file. If file, becomes an global attribute
    • delete Delete an attribute
    • put Sets the value of the attribute
    • get Returns the values of the attribute
    • atttype Inquires the type of attribute values
    • typecode Inquires the type of attribute values (returns a NArray typecode)

---------------------------------------------

class NetCDF

constants

  • NC_NOWRITE, NC_WRITE, NC_SHARE, NC_CLOBBER, NC_NOCLOBBER, NC_64BIT_OFFSET, NC_NETCDF4, NC_CLASSIC_MODEL, NCVERSION, SUPPORT_BIGMEM : these constants can accessed by NumRu::NetCDF::NC_NOWRITE etc.

Class Methods

NetCDF.nc4?

Returens wheather the linked NetCDF library is NetCDF-4 (true/false). false means that it is version 3.

NetCDF.creation_format=(cmode)

(Available only when NetCDF version 4 is used. Error is raised if not.) Set the file format created by NetCDF.create. The initial setting is "classic" (conventional netcdf 3 format).

Arguments

  • cmode : one of the following:
    • 0, nil, or NetCDF::NC_CLASSIC_MODEL : the classic format (original NetCDF-3 format). This is the default setting of RubyNetCDF.
    • NetCDF::NC_64BIT_OFFSET : classic but supports larger variables
    • NetCDF::NC_NETCDF4 : The new NetCDF-4 format based on HDF5
    • ( NetCDF::NC_NETCDF4 | NetCDF::NC_CLASSIC_MODEL) [bit "or" of NetCDF::NC_NETCDF4 and NetCDF::NC_CLASSIC_MODEL ]: the new NetCDF-4 format but new data models are disabled.

NetCDF.creation_format

(Available only when NetCDF version 4 is used. Error is raised if not.) Returns the current setting of the creation format.

NetCDF.open(filename, mode="r", share=false)

Opens a file (class method). If mode="w" and the file does not exist, a new file is created.

Arguments

  • filename (String): file name (path)
  • mode (String) : IO mode "r" (read only); "w","w+" (write -- current contents are overwritten (eliminated!)); "r+","a","a+" (append -- writable while current contents are preserved). All the options permit reading, unlike the predefined File class. Note that to "append" will require extra time and disk space due to the limitations of the original NetCDF library, which is used in this library.
  • share (true or false) : Whether to use the "shared" mode or not (set true if a file being written may be read from other processes. See nc_open in Ch.5 of users' guide of the C version)

Return value

  • a NetCDF object

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_open, nc_create

NetCDF.new

Aliased to NetCDF.open

NetCDF.create(filename, noclobber=false, share=false)

Creates a NetCDF file (class method)

Arguments

  • filename (String) : file name (path)
  • noclobber (true or false) : overwrite or not if the file exists
  • share (true or false) : Whether to use the shared mode or not (set true if a file being written may be read from other processes. See nc_open in Ch.5 of users' guide of the C version)

Return value

  • a NetCDF object

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_create

NetCDF.create_tmp(tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'.', share=false)

Creates a temporary NetCDF file (class method). Its name is automatically generated, and it is deleted when closed.

Arguments

  • tmpdir (String) : directory to place the temporary file. By default, "." or a directory specified by an environmental variable (TMPDIR or TMP or TEMP) is used. In a secure mode, theses environmental variable is NOT used, and the default value is '.'.
  • share (true or false) : Whether to use the shared mode or not

Return value

  • a NetCDF object

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_create

Instance Methods

close

Closes the file.

Arguments

  • (none)

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_close

ndims

Returns the number of dimensions in the file

Arguments

  • (none)

Return value

  • Integer

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_ndims

nvars

Returns the number of variables in the file

Arguments

  • (none)

Return value

  • Integer

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_nvars

natts

Returns the number of global attributes in the file

Arguments

  • (none)

Return value

  • Integer

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_natts

unlimited

Returns the unlimited dimension in the file

Arguments

  • (none)

Return value

  • a NetCDFDim if it exists; nil if not

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_unlimdim

path

Returns the path of the file (contents of the filename specified when opened/created)

Arguments

  • (none)

Return value

  • String

Corresponding (dependent) function(s) in the C library of NetCDF

  • (none)

redef

Switches to the define mode. Does nothing if already in it (nil returned).

Arguments

  • (none)

Return value

  • true if successfully switched to the define mode; nil if the file is already in the define mode. Exception is raised if unsuccessful for other reasons.

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_redef

enddef

Switches to the data mode. Does nothing if already in it (nil returned).

Arguments

  • (none)

Return value

  • true if successfully switched to the data mode; nil if the file is already in the data mode. Exception is raised if unsuccessful for other reasons.

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_enddef

define_mode?

Inquire whether the file is in the define mode.

Arguments

  • (none)

Return value

  • true if the data is in the define mode; false if the file is in the data mode; nil otherwise (possibly the file is read-only).

Corresponding (dependent) function(s) in the C library of NetCDF

  • combination of nc_redef and nc_enddef

sync

Synchronizes the disk copy of a netCDF dataset with in-memory buffer

Arguments

  • (none)

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_sync

def_dim(dimension_name, length)

Define a dimension

Arguments

  • dimension_name (String) : Name of the dimension to be defined
  • length (Integer) : length of the dimension. 0 for unlimited.

Return value

  • defined dimension (NetCDFDim object)

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_def_dim

put_att(attribute_name, value, atttype=nil)

Sets a global attribute

Arguments

  • attribute_name (String) : name of the global attribute
  • value (Numeric, String, Array of Numeric, or NArray) : value of the attribute
  • atttype (nil or String) : data type of the attribute value. nil lets it automatically determined from the value. "char" (or "string"), "byte", "sint", "int", "sfloat", or "float" specifies the type explicitly (1,1,2,4,4,8 bytes, respectively)

Return value

  • created attribute (NetCDFAtt object)

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_put_att_<type>

def_var(name, vartype, dimensions)

Defines a variable

Arguments

  • name (String) : Name of the variable to define
  • vartype (String or Fixnum) : data type of the variable ("char", "byte", "sint", "sint", "int", "sfloat", or "float"), or a NArray typecodes(Fixnum)
  • dimensions (Array) : Dimensions of the variable. An Array of NetCDFDim, in the order from the fastest varying dimension to the slowest varying one; its length becomes the rank of the variable.

Return value

  • defined variable (NetCDFVar object)

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_def_var

def_var_with_dim(name, vartype, shape_ul0, dimnames)

Same as def_var but defines dimensions first if needed. Raise exception if it conflicts with the lengths of existing dimensions.

Arguments

  • name (String) : Name of the variable to define
  • vartype (String) : data type of the variable ("char", "byte", "sint", "sint", "int", "sfloat", or "float")
  • shape_ul0 (Array of Integer) : Shape of the variable, i.e., lengths of dimensions. The unlimited dimension is specified by zero. The length of shape_ul0 determines the rank of the variable.
  • dimnames (Array of String) : Names of the dimensions. Its length (=>rank) must be equal to that of shape_ul0

Return value

  • defined variable (NetCDFVar object)

Corresponding (dependent) function(s) in the C library of NetCDF

  • (nc_def_var)

var(var_name)

Opens an existing variable in the file

Arguments

  • var_name (String) : Name of the variable to open

Return value

  • a NetCDFVar object; nil if the variable does not exist

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_varid

vars(names)

Opens existing variables in the file

Arguments

  • names (nil or Array of String): Names of the variables to open; all variables are returned if nil (default).

Return value

  • Array of NetCDFVar objects; exception is raised if names has a non-existent name

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_varid

dim(dimension_name)

Opens an existing dimension in the file

Arguments

  • dimension_name (String) : Name of the dimension to open

Return value

  • a NetCDFDim object; nil if the dimension does not exist

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_dimid

dims(names)

Opens existing dimensions in the file

Arguments

  • names (nil or Array of String): Names of the dimensions to open; all dimensions are returned if nil (default).

Return value

  • Array of NetCDFDim objects; exception is raised if names has a non-existent name

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_dimid

att(attribute_name)

Opens an existing global attribute in the file

Arguments

  • attribute_name (String) : Name of the global attribute to open

Return value

  • a NetCDFAtt object if the attribute exists; nil if not

Corresponding (dependent) function(s) in the C library of NetCDF

  • (nc_inq_attid used for inquiry)

fill=(filemode)

Sets a fill mode. (Default behavior of NetCDF is FILL.)

Arguments

  • fillmode (true or false)

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_set_fill

each_dim{ ... }

Iterator regarding the dimensions in the file. Ex.: {|i| print i.name,"\n"} prints names of all dimensions

Arguments

  • { ... } : Block for the iterator. A "do end" block is the alternative.

Return value

  • self

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_ndims)

each_var{ ... }

Iterator regarding the variables in the file. Ex.: {|i| print i.name,"\n"} prints names of all variables

Arguments

  • { ... } : Block for the iterator. A "do end" block is the alternative.

Return value

  • self

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_nvars)

each_att{ ... }

Iterator regarding the global attributes of the file. Ex.: {|i| print i.name,"\n"} prints names of all of them.

Arguments

  • { ... } : Block for the iterator. A "do end" block is the alternative.

Return value

  • self

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_natts, nc_inq_attname)

dim_names

Returns the names of all dimensions in the file

Arguments

  • (none)

Return value

  • Array of NetCDFDim

Corresponding (dependent) function(s) in the C library of NetCDF

  • (nc_inq_ndims, nc_inq_dimname)

var_names

Returns the names of all variables in the file

Arguments

  • (none)

Return value

  • Array of String

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_nvars, nc_inq_varname)

att_names

Returns the names of all the global attributes of the file

Arguments

  • (none)

Return value

  • Array of NetCDFAtt

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_natts, nc_inq_attname)

---------------------------------------------

class NetCDFDim

Class Methods

Instance Methods

length

Returns the length of the dimension

Arguments

  • (none)

Return value

  • Integer

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_dimlen

length_ul0

Same as length but returns 0 for the unlimited dimension

Arguments

  • (none)

Return value

  • Integer

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_dimlen

name=(dimension_newname)

Rename the dimension

Arguments

  • dimension_newname (String) : new name

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_rename_dim

name

Returns the name of the dimension

Arguments

  • (none)

Return value

  • String

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_dimname

unlimited?

Inquires whether the dimension is unlimited or not

Arguments

  • (none)

Return value

  • true or false

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_unlimdim)

---------------------------------------------

class NetCDFVar

Class Methods

NetCDFVar.new(file,varname,mode="r",share=false)

open a NetCDF variable. This can also be done with NetCDF#var (instance method of NetCDF class), which is recommended over this method.

Arguments

  • file (NetCDF or String) : a NetCDF file object (NetCDF) or the path of a NetCDF file (String).
  • varname (String) : name of the variable in the file
  • mode (String) : IO mode -- used if file is a String (see NetCDF.open)
  • share (true or false) : Whether to use the "shared" mode or not -- used if file is a String (see NetCDF.open)

Return value

  • a NetCDFVar object

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_open, nc_create, nc_inq_varid etc.)

NetCDFVar.unpack_type=(na_type)

Fix the NArray type to be used in unpack.

Arguments

  • na_type (Integer) : NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, or NArray::FLOAT

Return value

  • na_type (the argument)

NetCDFVar.unpack_type

Returns the NArray type set by NetCDFVar.unpack_type=.

Return value

  • nil, NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, or NArray::FLOAT

Instance Methods

deflate(deflate_level, shuffle=false)

(Available only when NetCDF version 4 is used. Error is raised if not.) Makes the current (newly created) variable "deflated" (=compressed). This method must be called after defining a variable (NetCDF#def_var) and before calling NetCDF#enddef.

Arguments

  • deflate_level (Integer) :: 0 to 9. (0: no compression; 9: highest compression; recommended: 1 or 2).
  • shuffle (optional; true or false; default: false) if true, turn on the shuffle filter.
    • <URL:http://www.unidata.ucar.edu/software/netcdf/papers/AMS_2008.pdf>: ``The shuffle algorithm changes the byte order in the data stream; when used with integers that are all close together, this results in a better compression ratio. There is no benefit from using the shuffle filter without also using compression.''
    • Note: shuffle is effective for float variables too (tested by horinouchi).

Return value

  • self

deflate_params

(Available only when NetCDF version 4 is used. Error is raised if not.) Returns the present deflation parameters.

Return value

  • [shuffle, deflate, deflate_level] (a 3-element Array), where the values of shuffle and deflate are true or false, and deflate_level is an Integer (0-9).

endian=(endian)

(Available only when NetCDF version 4 is used. Error is raised if not.) Sets (changes) the endian. See deflate for when to use it.

Arguments

  • endian : one of the following constants: NetCDF::NC_ENDIAN_NATIVE (=0) (default), NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2).

Return value

  • self

endian

(Available only when NetCDF version 4 is used. Error is raised if not.) Returns the current endian setting.

Return value

  • one of the following constants: NetCDF::NC_ENDIAN_NATIVE (=0) (default), NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2).

dim(dim_num)

Inquires the dim_num-th dimension of the variable (dim_num=0,1,2,..)

Arguments

  • dim_num (Fixnum) : 0,1,... 0 is the fastest varying dimension.

Return value

  • a NetCDFDim object

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_vardimid)

dims

Returns an array of all the dimensions of the variable

Arguments

  • (none)

Return value

  • Array of NetCDFDim objects.

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_vardimid

shape_ul0

Returns the shape of the variable, but the length of the unlimited dimension is set to zero. Good to define another variable.

Arguments

  • (none)

Return value

  • Array. [length of 0th dim, length of 1st dim,.. ]

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_vardimid, nc_inq_unlimdim etc)

shape_current

Returns the current shape of the variable.

Arguments

  • (none)

Return value

  • Array. [length of 0th dim, length of 1st dim,.. ]

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_vardimid etc)

each_att{ ... }

Iterator regarding the global attributes of the variables. Ex.: {|i| print i.name,"\n"} prints names of all of them.

Arguments

  • { ... } : Block for the iterator. A "do end" block is the alternative.

Return value

  • self

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_natts, nc_inq_attname)

dim_names

Returns the names of all the dimensions of the variable

Arguments

  • (none)

Return value

  • Array of String

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_varndims, nc_inq_vardimid, nc_inq_dimname)

att_names

Returns the names of all the attributes of the variable

Arguments

  • (none)

Return value

  • Array of String

Corresponding (dependent) function(s) in the C library of NetCDF

  • (dependent on nc_inq_natts, nc_inq_attname)

name

Returns the name of the variable

Arguments

  • (none)

Return value

  • String

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_varname

name=(variable_newname)

Rename the variable

Arguments

  • variable_newname (String) : new name

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_rename_var

ndims

Number of dimensions of the variable (which is rank of the variable).

Arguments

  • (none)

Return value

  • Integer

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_varndims

rank

Aliased to ndims

ntype

Aliased to vartype

vartype

Inquires the data value type of the variable

Arguments

  • (none)

Return value

  • String ("char","byte","sint","int","sfloat", or "float")

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_vartype

typecode

Inquires the data type of the variable (returns a typecode of NArray)

Arguments

  • (none)

Return value

  • a Fixnum (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT)

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_vartype

natts

Returns the number of the attributes of the variable

Arguments

  • (none)

Return value

  • Integer

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_varnatts

file

Inquires the file that the variable is in

Arguments

  • (none)

Return value

  • a NetCDF object

Corresponding (dependent) function(s) in the C library of NetCDF

  • (none)

att(attribute_name)

Returns the attribute specified by its name

Arguments

  • attribute_name (String) : Name of the attribute

Return value

  • a NetCDFAtt object if the attribute exists; nil if not

Corresponding (dependent) function(s) in the C library of NetCDF

  • (nc_inq_attid is used for inquiry)

put_att(attribute_name, value, atttype=nil)

Sets an attribute

Arguments

  • attribute_name (String) : name of the attribute
  • value (Numeric, String, Array of Numeric, or NArray) : value of the attribute
  • atttype (nil or String) : data type of the attribute value. nil lets it automatically determined from the value. "char" (="string"), "byte", "sint", "int", "sfloat", or "float" specifies the type explicitly (1,1,2,4,4,8 bytes, respectively)

Return value

  • a NetCDFAtt object

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_put_att_<type>

put(value, option=nil)

Aliased to simple_put

simple_put(value, option=nil)

Set the values of the variable

Arguments

  • value : value to set (Numeric, Array of Numeric (1D only), or NArray (possibly multi-D)). If it is a Numeric or length==1, the value is set uniformly.
  • option (Hash) : Optional argument to limit the portion of the variable to output values. If omitted, the whole variable is subject to the output. This argument accepts a Hash whose keys contain either "index" or a combination of "start","end", and "stride". The value of "index" points the index of a scalar portion of the variable. The other case is used to designate a regularly ordered subset, where "start" and "end" specifies bounds in each dimension and "stride" specifies intervals in it. As in Array "start", "end", and "index" can take negative values to specify index backward from the end. However, "stride" has to be positive, so reversing the array must be done afterwards if you like.

    Example: If the variable is 2D:

    {"start"=>[2,5],"end"=>[6,-1],"stride"=>[2,4]} -- Specifies a subset made as follows: the 1st dimension from the element 2 to the element 6 (note that the count starts with 0, so that the element 2 is the 3rd one) with an interval of 2; the 2nd dimension from the element 6 to the last element (designated by -1) with an interval of 5.

    {"index"=>[0,0]}: Scalar of the fist element

    {"index"=>[0,-2]}: Scalar from the 1st element of with respect to the 1st dimension and the 2nd element from the last with respect to the 2nd dimension

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_put_var_<type>, nc_put_vars_<type>, nc_put_var1_<type>

pack(na)

Pack a NArray (etc) using the attributes scale_factor and/or add_offset of self.

If scale_factor and/or add_offset is defined, returns (na-add_offset)/scale_factor. Returns na if not.

Arguments

  • na : a numeric array to pack (NArray, NArrayMiss, or Array)

Return value

  • a NArray or NArrayMiss

scaled_put(value, option=nil)

Same as simple_put but interprets the attributes scale_factor and/or add_offset using pack.

See the document for simple_put for arguments etc.

get(option=nil)

Aliased to simple_get.

simple_get(option=nil)

Returns values of the variable

Arguments

  • option (Hash) : Optional argument to limit the portion of the variable to get values. Its usage is the same as in the method put.

Return value

  • an NArray object

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_get_var_<type>, nc_get_vars_<type>, nc_get_var1_<type>

unpack(na)

Unpack a NArray (etc) using the attributes scale_factor and/or add_offset of self.

If scale_factor and/or add_offset is defined, returns na * scale_factor + add_offset. Returns na if not. Type conversion is made by the coercing -- for example if na is sint and scale_factor and add_offset is sfloat, return value is sfloat. The type of the return value can be specified explicitly with NetCDFVar.unpack_type=.

Arguments

  • na : a numeric array to unpack (NArray, or NArrayMiss)

Return value

  • a NArray or NArrayMiss

scaled_get(option=nil)

Same as simple_get but interprets the attributes scale_factor and/or add_offset using unpack.

See the document for simple_get for arguments etc.

[]

Same as NetCDFVar#get but a subset is specified as in the method [] of NArray.

In addition to the subset specifications supported by NArray, ranges with steps are supported, which is specified like {0..-1, 3}, i.e., a 1-element Hash with the key and value representing the range (Range) and the step (Integer), respectively. Unlike NArray, 1-dimensional indexing of multi-dimensional variables is not support.

[] =

Same as NetCDFVar#put but a subset is specified as in the method []= of NArray.

In addition to the subset specifications supported by NArray, ranges with steps are supported, which is specified like {0..-1, 3}, i.e., a 1-element Hash with the key and value representing the range (Range) and the step (Integer), respectively. Unlike NArray, 1-dimensional indexing of multi-dimensional variables is not support.

Instance Methods added by requiring "numru/netcdf_miss"

get_with_miss(option=nil)

Same as get but interprets data missing.

Data missing is specified by the standard attributes valid_range, (valid_min and/or valid_max), or missing_value, with the precedence being this order. Unlike the recommendation in the NetCDF User's guide, missing_value is interpreted if present. If missing_value and valid_* present simultaneously, missing_value must be outside the valid range. Otherwise, exception is raised.

If data missing is specified as stated above, this method returns a NArrayMiss. If not, it returns a NArray. Thus, you can use this whether data missing is defined or not.

Arguments

Return value

  • an NArrayMiss (if data missing is specified) or an NArray (if data missing is NOT specified)

Possible exception in addition to NetcdfError.

  • missing_value is in the valid range (see above).

Corresponding (dependent) function(s) in the C library of NetCDF

  • See get. This method is written in Ruby.

EXAMPLE

  • The following is an example to replace get with get_with_miss. It will also make [] interpret data missing, since it calls get internally.

    file = NetCDF.open('hogehoge.nc')
    var = file.var('var')
    def var.get(*args); get_with_miss(*args); end
    p var.get       # --> interprets data missing if defined
    p var[0..-1,0]  # --> interprets data missing if defined (assumed 2D)

get_with_miss_and_scaling(option=nil)

Same as get_with_miss but handles data scaling too using unpack.

Missing data handling using valid_* / missing_value is applied basically to packed data, which is consistent with most conventions. However, it is applied to unpacked data if and only if the type of valid_* / missing_value is not the same as the packed data and is the samed as the unpacked data. This treatment can handle all conventions.

EXAMPLE

  • See above. The same thing applies.

put_with_miss(value, option=nil)

Same as put but interprets data missing.

If value is an NArray, the methods behaves as put. Data missing in value is interpreted if it is an NArrayMiss and data missing is specified by attributes in self (see get_with_miss ). Namely, the data which are "invalid" in the value is replaced with a missing value when written in the file. (missing_value or _FillValue or a value outside the valid range). No check is made whether "valid" values in the NArrayMiss is within the valid range of self.

Arguments

  • value : NArrayMiss or what is allowed in put.
  • option (Hash) : See put.

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • See put. This method is written in Ruby.

EXAMPLE

  • The following is an example to replace put with put_with_miss. It will also make []= interpret data missing, since it calls put internally.

    file = NetCDF.open('hogehoge.nc')
    var = file.var('var')
    def var.put(*args); put_with_miss(*args); end
    var.put = narray_miss      # --> interprets data missing if defined
    var[0..-1,0] = narray_miss # --> interprets data missing if defined (assumed 2D)

put_with_miss_and_scaling(value, option=nil)

Same as put_with_miss but handles data scaling too using pack.

Missing data handling using valid_* / missing_value is applied basically to packed data, which is consistent with most conventions. However, it is applied to unpacked data if and only if the type of valid_* / missing_value is not the same as the packed data and is the samed as the unpacked data. This treatment can handle all conventions.

EXAMPLE

  • See above. The same thing applies.

---------------------------------------------

class NetCDFAtt

Class Methods

Instance Methods

name

Returns the name of the attribute

Arguments

  • (none)

Return value

  • String

Corresponding (dependent) function(s) in the C library of NetCDF

  • (none)

name=(attribute_newname)

Rename the attribute

Arguments

  • attribute_newname (String) : New name

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_rename_att

copy(var_or_file)

Copies an attribute to a variable or a file. If file, becomes an global attribute

Arguments

  • var_or_file (NetCDFVar or NetCDF)

Return value

  • Resultant new attribute (NetCDFAtt)

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_copy_att

delete

Delete an attribute

Arguments

  • (none)

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_del_att

put(value, atttype=nil)

Sets the value of the attribute

Arguments

  • value (Numeric, String, Array of Numeric, or NArray) : value of the attribute
  • atttype (nil or String) : data type of the attribute value. nil lets it automatically determined from the value. "char" (="string"), "byte", "sint", "int", "sfloat", or "float" specifies the type explicitly (1,1,2,4,4,8 bytes, respectively)

Return value

  • nil

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_put_att_<type>

get

Returns the values of the attribute

Arguments

  • (none)

Return value

  • String or an NArray object (NOTE: even a scalar is returned as an NArray of length 1)

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_get_att_<type>

atttype

Inquires the type of attribute values

Arguments

  • (none)

Return value

  • "char","byte","sint","int","sfloat","float"

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_atttype

atttype

Inquires the type of attribute values (returns a NArray typecode)

Arguments

  • (none)

Return value

  • a Fixnum (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT)

Corresponding (dependent) function(s) in the C library of NetCDF

  • nc_inq_atttype
ruby-netcdf-0.7.2/doc/Ref_man_jp.html0000644000175000017500000020154012772251340017276 0ustar uwabamiuwabami Untitled

RubyNetCDF レファレンスマニュアル

RubyNetCDF version : 0.7.1

---------------------------------------------

概è¦

RubyNetCDF 㯠NetCDF ライブラリー㮠Ruby インターフェースã§ã‚る。Ruby ã¯ãƒ•リーãªã‚ªãƒ–ジェクト指å‘スクリプト言語ã§ã‚り〠ã“ã“ ã‹ã‚‰å…¥æ‰‹ã§ãる。RubyNetCDF ã¯æ•°å€¤é…列ã¨ã—ã¦ã€ Ruby ã§ä¸€èˆ¬çš„ã«ä½¿ã‚れã¦ã„る多次元数値é…列ライブラリー NArray を用るã®ã§ã€ã‚らã‹ã˜ã‚インストールã—ã¦ãŠãå¿…è¦ãŒã‚る。 NArray ã¯ãƒ‡ãƒ¼ã‚¿ã‚’ã€C ã®ãƒã‚¤ãƒ³ã‚¿ãƒ¼ãŒæŒ‡ã™é€£ç¶šã—ãŸãƒ¡ãƒ¢ãƒªãƒ¼é ˜åŸŸ ã«ä¿æŒã—ã€è¨ˆç®—機資æºã‚’効率よã利用ã™ã‚‹ã€‚NArray 㯠Python ã«ãŠã‘ã‚‹ NumPy ã¨ä¼¼ã‚‹ãŒã€å¹¾ã¤ã‹ã®ãƒ†ã‚¹ãƒˆã¯ NArray ã®ã»ã†ãŒ NumPy より効率ãŒè‰¯ã„ ã“ã¨ã‚’示唆ã—ã¦ã„る。 オプションã¨ã—ã¦ã€RubyNetCDF ã¯ãƒ‡ãƒ¼ã‚¿æ¬ æã®è‡ªå‹•çš„ãªå–り扱ã„メソッドを æä¾›ã™ã‚‹ã€‚ã“れを使ã†ã«ã¯ã€ NArrayMiss ãŒå¿…è¦ã§ã‚る。詳ã—ãã¯ä½¿ç”¨æ³•を見よ。

ç¾åœ¨ NetCDF-4 ã®ã‚µãƒãƒ¼ãƒˆã¯éƒ¨åˆ†çš„ã§ã‚ã‚‹(æ–°ã—ã„データモデルã¯ã‚µãƒãƒ¼ãƒˆã—ã¦ãªã„)。

æ§‹æˆ

RubyNetCDF ã¯ä»¥ä¸‹ã®ï¼”ã¤ã®ã‚¯ãƒ©ã‚¹ã‹ã‚‰æ§‹æˆã•れる。

  • クラス NetCDF -- ファイルã®ã‚¯ãƒ©ã‚¹

    一ã¤ã®NetCDFクラスã®ã‚ªãƒ–ジェクトã¯ä¸€ã¤ã® NetCDF ファイルã«å¯¾å¿œã™ã‚‹

  • クラス NetCDFDim -- 次元ã®ã‚¯ãƒ©ã‚¹

    C 版 NetCDF ã§ã¯ã€æ¬¡å…ƒã¯ã€ãƒ•ァイルã®IDã¨æ¬¡å…ƒIDã¨ã„ã†ï¼’変数ã®çµ„ã§è¡¨ã•れるãŒã€ Ruby 版ã§ã¯ä¸€ã¤ã® NetCDFDim オブジェクトã§ä»£è¡¨ã•れる

  • クラス NetCDFVar -- 変数ã®ã‚¯ãƒ©ã‚¹

    C 版 NetCDF ã§ã¯ã€å¤‰æ•°ã¯ã€ãƒ•ァイルã®IDã¨å¤‰æ•°IDã¨ã„ã†ï¼’変数ã®çµ„ã§è¡¨ã•れるãŒã€ Ruby 版ã§ã¯ä¸€ã¤ã® NetCDFVar オブジェクトã§ä»£è¡¨ã•れる

  • クラス NetCDFAtt -- 属性ã®ã‚¯ãƒ©ã‚¹

    C 版 NetCDF ã§ã¯ã€å±žæ€§ã¯ã€ãƒ•ァイルã®IDã¨å¤‰æ•°IDã¨å±žæ€§åã®çµ„ã§è¡¨ã•れるãŒã€ Ruby 版ã§ã¯ä¸€ã¤ã® NetCDFAtt オブジェクトã§ä»£è¡¨ã•れる

データ型

本ライブラリーã§ã¯å…¨ã¦ã® NetCDF 変数ã®åž‹ char, byte, short, int, float, double ãŒã‚µãƒãƒ¼ãƒˆã•れã¦ã„る。ã—ã‹ã—ã€ã“れら㯠Ruby ã®ï¼ˆã‚ˆã‚Šæ­£ç¢º ã«è¨€ã†ã¨ NArray ã®ï¼‰æ…£ä¾‹ã«å¾“ã£ã¦ã€ãれãžã‚Œ "char", "byte", "sint", "int", "sfloat", "float" ã¨å‘¼ã°ã‚Œã‚‹ã€‚従ã£ã¦ã€NetCDFVar クラス㮠vartype (=ntype) ã¯ã“ã‚Œã‚‰ã®æ–‡å­—列ã®ä¸€ã¤ã‚’è¿”ã™ã€‚ã¾ãŸã€NetCDFクラス㮠def_var メ ソッドã¯ã€å¤‰æ•°ã‚’定義ã™ã‚‹éš›ã€ã“れらをå—ã‘付ã‘ã‚‹ã€‚ç‰¹ã«æ³¨æ„ã™ã‚‹å¿…è¦ãŒã‚ã‚‹ ã®ã¯ã€æœ¬ãƒ©ã‚¤ãƒ–ラリーã§ã® "float" 㯠C ã§è¨€ã†ã¨ã“ã‚ã® double ã‚’æ„味ã™ã‚‹ ã¨ã„ã†ã“ã¨ã§ã‚る。ã“れ㯠Ruby ã®æ…£ä¾‹ã®ã›ã„ã§ã‚ã‚‹ -- 組ã¿è¾¼ã¿ã® Float クラスã¯ã€C ã® float ã§ãªã double ã«å¯¾å¿œã™ã‚‹ã®ã§ã‚る。

NetCDFVar クラス㮠get メソッドã¯ãƒ•ァイル中ã¨åŒã˜åž‹ã® NArray 変数ã«å€¤ を読ã¿è¾¼ã‚€ãŒã€"char" 型変数ã«ã¤ã„ã¦ã¯ "byte" åž‹ NArray ã«èª­ã¿è¾¼ã¾ã‚Œã‚‹ã€‚ ã“れ㯠NArray ㌠"char" 型をæŒãŸãªã„ã‹ã‚‰ã§ã‚る。ãŸã ã€ãã‚‚ãã‚‚ NArray 㯠byte åž‹ã§æ–‡å­—列を簡å˜ã«æ‰±ãˆã‚‹ã®ã§ã€ç‰¹ã«ä¸éƒ½åˆã¯ãªã„ã¨è€ƒãˆã‚‰ã‚Œã‚‹ã€‚

エラー処ç†

エラーã¯åŸºæœ¬çš„ã«ã¯ä¾‹å¤–を発生ã™ã‚‹ã“ã¨ã«ã‚ˆã‚Šå¯¾å‡¦ã™ã‚‹ã€‚但ã—ã€å€¤ã‚’è¿”ã™ãƒ¡ã‚½ãƒƒ ドã§ã¯è»½å¾®ãªã‚¨ãƒ©ãƒ¼ã¯ nil ã‚’è¿”ã™ã“ã¨ã§å¯¾å‡¦ã™ã‚‹ï¼ˆå±žæ€§å€¤ã‚’å¾—ã‚‹ãŸã‚ã«æŒ‡å®š ã•れãŸåå‰ã®å±žæ€§ãŒå­˜åœ¨ã—ãªã„ã¨ããªã©ï¼‰ã€‚例外的ãªçжæ³ã§ nil を発生ã™ã‚‹ メソッドã«ã¤ã„ã¦ã¯ãƒžãƒ‹ãƒ¥ã‚¢ãƒ«ã«æ˜Žè¨˜ã—ã¦ã‚る。

セキュリティ

組ã¿è¾¼ã¿ã® File クラスã¨åŒã˜ã‚»ã‚­ãƒ¥ãƒªãƒ†ã‚£ãƒ¼å¯¾å¿œã‚’ã—ã¦ã„ã¦ã‚‹ã€‚

使用法

RubyNetCDFライブラリーを利用ã™ã‚‹ãŸã‚ã«ã¯ã€ã¾ã𿬡ã®è¡Œã‚’ Ruby ãƒ—ãƒ­ã‚°ãƒ©ãƒ ã«æ›¸ã„ ã¦ãƒ©ã‚¤ãƒ–ラリーをロードã™ã‚‹å¿…è¦ãŒã‚る。

require 'numru/netcdf'

ã‚‚ã—ã‚‚ (NetCDFVarクラスã®) 自動的ãªãƒ‡ãƒ¼ã‚¿æ¬ æå‡¦ç†ãƒ¡ã‚½ãƒƒãƒ‰ã‚’使ã„ãŸã„å ´ åˆã¯ã€ä»¥ä¸‹ã‚’実行ã™ã‚‹å¿…è¦ãŒã‚る。

require 'numru/netcdf_miss'

ã“れã¯å†…部ã§ä¸€ç•ªæœ€åˆã« require 'numru/netcdf' を実行ã™ã‚‹ã®ã§ã€ ã“れã ã‘呼ã¹ã°è‰¯ã„。データ欠æã®æ‰±ã„㯠NArrayMiss ã«ã‚ˆã‚‹ã®ã§ã€ã“れをインストールã—ã¦ãŠã‹ã­ã°ãªã‚‰ãªã„。 ã‚‚ã—ã‚‚ require 'numru/netcdf' ã ã‘を呼ã¶ã®ãªã‚‰ã€NArrayMiss ã¯ä¸è¦ã§ã‚る。

ã“ã“ã§ã€'numru' ("Numerical Ruby"ã‹ã‚‰å–られãŸ) ã¯ãƒ¦ãƒ¼ã‚¶ãƒ¼ã®ãƒ©ã‚¤ãƒ–ラリー ロードパス中ã®ã‚µãƒ–ディレクトリーã§ã€RubyNetCDF ライブラリーãŒç½®ã‹ã‚Œã‚‹ã€‚ ã™ã‚‹ã¨ã€ä»¥ä¸‹ã®ã‚ˆã†ã«åˆ©ç”¨ã§ãるよã†ã«ãªã‚‹ã€‚

file = NumRu::NetCDF.create('tmp.nc')
x = file.def_dim('x',10)
y = file.def_dim('y',10)
v = file.def_var('v','float',[x,y])
file.close

ã“ã“ã§ã€NumRu ã¯ã“ã®ãƒ©ã‚¤ãƒ–ラリーをå«ã‚€ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§ã‚る。ã“ã®ã‚ˆã†ãªãƒ¢ã‚¸ãƒ¥ãƒ¼ ルã«ãã‚‹ã‚“ã§ã‚ã‚‹ã®ã¯ã€åå‰ç©ºé–“ã§ã®è¡çªã‚’é¿ã‘ã‚‹ãŸã‚ã§ã‚る。ã“ã®ã‚ˆã†ãªæ‰± ã„ã‚’ã—ãªã„å ´åˆã€ã‚‚ã—もユーザーãŒã€æœ¬ãƒ©ã‚¤ãƒ–ラリー中ã®ã‚¯ãƒ©ã‚¹ã¨åå‰ãŒè¡çª ã™ã‚‹ã‚¯ãƒ©ã‚¹ã‚„モジュールをå«ã‚€ãƒ©ã‚¤ãƒ–ラリーを使ãŠã†ã¨ã™ã‚‹ã¨ã€å•題ãŒèµ·ã‚‹ã€‚

ã“ã®ã‚ˆã†ãªå•題ãŒèµ·ã“らãªã„ã§ã‚ã‚ã†å ´åˆã¯ã€"NumRu::" ã¨ã„ã†å† ã¯ã€NumRu モジュールを「インクルードã€ã™ã‚‹ã“ã¨ã§å¤–ã›ã‚‹ï¼ˆç¾åœ¨ã®ã‚¹ã‚³ãƒ¼ãƒ—ã«ãŠã„ã¦ã¨ ã„ã†ã“ã§ã‚る)。従ã£ã¦æ¬¡ã®ã‚ˆã†ã«æ›¸ã‘る。

include NumRu
file = NetCDF.create('tmp.nc')
...

ã•らãªã‚‹ä½¿ç”¨ä¾‹ã¨ã—ã¦ã¯ãƒ€ã‚¦ãƒ³ãƒ­ãƒ¼ãƒ‰ç”¨ãƒ‘ッケージã«å«ã¾ã‚Œã‚‹ demo ã‚„ test プログラムをå‚ç…§ã›ã‚ˆã€‚

---------------------------------------------

マニュアルã®è¦‹æ–¹

メソッドå(引数1, 引数2, ...) -- çœç•¥å¯èƒ½ãªå¼•数㯠引数å=デフォルト値 ã®å½¢ã§ç¤ºã™

機能ã®è§£èª¬

引数

  • 引数1ã®å (ãã®ã‚¯ãƒ©ã‚¹ã¾ãŸã¯å–り得る値): 説明
  • 引数2ã®å (ãã®ã‚¯ãƒ©ã‚¹ã¾ãŸã¯å–り得る値): 説明
  • ...

戻り値

  • 戻り値ã®èª¬æ˜Ž

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • NetCDF ver 3 ã®é–¢æ•°å。括弧ãŒãªã„å ´åˆã€ãã®é–¢æ•°ã¨åŒç­‰ã®æ©Ÿèƒ½ã‚’有 ã™ã‚‹ã“ã¨ã‚’示ã™ã€‚直接的ãªå¯¾å¿œãŒãªã„å ´åˆã€æ‹¬å¼§å†…ã«ä¾å­˜ã™ã‚‹é–¢æ•°ã‚’挙ã’る。

---------------------------------------------

メソッドインデックス

  • クラス NetCDF

    クラスメソッド

    • NetCDF.nc4? リンクã•れ㟠NetCDF ㌠version 4 ã‹ã©ã†ã‹è¿”ã™
    • NetCDF.creation_format= NetCDF.createã§ä½œã‚‰ã‚Œã‚‹ãƒ•ァイルフォーマットを設定ã™ã‚‹ (NetCDF-4 専用).
    • NetCDF.creation_format NetCDF.createã§ä½œã‚‰ã‚Œã‚‹ãƒ•ァイルフォーマットã®è¨­å®šã‚’è¿”ã™. (NetCDF-4 専用).
    • NetCDF.open ファイルオープン(クラスメソッド)mode="w" ã§ãƒ•ァイルãŒå­˜åœ¨ã—ãªã‘ã‚Œã°æ–°è¦ä½œæˆ
    • NetCDF.new NetCDF.openメソッドã®ã‚¨ã‚¤ãƒªã‚¢ã‚¹ã§ã‚ã‚‹
    • NetCDF.create NetCDFファイルを作る(クラスメソッド)
    • NetCDF.create_tmp テンãƒãƒ©ãƒªãƒ¼NetCDFファイルを作る(クラスメソッド)

    インスタンスメソッド

    • close ファイルクローズ
    • ndims ãƒ•ã‚¡ã‚¤ãƒ«ä¸­ã®æ¬¡å…ƒã®æ•°ã‚’è¿”ã™
    • nvars ファイル中ã®å¤‰æ•°ã®æ•°ã‚’è¿”ã™
    • natts ファイル中ã®ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§ã®æ•°ã‚’è¿”ã™
    • unlimited ファイル中ã®unlimited dimensionã‚’è¿”ã™
    • path ファイルã®ãƒ‘ス. open/create時ã®filename引数ã®ä¸­èº«ã‚’è¿”ã™.
    • redef define modeã«ã™ã‚‹ã€‚æ—¢ã«ãã†ãªã‚‰ä½•ã‚‚ã›ãšnilã‚’è¿”ã™ã€‚
    • enddef data mode ã«å…¥ã‚‹ã€‚æ—¢ã«ãã†ãªã‚‰ä½•ã‚‚ã›ãšnilã‚’è¿”ã™ã€‚
    • define_mode? 今定義モードã‹ã©ã†ã‹å•åˆã‚ã›ã‚‹.
    • sync メモリー中ã®ãƒãƒƒãƒ•ァーをディスク上ã«å映ã—ã¦ãƒ•ã‚¡ã‚¤ãƒ«ã‚’åŒæœŸã•ã›ã‚‹
    • def_dim dimensionを定義
    • put_att グローãƒãƒ«å±žæ€§ã‚’設定
    • def_var 変数を定義
    • def_var_with_dim def_varã¨åŒã˜ã ãŒå¿…è¦ãªã‚‰ã¾ãšæ¬¡å…ƒã‚’å®šç¾©ã™ã‚‹ã€‚
    • var ãƒ•ã‚¡ã‚¤ãƒ«ã«æ—¢å­˜ã®å¤‰æ•°ã‚’オープン
    • vars ãƒ•ã‚¡ã‚¤ãƒ«ã«æ—¢å­˜ã®å¤‰æ•°ã‚’ã¾ã¨ã‚ã¦ã‚ªãƒ¼ãƒ—ン
    • dim æ—¢å­˜ã®æ¬¡å…ƒã‚’オープン
    • dims æ—¢å­˜ã®æ¬¡å…ƒã‚’ã¾ã¨ã‚ã¦ã‚ªãƒ¼ãƒ—ン
    • att 既存ã®ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§ã‚’オープン
    • fill= fillmodeã®å¤‰æ›´ã€‚(NetCDF ã®ãƒ‡ãƒ•ォルト㯠FILL ã§ã‚る。)
    • each_dim 次元ã«é–¢ã™ã‚‹ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿.
    • each_var 変数ã«é–¢ã™ã‚‹ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿.
    • each_att グローãƒãƒ«å±žæ€§ã«é–¢ã™ã‚‹ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿.
    • dim_names ファイル中ã®å…¨æ¬¡å…ƒã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚
    • var_names ファイル中ã®å…¨å¤‰æ•°ã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚
    • att_names ファイル中ã®å…¨ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§ã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚
  • クラス NetCDFDim

    クラスメソッド

    インスタンスメソッド

    • length 次元ã®é•·ã•ã‚’è¿”ã™
    • length_ul0 length ã¨åŒã˜ã ãŒã€ç„¡åˆ¶é™æ¬¡å…ƒã«é–¢ã—ゼロを返ã™
    • name= åå‰ã‚’ã¤ã‘ã‹ãˆã‚‹
    • name åå‰ã‚’è¿”ã™
    • unlimited? ç„¡åˆ¶é™æ¬¡å…ƒã‹ã©ã†ã‹ï¼Ÿ
  • クラス NetCDFVar

    クラスメソッド

    インスタンスメソッド

    • deflate 圧縮 (deflation) を設定. (netCDF-4 only)
    • deflate_params ç¾åœ¨ã®åœ§ç¸®è¨­å®šå•åˆã›. (netCDF-4 only)
    • endian= エンディアンを設定 (netCDF-4 only)
    • endian エンディアン設定を返ã™. (netCDF-4 only)
    • dim ãã®å¤‰æ•°ã«ãŠã‘ã‚‹ dim_num 番目(0ã‹ã‚‰æ•°ãˆã‚‹)ã®æ¬¡å…ƒã‚’å•åˆã‚ã›ã‚‹ã€‚
    • dims ãã®å¤‰æ•°ã®å…¨æ¬¡å…ƒã‚’é…列ã«ã„れã¦è¿”ã™
    • shape_ul0 変数ã®å½¢ã‚’è¿”ã™. 但ã—ç„¡åˆ¶é™æ¬¡å…ƒã®é•·ã•ã¯ã‚¼ãƒ­.
    • shape_current 変数ã®ç¾åœ¨ã®å½¢ã‚’è¿”ã™.
    • each_att 変数中ã®å…¨å±žæ€§(NetCDFAtt)ã«é–¢ã™ã‚‹ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿
    • dim_names 変数中ã®å…¨æ¬¡å…ƒã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚
    • att_names 変数中ã®å…¨å±žæ€§ã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚
    • name 変数ã®åå‰ã‚’è¿”ã™
    • name= åå‰ã‚’ä»˜ã‘æ›¿ãˆã‚‹
    • ndims æ¬¡å…ƒã®æ•°ã‚’å•ã†
    • rank ndimsã®ã‚¨ãƒªã‚¢ã‚¹
    • ntype vartype ã®åˆ¥å
    • vartype 変数値ã®åž‹ã‚’å•ã†
    • typecode 変数値ã®åž‹ã‚’å•ã†(NArrayã®typecodeã§è¿”ã™)
    • natts å±žæ€§ã®æ•°ã‚’å•ã†
    • file ãã®å¤‰æ•°ãŒå±žã™ã‚‹ãƒ•ァイルをå•åˆã‚ã›ã‚‹
    • att åå‰ã‚’指定ã—ãŸå±žæ€§ã‚’è¿”ã™
    • put_att 属性を設定
    • put  simple_putã®åˆ¥å(alias)
    • simple_put 値を入れる
    • pack selfã®å±žæ€§ scale_factor and/or add_offset を用ã„㦠NArray 等を "pack" ã™ã‚‹.
    • scaled_put simple_put ã¨åŒæ§˜ã ãŒã€packã«ã‚ˆã‚Šå±žæ€§ scale_factor 㨠add_offset を解釈ã™ã‚‹
    • get  simple_getã®åˆ¥å(alias)
    • simple_get 値をå–り出ã™
    • unpack selfã®å±žæ€§ scale_factor and/or add_offset を用ã„㦠NArray 等を "unpack" ã™ã‚‹.
    • scaled_get simple_get ã¨åŒæ§˜ã ãŒã€unpackã«ã‚ˆã‚Šå±žæ€§ scale_factor 㨠add_offset を解釈ã™ã‚‹
    • [] NetCDFVar#get ã¨åŒæ§˜ã ãŒã€ã‚µãƒ–セットを NArray#[] ã¨åŒæ§˜ã«æŒ‡å®šã™ã‚‹.
    • []= NetCDFVar#put ã¨åŒæ§˜ã ãŒã€ã‚µãƒ–セットを NArray#[]= ã¨åŒæ§˜ã«æŒ‡å®šã™ã‚‹.

    "numru/netcdf_miss" ã‚’ require ã™ã‚‹ã“ã¨ã§è¿½åŠ ã•れるインスタンスメソッド

  • クラス NetCDFAtt

    クラスメソッド

    インスタンスメソッド

    • name 属性ã®åå‰ã‚’è¿”ã™
    • name= 属性ã®åå‰ã‚’変更
    • copy 属性を別ã®å¤‰æ•°ã¾ãŸã¯ãƒ•ァイルã«ã‚³ãƒ”ー。ファイルã®å ´åˆã¯ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§ã«ãªã‚‹
    • delete 属性を削除
    • put 属性ã®å€¤ã‚’設定
    • get 属性ã®ä¸­èº«ã‚’å–り出ã™
    • atttype 属性値ã®åž‹ã‚’å•ã†
    • typecode 属性値ã®åž‹ã‚’å•ã†(NArrayã®typecodeã§è¿”ã™)

---------------------------------------------

クラス NetCDF

定数

  • NC_NOWRITE, NC_WRITE, NC_SHARE, NC_CLOBBER, NC_NOCLOBBER, NC_64BIT_OFFSET, NC_NETCDF4, NC_CLASSIC_MODEL, NCVERSION, SUPPORT_BIGMEM : ã“れら㯠NumRu::NetCDF::NC_NOWRITE ãªã©ã‚¢ã‚¯ã‚»ã‚¹ã™ã‚‹ã€‚

クラスメソッド

NetCDF.nc4?

ã“ã®ãƒ©ã‚¤ãƒ–ラリ㌠NetCDF version 4 を使ã†ã‚ˆã†ã«ãªã£ã¦ã„れ㰠(リンクã•れã¦ã‚‹ NetCDF ライブラリãŒver 4ãªã‚‰ï¼‰true を, ãã†ã§ãªã‘れ㰠(NetCDF 3ãªã‚‰) false ã‚’è¿”ã™ã€‚

NetCDF.creation_format=(cmode)

(ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ NetCDF-4 ãŒä½¿ã‚れã¦ã‚‹ã¨ãã®ã¿ä½¿ç”¨å¯èƒ½ï¼šãã†ã§ãªã‘れ㰠例外ãŒç™ºç”Ÿã™ã‚‹). NetCDF.create ã§ä½œã‚‰ã‚Œã‚‹ãƒ•ァイルã®ãƒ•ォーマットを指定ã™ã‚‹. åˆæœŸè¨­å®šã¯ "classic".

引数

  • cmode : 以下ã®ã„ãšã‚Œã‹ã€‚
    • 0, nil, or NetCDF::NC_CLASSIC_MODEL : classic format (以å‰ã‹ã‚‰ã® NetCDF-3 ã®ãƒ•ォーマット). ã“れãŒåˆæœŸè¨­å®š.
    • NetCDF::NC_64BIT_OFFSET : classic ã ãŒï¼Œå¤‰æ•°ã®ã‚µã‚¤ã‚ºã‚’大ãã出æ¥ã‚‹
    • NetCDF::NC_NETCDF4 : HDF5 ベース㮠NetCDF-4 新フォーマット
    • ( NetCDF::NC_NETCDF4 | NetCDF::NC_CLASSIC_MODEL) [ã“れ㯠NetCDF::NC_NETCDF4 㨠NetCDF::NC_CLASSIC_MODEL ã® bit "or"]: NetCDF-4 新フォーマットã ãŒï¼Œæ–°ã—ã„データモデルã¯ä½¿ãˆãªã„よã†åˆ¶é™.

NetCDF.creation_format

(ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ NetCDF-4 ãŒä½¿ã‚れã¦ã‚‹ã¨ãã®ã¿ä½¿ç”¨å¯èƒ½ï¼šãã†ã§ãªã‘れ㰠例外ãŒç™ºç”Ÿã™ã‚‹). NetCDF.create ã§ä½œã‚‰ã‚Œã‚‹ãƒ•ァイルã®ãƒ•ォーマットã®ç¾åœ¨ã®è¨­å®šã‚’è¿”ã™.

NetCDF.open(filename, mode="r", share=false)

ファイルオープン(クラスメソッド)mode="w" ã§ãƒ•ァイルãŒå­˜åœ¨ã—ãªã‘ã‚Œã°æ–°è¦ä½œæˆ

引数

  • filename (String): ファイルå
  • mode (String) : 入出力モード: "r"(読ã¿å–りã®ã¿); "w","w+" (書ã 込㿠-- ç¾åœ¨ã®ä¸­èº«ã¯ä¸Šæ›¸ã(消ãˆã‚‹!)); "r+","a","a+" (追加 -- ç¾åœ¨ã®å†…容ã¯ãã®ã¾ã¾ã«ã€æ›¸ãè¾¼ã¿å¯)。 組ã¿è¾¼ã¿ã® File クラス㨠é•ã„ã€ã©ã®ãƒ¢ãƒ¼ãƒ‰ã§ã‚‚読ã¿è¾¼ã¿ã¯å¯èƒ½ã€‚注æ„:元ã«ãªã‚‹ NetCDFライ ブラリーã®åˆ¶é™ã«ã‚ˆã‚Šã€ã€Œè¿½åŠ ã€ã«ã¯ä½™åˆ†ãªæ™‚é–“ã¨ãƒ‡ã‚£ã‚¹ã‚¯ã‚¹ãƒšãƒ¼ã‚¹ ãŒã‹ã‹ã‚‹ã€‚
  • share (true or false) : sharedモードã«ã™ã‚‹ã‹ (書ãè¾¼ã¿ä¸­ã®ãƒ•ã‚¡ イルã«ä»–ã®ãƒ—ロセスã‹ã‚‰ã®èª­ã¿è¾¼ã¿ãŒã‚り得る場åˆã« true ã¨ã™ã‚‹ã€‚C版ユー ザーズガイド第5ç« ã® nc_open ã®é …ã‚’å‚ç…§ã®ã“ã¨)

戻り値

  • NetCDFクラスã®ã‚ªãƒ–ジェクト

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_open, nc_create

NetCDF.new

NetCDF.openメソッドã®ã‚¨ã‚¤ãƒªã‚¢ã‚¹ã§ã‚ã‚‹

NetCDF.create(filename, noclobber=false, share=false)

NetCDFファイルを作る(クラスメソッド)

引数

  • filename (String) : ファイルå
  • noclobber (true or false) : 上書ãã™ã‚‹ã‹ã—ãªã„ã‹
  • share (true or false) : shared mode を使ã†ã‹ (書ãè¾¼ã¿ä¸­ã®ãƒ•ã‚¡ イルã«ä»–ã®ãƒ—ロセスã‹ã‚‰ã®èª­ã¿è¾¼ã¿ãŒã‚り得る場åˆã« true ã¨ã™ã‚‹ã€‚C版ユー ザーズガイド第5ç« ã® nc_open ã®é …ã‚’å‚ç…§ã®ã“ã¨)

戻り値

  • NetCDFクラスã®ã‚ªãƒ–ジェクト

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_create

NetCDF.create_tmp(tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'.', share=false)

テンãƒãƒ©ãƒªãƒ¼NetCDFファイルを作る(クラスメソッド) åå‰ã¯è‡ªå‹•ã§æ±ºã¾ã‚‹ã€‚クローズã•ã‚Œã‚‹ã¨æ¶ˆã•れる。

引数

  • tmpdir (String) : テンãƒãƒ©ãƒªãƒ¼ãƒ•ァイルを置ãディレクトリーå。 デフォルトã¯ç’°å¢ƒå¤‰æ•°ã§æŒ‡å®šã•れãŸãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãƒ¼ï¼ˆTMPDIR,TMP,or TEMP)ã¾ãŸã¯ '.'。セキュアーモードã§ã¯ '.' ã®ã¿ãŒãƒ‡ãƒ•ォルトã¨ãª る。
  • share (true or false) : shared mode を使ã†ã‹

戻り値

  • NetCDFクラスã®ã‚ªãƒ–ジェクト

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_create

インスタンスメソッド

close

ファイルクローズ

引数

  • ãªã—

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_close

ndims

ãƒ•ã‚¡ã‚¤ãƒ«ä¸­ã®æ¬¡å…ƒã®æ•°ã‚’è¿”ã™

引数

  • ãªã—

戻り値

  • Integer

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_ndims

nvars

ファイル中ã®å¤‰æ•°ã®æ•°ã‚’è¿”ã™

引数

  • ãªã—

戻り値

  • Integer

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_nvars

natts

ファイル中ã®ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§ã®æ•°ã‚’è¿”ã™

引数

  • ãªã—

戻り値

  • Integer

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_natts

unlimited

ファイル中ã®unlimited dimensionã‚’è¿”ã™

引数

  • ãªã—

戻り値

  • 存在ã™ã‚‹ã¨ãNetCDFDimクラスã®ã‚ªãƒ–ジェクト。ãªã„ã¨ãã¯nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_unlimdim

path

ファイルã®ãƒ‘ス. open/create時ã®filename引数ã®ä¸­èº«ã‚’è¿”ã™.

引数

  • ãªã—

戻り値

  • String

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • ãªã—

redef

define modeã«ã™ã‚‹ã€‚æ—¢ã«ãã†ãªã‚‰ä½•ã‚‚ã›ãšnilã‚’è¿”ã™ã€‚

引数

  • ãªã—

戻り値

  • true (定義モードã¸ã®å¤‰æ›´ãŒæˆåŠŸ); nil (æ—¢ã«å®šç¾©ãƒ¢ãƒ¼ãƒ‰ä¸­). ãã®ä»–ã®ç†ç”±ã§å¤‰æ›´ã§ããªã„å ´åˆã¯ä¾‹å¤–発生.

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_redef

enddef

data mode ã«å…¥ã‚‹ã€‚æ—¢ã«ãã†ãªã‚‰ä½•ã‚‚ã›ãšnilã‚’è¿”ã™ã€‚

引数

  • ãªã—

戻り値

  • true (データモードã¸ã®å¤‰æ›´ãŒæˆåŠŸ); nil (æ—¢ã«ãƒ‡ãƒ¼ã‚¿ãƒ¢ãƒ¼ãƒ‰ä¸­). ãã®ä»–ã®ç†ç”±ã§å¤‰æ›´ã§ããªã„å ´åˆã¯ä¾‹å¤–発生.

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_endef

define_mode?

今定義モードã‹ã©ã†ã‹å•åˆã‚ã›ã‚‹.

引数

  • ãªã—

戻り値

  • true (今定義モード); false (今データモード); nil (ãã®ä»– -- 読ã¿å‡ºã—専用ãªã©).

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_redef 㨠nc_enddef ã®çµ„ã¿åˆã‚ã›

sync

メモリー中ã®ãƒãƒƒãƒ•ァーをディスク上ã«å映ã—ã¦ãƒ•ã‚¡ã‚¤ãƒ«ã‚’åŒæœŸã•ã›ã‚‹

引数

  • ãªã—

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_sync

def_dim(dimension_name, length)

dimensionを定義

引数

  • dimension_name (String) : 定義ã™ã‚‹dimensionã®åå‰
  • length (Integer) : dimensionã®é•·ã•ã€‚ç„¡åˆ¶é™æ¬¡å…ƒã¯ 0。

戻り値

  • 定義ã•ã‚ŒãŸæ¬¡å…ƒ (NetCDFDimオブジェクト)

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_def_dim

put_att(attribute_name, value, atttype=nil)

グローãƒãƒ«å±žæ€§ã‚’設定

引数

  • attribute_name (String) : グローãƒãƒ«å±žæ€§ã®åå‰
  • value (Numeric, String, Array of Numeric, or NArray) : 設定ã™ã‚‹å€¤
  • atttype (nil or String) : 属性ã®åž‹. "char"(="string"),"byte", "sint","int","sfloat", "float" (ãれ ãžã‚Œ,1,1,2,4,4,8 ãƒã‚¤ãƒˆ)) ã¾ãŸã¯ nil (ã¤ã¾ã‚ŠãŠä»»ã›)

戻り値

  • 設定ã•れãŸå±žæ€§ (NetCDFAttオブジェクト)

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_put_att_<type>

def_var(variable_name, vartype, dimensions)

変数を定義

引数

  • variable_name (String) : 定義ã™ã‚‹variableã®åå‰
  • vartype (String or Fixnum) : 変数ã®ã‚¿ã‚¤ãƒ— ("char", "byte", "sint", "sint", "int", "sfloat", "float" ã®ã„ãšã‚Œã‹ã€ã¾ãŸã¯NArrayã®typecode(Fixnum))
  • dimensions (Array) : variableã®æ¬¡å…ƒã€‚NetCDFDim ã® Array。最も 「速ãå›žã‚‹ã€æ¬¡å…ƒã‹ã‚‰ã€Œé…ãå›žã‚‹ã€æ¬¡å…ƒã®é †ã«ã€‚ãã®é•·ã•ãŒå¤‰æ•°ã® rank ã¨ãªã‚‹ã€‚

戻り値

  • 定義ã—ãŸå¤‰æ•°(NetCDFVarオブジェクト)

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_def_var

def_var_with_dim(variable_name, vartype, shape_ul0, dimnames)

def_varã¨åŒã˜ã ãŒå¿…è¦ãªã‚‰ã¾ãšæ¬¡å…ƒã‚’å®šç¾©ã™ã‚‹ã€‚ 既存次元ã®é•·ã•ã¨åˆã‚ãªã„å ´åˆä¾‹å¤–。

引数

  • variable_name (String) : 定義ã™ã‚‹variableã®åå‰
  • vartype (String) : 変数ã®ã‚¿ã‚¤ãƒ— ("char", "byte", "sint", "sint", "int", "sfloat", "float" ã®ã„ãšã‚Œã‹)
  • shape_ul0 (Array of Integer) : 変数ã®å½¢ã€å³ã¡ã€å„次元ã®é•·ã•。無 åˆ¶é™æ¬¡å…ƒã¯ã‚¼ãƒ­ã§è¡¨ã™ã€‚é•·ã•ãŒå¤‰æ•°ã® rank ã¨ãªã‚‹ã€‚
  • dimnames (Array of String) : 儿¬¡å…ƒã®åå‰. é•·ã•(=>rank) 㯠shape_ul0 ã¨ç­‰ã—ããªã‘れã°ãªã‚‰ãªã„。

戻り値

  • 定義ã—ãŸå¤‰æ•°(NetCDFVarオブジェクト)

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_def_var)

var(var_name)

ãƒ•ã‚¡ã‚¤ãƒ«ã«æ—¢å­˜ã®å¤‰æ•°ã‚’オープン

引数

  • var_name (String) : オープンã™ã‚‹å¤‰æ•°å

戻り値

  • NetCDFVar クラスã®ã‚ªãƒ–ジェクト。存在ã—ãªã‘れ㰠nil。

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_varid

vars(names = nil)

ファイル中ã®å¤‰æ•°ã‚’ã¾ã¨ã‚ã¦ã‚ªãƒ¼ãƒ—ン

引数

  • names (nil or Array of String) : オープンã™ã‚‹å¤‰æ•°å. nilãªã‚‰å…¨éƒ¨ï¼ˆãƒ‡ãƒ•ォルト)

戻り値

  • NetCDFVarオブジェクトã®Array。namesã«å­˜åœ¨ã—ãªã„変数åãŒå«ã¾ã‚Œã‚Œã°ä¾‹å¤–発生。

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_varid

dim(dimension_name)

æ—¢å­˜ã®æ¬¡å…ƒã‚’オープン

引数

  • dimension_name (String) : オープンã™ã‚‹æ¬¡å…ƒå

戻り値

  • NetCDFDimクラスã®ã‚ªãƒ–ジェクト。存在ã—ãªã‘れ㰠nil。

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_dimid

dims(names = nil)

ãƒ•ã‚¡ã‚¤ãƒ«ä¸­ã®æ¬¡å…ƒã‚’ã¾ã¨ã‚ã¦ã‚ªãƒ¼ãƒ—ン

引数

  • names (nil or Array of String) : オープンã™ã‚‹æ¬¡å…ƒå. nilãªã‚‰å…¨éƒ¨ï¼ˆãƒ‡ãƒ•ォルト)

戻り値

  • NetCDFDimオブジェクトã®Array。namesã«å­˜åœ¨ã—ãªã„次元åãŒå«ã¾ã‚Œã‚Œã°ä¾‹å¤–発生。

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_dimid

att(attribute_name)

既存ã®ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§ã‚’オープン

引数

  • attribute_name (String) : オープンã™ã‚‹ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§å

戻り値

  • 存在ã™ã‚Œã° NetCDFAttクラスã®ã‚ªãƒ–ジェクト。存在ã—ãªã‘れã°nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_attidを検査ã«åˆ©ç”¨)

fill=(filemode)

fillmodeã®å¤‰æ›´ã€‚(NetCDF ã®ãƒ‡ãƒ•ォルト㯠FILL ã§ã‚る。)

引数

  • fillmode (true for FILL or false for NOFILL)

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_set_fill

each_dim{ ... }

次元ã«é–¢ã™ã‚‹ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿. 例: {|i| print i.name,"\n"} ã§å…¨æ¬¡å…ƒã®åå‰ã‚’表示.

引数

  • { ... } : イテレーター用ブロック。do endブロックã§ã‚‚よã„。

戻り値

  • self

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_ndimsを利用)

each_var{ ... }

変数ã«é–¢ã™ã‚‹ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿. 例: {|i| print i.name,"\n"} ã§å…¨å¤‰æ•°ã®åå‰ã‚’表示.

引数

  • { ... } : イテレーター用ブロック。do endブロックã§ã‚‚よã„。

戻り値

  • self

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_nvarsを利用)

each_att{ ... }

グローãƒãƒ«å±žæ€§ã«é–¢ã™ã‚‹ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿. 例: {|i| print i.name,"\n"} ã§å…¨å±žæ€§ã®åå‰ã‚’表示.

引数

  • { ... } : イテレーター用ブロック。do endブロックã§ã‚‚よã„。

戻り値

  • self

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_natts, nc_inq_attnameを利用)

dim_names

ファイル中ã®å…¨æ¬¡å…ƒã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚

引数

  • ãªã—

戻り値

  • String ã® Array

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_ndims, nc_inq_dimnameを利用)

var_names

ファイル中ã®å…¨å¤‰æ•°ã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚

引数

  • ãªã—

戻り値

  • String ã® Array

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_nvars, nc_inq_varnameを利用)

att_names

ファイル中ã®å…¨ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§ã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚ 引数

  • ãªã—

戻り値

  • String ã® Array

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_natts, nc_inq_attnameを利用)

---------------------------------------------

クラス NetCDFDim

クラスメソッド

インスタンスメソッド

length

次元ã®é•·ã•ã‚’è¿”ã™

引数

  • ãªã—

戻り値

  • Integer

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_dimlen

length_ul0

length ã¨åŒã˜ã ãŒã€ç„¡åˆ¶é™æ¬¡å…ƒã«é–¢ã—ゼロを返ã™

引数

  • ãªã—

戻り値

  • Integer

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_dimlen

name=(dimension_newname)

åå‰ã‚’ã¤ã‘ã‹ãˆã‚‹

引数

  • dimension_newname (String) : æ–°ã—ã„åå‰

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_rename_dim

name

åå‰ã‚’è¿”ã™

引数

  • ãªã—

戻り値

  • String

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_dimname

unlimited?

ç„¡åˆ¶é™æ¬¡å…ƒã‹ã©ã†ã‹ï¼Ÿ

引数

  • ãªã—

戻り値

  • true or false

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_unlimdim を利用)

---------------------------------------------

クラス NetCDFVar

クラスメソッド

NetCDFVar.new(file,varname,mode="r",share=false)

NetCDF変数をオープンã™ã‚‹ã€‚ã“れã¯ã€NetCDF#var (NetCDFクラスã®ã‚¤ãƒ³ スタンスメソッドvar) を使ã£ã¦ã‚‚出æ¥ã‚‹ã—ã€ãã¡ã‚‰ã®ã»ã†ã‚’推奨ã™ã‚‹ã€‚

引数

  • file (NetCDF or String) : NetCDFオブジェクト(NetCDF) ã¾ãŸã¯ NetCDF ファイルã®ãƒ‘ス(String)
  • varname (String) : file中ã®å¤‰æ•°å
  • mode (String) : 入出力モード。file㌠String ã®æ™‚ã«ä½¿ã‚れる。 (NetCDF.openã®é …を見よ)
  • share (true or false) : sharedモードã«ã™ã‚‹ã‹ã€‚ file㌠String ã®æ™‚ã«ä½¿ã‚れる。(NetCDF.openã®é …を見よ)

戻り値

  • NetCDFVarクラスã®ã‚ªãƒ–ジェクト

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_open, nc_create, nc_inq_varid 等を利用ã™ã‚‹)

NetCDFVar.unpack_type=(na_type)

scaled_getã§ä½¿ã†NArrayã®åž‹ã‚’固定ã™ã‚‹.

引数

  • na_type (Integer) : NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, or NArray::FLOAT

戻り値

  • na_type (引数)

NetCDFVar.unpack_type

NetCDFVar.unpack_type=ã§è¨­å®šã—ãŸNArrayã®åž‹ã‚’è¿”ã™.

戻り値

  • nil, NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, or NArray::FLOAT

インスタンスメソッド

deflate(deflate_level, shuffle=false)

(ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ NetCDF-4 ãŒä½¿ã‚れã¦ã‚‹ã¨ãã®ã¿ä½¿ç”¨å¯èƒ½ï¼šãã†ã§ãªã‘れ㰠例外ãŒç™ºç”Ÿã™ã‚‹). (æ–°ã—ã作æˆã•れãŸ)変数ãŒåœ§ç¸®(deflate)ã•れるよã†ã«ã™ã‚‹. ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ï¼Œ å¤‰æ•°ã‚’ä½œæˆ (NetCDF#def_var) ã—ãŸå¾Œï¼ŒNetCDF#enddef を呼ã¶å‰ã«å‘¼ã°ãªã‘れã°ãªã‚‰ãªã„.

引数

  • deflate_level (Integer) :: 0 to 9. (0: no compression; 9: highest compression; recommended: 1 or 2).
  • shuffle (optional; true or false; default: false) if true, turn on the shuffle filter.
    • <URL:http://www.unidata.ucar.edu/software/netcdf/papers/AMS_2008.pdf>: ``The shuffle algorithm changes the byte order in the data stream; when used with integers that are all close together, this results in a better compression ratio. There is no benefit from using the shuffle filter without also using compression.''
    • Note: shuffle is effective for float variables too (tested by horinouchi).

戻り値

  • self

deflate_params

(ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ NetCDF-4 ãŒä½¿ã‚れã¦ã‚‹ã¨ãã®ã¿ä½¿ç”¨å¯èƒ½ï¼šãã†ã§ãªã‘れ㰠例外ãŒç™ºç”Ÿã™ã‚‹). ç¾åœ¨ã®åœ§ç¸®(deflation)パラメターを返ã™ã€‚

戻り値

  • [shuffle, deflate, deflate_level] (a 3-element Array). shuffle 㨠deflate 㯠true ã¾ãŸã¯ false. deflate_level ã¯æ•´æ•°(0-9).

endian=(endian)

(ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ NetCDF-4 ãŒä½¿ã‚れã¦ã‚‹ã¨ãã®ã¿ä½¿ç”¨å¯èƒ½ï¼šãã†ã§ãªã‘れ㰠例外ãŒç™ºç”Ÿã™ã‚‹). エンディアンを設定ã™ã‚‹ã€‚使用タイミング㯠deflate ã¨åŒã˜ã€‚

Arguments

  • endian : 次ã®ã„ãšã‚Œã‹: NetCDF::NC_ENDIAN_NATIVE (=0) (default), NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2).

Return value

  • self

endian

(ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ NetCDF-4 ãŒä½¿ã‚れã¦ã‚‹ã¨ãã®ã¿ä½¿ç”¨å¯èƒ½ï¼šãã†ã§ãªã‘れ㰠例外ãŒç™ºç”Ÿã™ã‚‹). ç¾åœ¨ã®ã‚¨ãƒ³ãƒ‡ã‚£ã‚¢ãƒ³è¨­å®šã‚’è¿”ã™.

Return value

  • 次ã®ã„ãšã‚Œã‹: NetCDF::NC_ENDIAN_NATIVE (=0) (default), NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2).

dim(dim_num)

ãã®å¤‰æ•°ã«ãŠã‘ã‚‹ dim_num 番目(0ã‹ã‚‰æ•°ãˆã‚‹)ã®æ¬¡å…ƒã‚’å•åˆã‚ã›ã‚‹ã€‚

引数

  • dim_num (Fixnum) : 0,1,2,...。最も速ã回る次元ãŒ0。

戻り値

  • NetCDFDimオブジェクト

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_vardimid利用)

dims

ãã®å¤‰æ•°ã®å…¨æ¬¡å…ƒã‚’é…列ã«ã„れã¦è¿”ã™

引数

  • ãªã—

戻り値

  • NetCDFDimオブジェクトã®Array

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_vardimid

shape_ul0

変数ã®å½¢ã‚’è¿”ã™. 但ã—ç„¡åˆ¶é™æ¬¡å…ƒã®é•·ã•ã¯ã‚¼ãƒ­. ä»–ã®å¤‰æ•°ã®å®šç¾©ã«ä¾¿åˆ©.

引数

  • ãªã—

戻り値

  • Array. [0次元目ã®é•·ã•, 1次元目ã®é•·ã•,.. ]

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_vardimid, nc_inq_unlimdim 等を利用)

shape_current

変数ã®ç¾åœ¨ã®å½¢ã‚’è¿”ã™.

引数

  • ãªã—

戻り値

  • Array. [0次元目ã®é•·ã•, 1次元目ã®é•·ã•,.. ]

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_vardimid 等を利用)

each_att{ ... }

変数中ã®å…¨å±žæ€§(NetCDFAtt)ã«é–¢ã™ã‚‹ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿

引数

  • { ... } : 繰り返ã™ãƒ–ロック

戻り値

  • self

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_natts, nc_inq_attnameを利用)

dim_names

変数中ã®å…¨æ¬¡å…ƒã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚

引数

  • ãªã—

戻り値

  • String ã® Array

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_varndims, nc_inq_vardimid, nc_inq_dimname を利用)

att_names

変数中ã®å…¨å±žæ€§ã®åå‰ã‚’é…列ã«å…¥ã‚Œã¦è¿”ã™ã€‚

引数

  • ãªã—

戻り値

  • String ã® Array

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_natts, nc_inq_attnameを利用)

name

変数ã®åå‰ã‚’è¿”ã™

引数

  • ãªã—

戻り値

  • String

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_varname

name=(variable_newname)

åå‰ã‚’ä»˜ã‘æ›¿ãˆã‚‹

引数

  • variable_newname (String) : æ–°ã—ã„åå‰

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_rename_var

ndims

æ¬¡å…ƒã®æ•°ã‚’å•ã†

引数

  • ãªã—

戻り値

  • Integer

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_varndims

rank

ndimsã®ã‚¨ãƒªã‚¢ã‚¹

ntype

vartypeã®åˆ¥å

vartype

変数値ã®åž‹ã‚’å•ã†

引数

  • ãªã—

戻り値

  • String ("char","byte","sint","int","sfloat", or "float")

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_vartype

typecode

変数値ã®åž‹ã‚’å•ã†(NArrayã®typecodeã§è¿”ã™)

引数

  • ãªã—

戻り値

  • Fixnumオブジェクト (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT)

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_vartype

natts

å±žæ€§ã®æ•°ã‚’å•ã†

引数

  • ãªã—

戻り値

  • Integer

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_varnatts

file

ãã®å¤‰æ•°ãŒå±žã™ã‚‹ãƒ•ァイルをå•åˆã‚ã›ã‚‹

引数

  • ãªã—

戻り値

  • NetCDFクラスã®ã‚ªãƒ–ジェクト

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • ãªã—

att(attribute_name)

åå‰ã‚’指定ã—ãŸå±žæ€§ã‚’è¿”ã™

引数

  • attribute_name (String) : å–り出ã™å±žæ€§å

戻り値

  • NetCDFAttオブジェクト. 存在ã—ãªã‘れã°nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • (nc_inq_attidを検査ã«åˆ©ç”¨)

put_att(attribute_name, value, atttype=nil)

属性を設定

引数

  • attribute_name (String) : attributeå
  • value (Numeric, String, Array of Numeric, or NArray) : 設定ã™ã‚‹å€¤
  • atttype (nil or String) : 属性ã®åž‹. "char"(="string"),"byte", "sint","int","sfloat", "float" (ãれ ãžã‚Œ,1,1,2,4,4,8 ãƒã‚¤ãƒˆ)) ã¾ãŸã¯ nil (ã¤ã¾ã‚ŠãŠä»»ã›)

戻り値

  • NetCDFAttã®ã‚ªãƒ–ジェクト

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_put_att_<type>

put(value, option=nil)

simple_putã®åˆ¥å(alias)

simple_put(value, option=nil)

値を入れる

引数

  • value : 入れる値 (Numeric,Array(Numericã®1次元é…列)ã€NArray) スカラー(Numeric)ã¾ãŸã¯é•·ã•1ã®å ´åˆã¯ã€ãã®å€¤ã‚’一様ã«è¨­å®šã™ã‚‹ã€‚
  • option (Hash) : 変数ã®ä¸€éƒ¨åˆ†ã‚’指定ã™ã‚‹ãŸã‚ã®ã‚ªãƒ—ã‚·ãƒ§ãƒ³å¼•æ•°ã€‚çœ ç•¥ã™ã‚Œã°ã€å¤‰æ•°å…¨ä½“ãŒå¯¾è±¡ã¨ãªã‚‹ã€‚ãƒãƒƒã‚·ãƒ¥ã®ã‚­ãƒ¼ã¨ã—ã¦ã¯ã€ "start","end","stride"ã®çµ„ã€ã¾ãŸã¯"index"ãŒä½¿ç”¨ã§ãる。"index" ã¯1è¦ç´ ï¼ˆã‚¹ã‚«ãƒ©ãƒ¼ï¼‰ã‚’指ã™ã€‚"end","stride"ã¯çœç•¥å¯ã€‚çœç•¥ã™ã‚‹ã«ã— ã‚ã—ãªã„ã«ã—ã‚ã€æ›¸ãã“ã‚€ã¹ãè¦ç´ ã®æ•°ãŒ valueã®ãれã¨ä¸€è‡´ã™ã‚‹ã‚ˆã†ã«ã— ãªã‘れã°ãªã‚‰ãªã„。start,end,indexã§ã¯Arrayã®å ´åˆã¨åŒæ§˜ã€è² ã®å€¤ã§å¾Œã‚ ã‹ã‚‰ã®ä½ç½®ã‚’指定ã§ãる。"stride"ã¯æ­£ã®å€¤ã®ã¿å—ã‘付ã‘ã‚‹ã®ã§ã€é… 列を引ã£ãり返ã—ãŸã‘れã°å¾Œã‹ã‚‰åˆ¥é€”ã‚„ã‚‹ã“ã¨ã«ãªã‚‹ã€‚

    例: 変数ãŒ2次元ã®å ´åˆ:

    {"start"=>[2,5],"end"=>[6,-1],"stride"=>[2,4]} -- 第1次元目ã¯ã€ è¦ç´  2 ã‹ã‚‰ 6 ã¾ã§ 1 ã¤ãŠã (0ã‹ã‚‰æ•°ãˆã‚‹ã®ã§è¦ç´  2 㯠3 番目ã§ã‚ ã‚‹ã“ã¨ã«æ³¨æ„)ã€ç¬¬2次元目ã¯ã€è¦ç´  6 ã‹ã‚‰ 最後(=-1)ã¾ã§ 3 ã¤ãŠã ã«ã¨ã£ãŸã‚µãƒ–セット。

    {"index"=>[0,0]}: 最åˆã®è¦ç´ ã«ã‚㟠るスカラー値

    {"index"=>[0,-2]}: 1æ¬¡å…ƒç›®ã¯æœ€åˆ, 2æ¬¡å…ƒç›®ã¯æœ€å¾Œã‹ã‚‰2番目ã«ã‚㟠るスカラー値

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_put_var_<type>, nc_put_vars_<type>, nc_put_var1_<type>

pack(na)

selfã®å±žæ€§ scale_factor and/or add_offset を用ã„㦠NArray 等を "pack" ã™ã‚‹.

ã‚‚ã—ã‚‚ scale_factor and/or add_offset ãŒè¨­å®šã•れã¦ã„れ㰠(na-add_offset)/scale_factor ã‚’è¿”ã™ã€‚ãã†ã§ãªã‘れ㰠na ã‚’è¿”ã™ã€‚

引数

  • na : pack ã™ã‚‹æ•°å€¤é…列 (NArray, NArrayMiss, Array)

戻り値

  • a NArray or NArrayMiss

scaled_put(value, option=nil)

simple_put ã¨åŒæ§˜ã ãŒã€packã«ã‚ˆã‚Šå±žæ€§ scale_factor 㨠add_offset を解釈ã™ã‚‹

引数等ã«ã¤ã„ã¦ã¯ put ã®è§£èª¬ã‚’å‚ç…§ã®ã“ã¨

get(option=nil)

simple_getã®åˆ¥å(alias)

simple_get(option=nil)

値をå–り出ã™

引数

  • option (Hash) : 変数ã®ä¸€éƒ¨åˆ†ã‚’指定ã™ã‚‹ãŸã‚ã®ã‚ªãƒ—ション引数。仕 様㯠put ã«åŒã˜ã€‚

戻り値

  • NArrayクラスã®ã‚ªãƒ–ジェクト

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_get_var_<type>, nc_get_vars_<type>, nc_get_var1_<type>

unpack(na)

selfã®å±žæ€§ scale_factor and/or add_offset を用ã„㦠NArray 等を "unpack" ã™ã‚‹.

ã‚‚ã—ã‚‚ scale_factor and/or add_offset ãŒè¨­å®šã•れã¦ã„れ㰠na * scale_factor + add_offset ã‚’è¿”ã™ã€‚ãã†ã§ãªã‘れ㰠na ã‚’è¿”ã™ã€‚ coerce ã«ã‚ˆã£ã¦åž‹ãŒå¤‰åŒ–ã™ã‚‹ -- 例ãˆã°ã€ã‚‚ã— na ㌠sint ã§ scale_factor 㨠add_offset ㌠sfloat ã§ã‚れã°ã€è¿”り値㯠sfloat ã«ãªã‚‹ã€‚返り値ã®åž‹ã¯ NetCDFVar.unpack_type= を使ã£ã¦ é™½ã«æŒ‡å®šã™ã‚‹ã“ã¨ã‚‚ã§ãる。

引数

  • na : unpack ã™ã‚‹æ•°å€¤é…列 (NArray, or NArrayMiss)

戻り値

  • a NArray or NArrayMiss

scaled_get(option=nil)

simple_get ã¨åŒæ§˜ã ãŒã€unpackã«ã‚ˆã‚Šå±žæ€§ scale_factor 㨠add_offset を解釈ã™ã‚‹

引数等ã«ã¤ã„ã¦ã¯ put ã®è§£èª¬ã‚’å‚ç…§ã®ã“ã¨

[]

NetCDFVar#get ã¨åŒæ§˜ã ãŒã€ã‚µãƒ–セットを NArray#[] ã¨åŒæ§˜ã«æŒ‡å®šã™ã‚‹.

NArrayã§ã‚µãƒãƒ¼ãƒˆã•れã¦ã„るサブセット指定方法ã«åŠ ãˆã¦ã€ã‚¹ãƒ†ãƒƒãƒ—付 ãã®ç¯„囲を指定ã§ãる。ã“れ㯠{0..-1,2} ãªã©ã¨ã™ã‚‹ã€‚ã¤ã¾ã‚Šã€è¦ç´  æ•°ãŒï¼‘ã®ãƒãƒƒã‚·ãƒ¥ã®ã‚­ãƒ¼ã«ç¯„囲(Range)ã€å€¤ã«ã‚¹ãƒ†ãƒƒãƒ—(Integer)を指定 ã™ã‚‹ã€‚NArrayã¨é•ã„ã€ï¼’次元以上ã®å¤‰æ•°ã‚’1次元ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã§ 指定ã™ã‚‹ã“ã¨ã¯å‡ºæ¥ãªã„。

[] =

NetCDFVar#put ã¨åŒæ§˜ã ãŒã€ã‚µãƒ–セットを NArray#[]= ã¨åŒæ§˜ã«æŒ‡å®šã™ã‚‹.

NArrayã§ã‚µãƒãƒ¼ãƒˆã•れã¦ã„るサブセット指定方法ã«åŠ ãˆã¦ã€ã‚¹ãƒ†ãƒƒãƒ—付 ãã®ç¯„囲を指定ã§ãる。ã“れ㯠{0..-1,2} ãªã©ã¨ã™ã‚‹ã€‚ã¤ã¾ã‚Šã€è¦ç´  æ•°ãŒï¼‘ã®ãƒãƒƒã‚·ãƒ¥ã®ã‚­ãƒ¼ã«ç¯„囲(Range)ã€å€¤ã«ã‚¹ãƒ†ãƒƒãƒ—(Integer)を指定 ã™ã‚‹ã€‚NArrayã¨é•ã„ã€ï¼’次元以上ã®å¤‰æ•°ã‚’1次元ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã§ 指定ã™ã‚‹ã“ã¨ã¯å‡ºæ¥ãªã„。

"numru/netcdf_miss" ã‚’ require ã™ã‚‹ã“ã¨ã§è¿½åŠ ã•れるインスタンスメソッド

get_with_miss(option=nil)

getã¨åŒæ§˜ã ãŒã€ãƒ‡ãƒ¼ã‚¿æ¬ æã‚’処ç†ã™ã‚‹

データ欠æã¯æ¨™æº–属性 valid_range, (valid_min and/or valid_max), ã¾ãŸã¯ missing_value ã«ã‚ˆã‚ŠæŒ‡å®šã•れる。解釈ã®å„ªå…ˆé †ä½ã¯ã“ã®é †ç•ªã§ ã‚る。「ユーザーズガイドã€ã®æŽ¨å¥¨ã¨é•ã„ã€ã“ã“ã§ã¯ missin_value ã‚‚ 解釈ã•れる。も㗠missing_value 㨠valid_* ãŒåŒæ™‚ã«å­˜åœ¨ã™ã‚‹å ´åˆã€ missng_value ã¯æœ‰åŠ¹ãƒ‡ãƒ¼ã‚¿ç¯„å›²å¤–ã«ã‚ã£ã¦ã¯ãªã‚‰ãªã„。ãã®å ´åˆã€ä¾‹å¤– ãŒç™ºç”Ÿã™ã‚‹ã€‚

上記ã®ã‚ˆã†ã«ã‚‚ã—データ欠æï¼ˆã®ä»•æ–¹ï¼‰ãŒæŒ‡å®šã•れã¦ã„れã°ã€ã“ã®ãƒ¡ã‚½ãƒƒ ド㯠NArrayMiss オブジェクトを返ã™ã€‚ãã†ã§ãªã‘れ㰠NArray ã‚’è¿”ã™ã€‚

引数

  • getを見よ.

戻り値

  • NArrayMissオブジェクト (データ欠æãŒæŒ‡å®šã•ã¦ã„ã‚‹å ´åˆ) ã¾ãŸã¯ NArray オブジェクト (データ欠æãŒæŒ‡å®šã•ã¦ãªã„å ´åˆ)

NetcdfError 以外ã®ä¾‹å¤–発生

  • missing_value ãŒãƒ‡ãƒ¼ã‚¿æœ‰åŠ¹ç¯„å›²ã«ãªã„ (上記å‚ç…§ã®ã“ã¨).

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • get を見よ. ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ Ruby ã®ã¿ã§æ›¸ã‹ã‚Œã¦ã„ã‚‹.

例

  • 次ã®ä¾‹ã§ã¯ get ã‚’ get_with_miss ã‚’ç½®ãæ›ãˆã¦ã„ã‚‹. ã“ã†ã™ã‚‹ã¨ [] もデータ欠æã‚’解釈ã™ã‚‹ã‚ˆã†ã«ãªã‚‹ (内部㧠get を呼んã§ã‚‹ã®ã§).

    file = NetCDF.open('hogehoge.nc')
    var = file.var('var')
    def var.get(*args); get_with_miss(*args); end
    p var.get       # --> inteprets data missing if defined
    p var[0..-1,0]  # --> inteprets data missing if defined (assumed 2D)

get_with_miss_and_scaling(option=nil)

get_with_missã¨åŒæ§˜ã ãŒã€unpackã«ã‚ˆã‚Šã‚¹ã‚±ãƒ¼ãƒªãƒ³ã‚°ã‚‚行ã†.

欠æå€¤å‡¦ç†ã¯åŸºæœ¬çš„ã«ã¯ pack ã—ãŸãƒ‡ãƒ¼ã‚¿ã‚’対象ã«è¡Œã†(ã“れã¯å¤šã㮠コンベンション採用ã•れã¦ã„ã‚‹)。ãŸã ã—ã€valid_* / missing_value ã®åž‹ãŒ pack ã—ãŸãƒ‡ãƒ¼ã‚¿ã®åž‹ã¨ç•°ãªã‚Šã€ã‹ã¤ unpackã—ãŸãƒ‡ãƒ¼ã‚¿ã®åž‹ã¨ 一致ã™ã‚‹ã¨ã(ã«é™ã‚Šï¼‰ unpack ã—ãŸãƒ‡ãƒ¼ã‚¿ã‚’対象ã¨ã™ã‚‹ã€‚ ã“れã§åŸºæœ¬çš„ã«å…¨ã¦ã®ã‚³ãƒ³ãƒ™ãƒ³ã‚·ãƒ§ãƒ³ã«å¯¾å¿œã§ãる。

例

  • 上記å‚照。åŒã˜ã“ã¨ãŒã§ãる。

put_with_miss(value, option=nil)

putã¨åŒæ§˜ã ãŒã€ãƒ‡ãƒ¼ã‚¿æ¬ æã‚’処ç†ã™ã‚‹

ã‚‚ã—ã‚‚ value ㌠NArray ãªã‚‰ã€ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ put ã«åŒ ã˜. ã‚‚ã—value ㌠NArrayMiss ã§ã‹ã¤ self ã®å±žæ€§ã«ã‚ˆã‚Šãƒ‡ãƒ¼ã‚¿æ¬ æãŒ 定義ã•れã¦ã„れ㰠(get_with_missã‚’å‚ç…§ã®ã“ã¨)ã€value 中ã®ãƒ‡ãƒ¼ã‚¿æ¬ æãŒè§£é‡ˆã•れる。å³ã¡ã€valueä¸­ã®æ¬ æãƒ‡ãƒ¼ã‚¿ã¯ã€ ã‚る欠æå€¤ (missing_value ã¾ãŸã¯ _FillValue ã¾ãŸã¯ãƒ‡ãƒ¼ã‚¿æœ‰åŠ¹ç¯„å›² 外ã®é©å½“ãªå€¤) ã«ç½®ãæ›ãˆã‚‰ã‚ŒãŸä¸Šã§ãƒ•ã‚¡ã‚¤ãƒ«ã«æ›¸ãè¾¼ã¾ã‚Œã‚‹ã€‚ value 中ã®éžæ¬ æãƒ‡ãƒ¼ã‚¿ãŒ self ã«ãŠã‘る有効範囲ã«å…¥ã£ã¦ ã„ã‚‹ã‹ã©ã†ã‹ã¯ãƒã‚§ãƒƒã‚¯ã•れãªã„。

引数

  • value : NArrayMiss ã¾ãŸã¯ put ã§è¨±ã•れã¦ã„るクラスã®ã‚ªãƒ–ジェクト.
  • option (Hash) : put を見よ.

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • put を見よ. ã“ã®ãƒ¡ã‚½ãƒƒãƒ‰ã¯ Ruby ã®ã¿ã§æ›¸ã‹ã‚Œã¦ã„ã‚‹.

例

  • 次ã®ä¾‹ã§ã¯ put ã‚’ put_with_miss ã‚’ç½®ãæ›ãˆã¦ã„ã‚‹. ã“ã†ã™ã‚‹ã¨ []= もデータ欠æã‚’解釈ã™ã‚‹ã‚ˆã†ã«ãªã‚‹ (内部㧠put を呼んã§ã‚‹ã®ã§).

    file = NetCDF.open('hogehoge.nc')
    var = file.var('var')
    def var.put(*args); put_with_miss(*args); end
    var.put = narray_miss      # --> inteprets data missing if defined
    var[0..-1,0] = narray_miss # --> inteprets data missing if defined (assumed 2D)

put_with_miss_and_scaling(value, option=nil)

put_with_missã¨åŒæ§˜ã ãŒã€packã«ã‚ˆã‚Šã‚¹ã‚±ãƒ¼ãƒªãƒ³ã‚°ã‚‚行ã†.

欠æå€¤å‡¦ç†ã¯åŸºæœ¬çš„ã«ã¯ pack ã—ãŸãƒ‡ãƒ¼ã‚¿ã‚’対象ã«è¡Œã†(ã“れã¯å¤šã㮠コンベンション採用ã•れã¦ã„ã‚‹)。ãŸã ã—ã€valid_* / missing_value ã®åž‹ãŒ pack ã—ãŸãƒ‡ãƒ¼ã‚¿ã®åž‹ã¨ç•°ãªã‚Šã€ã‹ã¤ unpackã—ãŸãƒ‡ãƒ¼ã‚¿ã®åž‹ã¨ 一致ã™ã‚‹ã¨ã(ã«é™ã‚Šï¼‰ unpack ã—ãŸãƒ‡ãƒ¼ã‚¿ã‚’対象ã¨ã™ã‚‹ã€‚ ã“れã§åŸºæœ¬çš„ã«å…¨ã¦ã®ã‚³ãƒ³ãƒ™ãƒ³ã‚·ãƒ§ãƒ³ã«å¯¾å¿œã§ãる。

例

  • 上記å‚照。åŒã˜ã“ã¨ãŒã§ãる。

---------------------------------------------

クラス NetCDFAtt

クラスメソッド

インスタンスメソッド

name

属性ã®åå‰ã‚’è¿”ã™

引数

  • ãªã—

戻り値

  • String

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • ãªã—

name=(attribute_newname)

属性ã®åå‰ã‚’変更

引数

  • attribute_newname (String) : æ–°ã—ã„åå‰

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_rename_att

copy(var_or_file)

属性を別ã®å¤‰æ•°ã¾ãŸã¯ãƒ•ァイルã«ã‚³ãƒ”ー。ファイルã®å ´åˆã¯ã‚°ãƒ­ãƒ¼ãƒãƒ«å±žæ€§ã«ãªã‚‹

引数

  • var_or_file (NetCDFVar or NetCDF)

戻り値

  • コピーã—ã¦ä½œã‚‰ã‚ŒãŸå±žæ€§ (NetCDFAtt)

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_copy_att

delete

属性を削除

引数

  • ãªã—

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_del_att

put(value, atttype=nil)

属性ã®å€¤ã‚’設定

引数

  • value (Numeric, String, Array of Numeric, or NArray) : 入れる値
  • atttype (nil or String) : 属性ã®åž‹. "char"(="string"),"byte", "sint","int","sfloat", "float" (ãれ ãžã‚Œ,1,1,2,4,4,8 ãƒã‚¤ãƒˆ)) ã¾ãŸã¯ nil (ã¤ã¾ã‚ŠãŠä»»ã›)

戻り値

  • nil

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_put_att_<type>

get

属性ã®ä¸­èº«ã‚’å–り出ã™

引数

  • ãªã—

戻り値

  • 文字列ã¾ãŸã¯NArrayオブジェクト (注æ„: スカラーã®å ´åˆã‚‚é•·ã•1ã® NArrayã«ãªã‚‹)

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_get_att_<type>

atttype

属性値ã®åž‹ã‚’å•ã†

引数

  • ãªã—

戻り値

  • "char","byte","sint","int","sfloat","float"

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_atttype

typecode

属性値ã®åž‹ã‚’å•ã†(NArrayã®typecodeã§è¿”ã™)

引数

  • ãªã—

戻り値

  • Fixnumオブジェクト (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT)

対応ã™ã‚‹(利用ã™ã‚‹) C 版 NetCDF ã®é–¢æ•°

  • nc_inq_atttype
ruby-netcdf-0.7.2/doc/to_html0000755000175000017500000000037012772251340015742 0ustar uwabamiuwabami#!/bin/csh nkf -m Ref_man_jp.rd | rd2 --out-code=utf-8 | \ sed -e 's/
/

/' -e 's/<\/dt>/<\/h4><\/dt>/' \ > Ref_man_jp.html rd2 Ref_man.rd | \ sed -e 's/
/

/' -e 's/<\/dt>/<\/h4><\/dt>/' \ > Ref_man.html ruby-netcdf-0.7.2/doc/README_JP.txt0000644000175000017500000001225312772251340016440 0ustar uwabamiuwabami***** README_JP.txt --- RubyNetCDF ¤È¤Ï?--- ***** *** RubyNetCDF ¤ÎÇØ·Ê¤ÈÌÜŪ *** º£Æü¡¢µ¤¾Ý¡¢Â絤¡¢Ä¶¹âÁزʳؤʤɤÎʬÌî¤ËÃÖ¤¤¤Æ¤Ï¡¢´Ñ¬µ¡´ï¤Îȯã¤Ë¤è¤ê¡¢ ¿¤¯¤Î´Ñ¬¥Ç¡¼¥¿¤¬ÆÀ¤é¤ì¤ë¤è¤¦¤Ë¤Ê¤ê¡¢¤µ¤é¤Ë·×»»µ¡²Ê³Ø¤Îȯã¤Ë¤è¤ê¡¢·× »»µ¡¥·¥ß¥å¥ì¡¼¥·¥ç¥ó¤Ë¤è¤ë¿ôÃͲòÀϤ¬¤µ¤«¤ó¤Ë¹Ô¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£¤½¤Î ·ë²Ì¡¢¸½ºß¤Ç¤Ï³Æ¸¦µæ¼¼Ã±°Ì¤Ç°·¤ï¤ì¤ë¥Ç¡¼¥¿Î̤À¤±¤ò¹Í¤¨¤Æ¤â¡¢¤½¤ÎÎ̤Ϥ« ¤Ê¤êËÄÂç¤Ê¤â¤Î¤È¤Ê¤ê¡¢¾¯¤·¤Ç¤â¡¢¸úΨ¤è¤¯¥Ç¡¼¥¿½èÍý¤ò¹Ô¤¦É¬Íפ¬¤Ç¤Æ¤­¤¿¡£ ¤µ¤é¤Ë¡¢´Ñ¬¥Ç¡¼¥¿¡¢¥·¥ß¥å¥ì¡¼¥·¥ç¥ó¤Î¥Ç¡¼¥¿¤ò²òÀϤ¹¤ë¤¿¤á¤Î¥×¥í¥°¥é¥à ºîÀ®¤Ï¥Õ¥¡¥¤¥ë¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤¬°ã¤¨¤Ð¡¢Ãà°ì¤½¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Ë¹ç¤ï¤»¤Æ¡¢ ¥×¥í¥°¥é¥à¤òºîÀ®¤»¤Í¤Ð¤Ê¤é¤º¡¢Èó¾ï¤ËÏ«ÎϤȻþ´Ö¤òÈñ¤ä¤¹¤³¤È¤Ë¤Ê¤ë¡£¤³¤ì ¤ò²ò·è¤¹¤ë¤Ë¤Ï¡¢ÍÍ¡¹¤Ê¥Õ¥©¡¼¥Þ¥Ã¥È¥Ç¡¼¥¿¤òÅý°ì¤·¤Æ°·¤¨¤ë¥¤¥ó¥¿¡¼¥Õ¥§¡¼ ¥¹¤¬É¬Íפǡ¢¤½¤Î¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Ï²Ä»ë²½¤ä¡¢¿ôÃÍ·×»»¤Ë¤âŬ¤·¤¿¤â¤Î¤¬É¬Í× ¤Ç¤¢¤ë¡£¤½¤Î¤è¤¦¤ÊÇØ·Ê¤ò¤Õ¤Þ¤¨¤Æ¡¢³«È¯¸úΨ¤¬¹â¤¯¡¢¥×¥í¥°¥é¥à¤ÎÊݼé´ÉÍý ¤¬ÍưפǤ¢¤ë¤È¤¤¤¦Íýͳ¤«¤é¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¸À¸ìruby¤òÍѤ¤¤¿¥Ç¡¼¥¿½èÍý¡¢ ²Ä»ë²½´Ä¶­³«È¯¤¬Í­¸ú¤È¹Í¤¨¤ë¡£¤½¤Î¤¿¤á¤Î¼ï¡¹¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¥Ç¡¼¥¿¤ò°· ¤¦¤¿¤á¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹ºî¤ê¤Î°ì¤Ä¤È¤·¤Æ¡¢¼«¸Êµ­½Ò·¿¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç¤¢¤ë¡¢ netCDF¥Ç¡¼¥¿¤ÎC¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ë¤ª¤±¤ëruby¤Ë¤è¤ë¥é¥Ã¥Ñ¡¼¤Î³«È¯¤òÌÜŪ¤È ¤¹¤ë¡£ *** netCDF¤Ë¤Ä¤¤¤Æ *** netCDF¤Ï¡¢Univercity Corporation for Atmospheric Research¤Ë¤è¤Ã¤Æ³«È¯¤µ ¤ì¤¿¡£¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤È¤Î°ã¤¤¤Ï¡¢netCDF¤Ïñ¤Ê¤ë¿ôÃÍÇÛÎó¤Î¤Ê¤é¤Ó¤Ë¤Ê¤Ã¤Æ¤¤ ¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢¤½¤Î¾¤ÎÉÕ²ÃŪ¾ðÊó¤ò¤½¤Î¥Õ¥¡¥¤¥ë¤ÎÃæ¤Ë»ý¤Ã¤Æ¤¤¤ë¤È¤¤¤¦¤³¤È ¤Ç¤¢¤ë¡£¶ñÂÎŪ¤Ê¹½Â¤¤Ï¡¢ file--has¢ªdimenstions ¢¬ ref --has¢ªvariables¢ª attributes --has¢ªattributes (global) ¤È¤¤¤Ã¤¿¶ñ¹ç¤Ë¡¢¼¡¸µ¡¢ÊÑ¿ô̾¡¢Â°À­¤È¤¤¤¦ÉÕ²ÃŪ¾ðÊó¤ò»ý¤Ã¤¿¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç ¤¢¤ë¡£ netCDF¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤È¤·¤Æ¤Ï¡¢C¸À¸ìÍÑ¡¢FORTRAN¸À¸ìÍÑ¡¢C++¸À¸ìÍÑ¡¢ perl¸À¸ìÍÑ¡¢¤È¤¢¤ë¤¬¡¢ruby¤Ï¤â¤È¤â¤ÈC¤Ç¤«¤«¤ì¤Æ¤ª¤ê¡¢¤µ¤é¤Ëµ¡Ç½³ÈÄ¥¤ò¤¹ ¤ë¾ì¹ç¤Ï³ÈÄ¥¥é¥¤¥Ö¥é¥ê¤È¤¤¤¦¥×¥í¥°¥é¥à¤òC¤ÇºîÀ®¤·¤Æ¼Â¸½¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë ¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£¤½¤³¤ÇC¸À¸ì¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ëruby¤Î¦¤«¤é¥¢¥¯¥»¥¹¤Ç¤­ ¤ë¤è¤¦¤Ë³ÈÄ¥¥é¥¤¥Ö¥é¥ê¤òºîÀ®¤¹¤ë¡£ *** ¼ÂºÝ¤Ë³«È¯¤·¤¿¥×¥í¥°¥é¥à¤Î»ÅÍÍ *** ¤Þ¤º¡¢¾åµ­¤Î¤è¤¦¤ÊnetCDF¤Î¹½Â¤¤Ë¹ç¤ï¤»¤Æ¡¢¿·¤·¤¯³ÈÄ¥¥é¥¤¥Ö¥é¥êÃæ¤Ë 4¤Ä¤Î¥¯¥é¥¹¤òÄêµÁ¤·¤¿¡£ ¡» NetCDF¥¯¥é¥¹ ¡» NetCDFDim ¥¯¥é¥¹ ¡» NetCDFVar ¥¯¥é¥¹ ¡» NetCDFAtt ¥¯¥é¥¹ ¤³¤Î¥¯¥é¥¹¤Î¤½¤ì¤¾¤ì¤ËC¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ë¹ç¤ï¤»¤ÆºîÀ®¤·¤¿¥á¥½¥Ã¥É¤À¤±¤Ç ¤Ê¤¯¡¢NetCDFDim,NetCDFAtt¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿¤¬ÍÆ°×¤Ë ¤Ç¤­¤ë¥á¥½¥Ã¥É¤òÍѰդ·¡¢ÊÑ¿ô¤Ø¤Î¥Ç¡¼¥¿¤Î½ñ¹þ¤ä¡¢¥Ç¡¼¥¿¤ÎÆÉ¤ß½Ð¤·¤â¥Ï¥Ã¥·¥å ¤òÍøÍѤ·¤¿¥ª¥×¥·¥ç¥ó°ú¿ô¤Ë¤è¤ëÀ©¸æ¤ò²Äǽ¤Ë¤¹¤ë¤³¤È¤ÇÍøÍѤ·¤ä¤¹¤¤¥¤¥ó¥¿¡¼ ¥Õ¥§¡¼¥¹¤ò¼Â¸½¤·¤¿¡£¤Þ¤¿ruby¤ÎÇÛÎó¤Ï¿ôÃÍ·×»»¤Ë¸þ¤¤¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢netCDF ¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤àÁ°¡¢¤Þ¤¿netCDF¥Õ¥¡¥¤¥ë¤«¤éÆÉ¤ß½Ð¤·¤¿¥Ç¡¼¥¿ÇÛÎó¤Î³ÊǼ ¤Ë¤Ï¡¢¿ôÃÍ·×»»¤ËŬ¤·¤¿¿ôÃÍ·¿ÇÛÎóNArray¤ò»ÈÍѤ·¤Æ¤¤¤ë¡£ °ì¤Ä°ì¤Ä¤Î¥á¥½¥Ã¥É¤Î»ÅÍͤˤĤ¤¤Æ¤Ï¡¢netcdf-0.01.tar.gz¤ËƱº­¤µ¤ì¤Æ¤¤¤ë how_to_use_netcdf.doc¤Þ¤¿¤Ïhow_to_use_netcdf.pdf¤Ëµ­ºÜ¤µ¤ì¤Æ¤¤¤ë¤Î¤Ç¤½ ¤Á¤é¤ò»²¾È²¼¤µ¤¤¡£ *** ¥¤¥ó¥¹¥È¡¼¥ëÊýË¡¤ª¤è¤ÓÃí°Õ»ö¹àÅù *** netcdf-0.01.tar.gz¤òŸ³«¤·¤Æ¤Ç¤­¤ënetcdf-0.01/¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ë extconf.rb¤ò»ÈÍѤ·¤Æ¡¢ ruby extconf.rb, make make test make site-install(¤Þ¤¿¤Ïmake install) ¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤Ç¤­¤ë¡£(make test ¤Ï¥Æ¥¹¥È¤ò¤¹¤ë¤À¤±¤Ê¤Î¤Ç¤·¤Ê¤¯¤Æ¤âÎÉ ¤¤) ¤Þ¤¿¤³¤Î¥×¥í¥°¥é¥à¤ò»ÈÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢NArray¤¬¤¢¤é¤«¤¸¤á¥¤¥ó¥¹¥È¡¼¥ë¤µ ¤ì¤Æ¤¤¤ë¤³¤È¤¬É¬Íפˤʤ롣¤Þ¤¿NArray¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ë¡¢ narray.h, narray_config.h ¤Ïruby¤Î¥Ø¥Ã¥À¥Õ¥¡¥¤¥ëruby.h¤Î³ÊǼ¾ì½ê (Ä̾ï/usr/local/lib/ruby/1.6/¥¢¡¼¥­¥Æ¥¯¥Á¥ã̾) °Ê²¼¤Ë¥³¥Ô¡¼¤·¤Æ¤ª¤¯É¬Íפ¬¤¢¤ë¡£ ¤µ¤é¤Ë¡¢¤³¤ì¤ÏÃí°Õ»ö¹à¤Ç¤¹¡£ ¤³¤³¤Ç¡¢extconf.rb¤ÎÃæ¤Ç¤Ï¡¢netcdf-0.01/¤Ë¤¢¤ëmkmf.rb¤ò¸Æ¤Ó½Ð¤·¤Æ¡¢ ¼Â¹Ô¤·¤Þ¤¹¤¬¡¢°ìÉôruby¤Î¤â¤È¤â¤È¤Îmkmf.rb¤ËÊѹ¹¤ò²Ã¤¨¤Æ¤¤¤Þ¤¹¡£ Êѹ¹¤Î»ÅÊý¤ò°Ê²¼¤Ë¼¨¤·¤Þ¤¹¡£º£¸å¡¢ruby¤Î¥Ð¡¼¥¸¥ç¥ó¥¢¥Ã¥×¤¬¹Ô¤ï¤ì¡¢ mkmf.rb¤¬½ñ¤­´¹¤¨¤é¤ì¤¿ºÝ¤Î»²¹Í¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£ ********************************************************************** install: $(archdir)/$(DLLIB) site-install: $(sitearchdir)/$(DLLIB) ¤È¤Ê¤Ã¤Æ¤¤¤ë¤Î¤Ç¡¢$(archdir)/$(DLLIB): ¤È $(sitearchdir)/$(DLLIB): ¤Ë¤½¤ì¤¾¤ì¡¢ $(archdir)/$(DLLIB): $(DLLIB) ¤Î¤Û¤¦¤Ï @$(RUBY) -r ftools -e 'File::makedirs(*ARGV)' $(rubylibdir) $(archdir) @$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0555, true)' $(DLLIB) $(archdir)/$(DLLIB) ¤Îľ¸å¤Ë¡¢ @$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0555, true)' netcdf.rb $(rubylibdir)/netcdf.rb ¤ò¡¢ $(sitearchdir)/$(DLLIB): $(DLLIB) ¤Î¤Û¤¦¤Ï @$(RUBY) -r ftools -e 'File::makedirs(*ARGV)' $(libdir) $(sitearchdir) @$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0555, true)' $(DLLIB) $(sitearchdir)/$(DLLIB) ¤Îľ¸å¤Ë¡¢ @$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0555, true)' netcdf.rb $(sitelibdir)/netcdf.rb ¤ò²Ã¤¨¤Æ¤¤¤Þ¤¹¡£ disclean: ¤ËÂФ·¡¢¤â¤È¤Ï @$(RM) core ruby$(EXEEXT) *~ ¤Ç¤¢¤ë¤Î¤ËÂФ·¡¢ @$(RM) core ruby$(EXEEXT) *~ *.nc demo/*.nc ¤È¡¢*.nc ¥Õ¥¡¥¤¥ë¤ò¾Ãµî¤¹¤ë¤è¤¦¤Ë¤·¤Þ¤·¤¿¡£ ************************************************************************* ÇÛÉÛ¾ò·ï¤ÏRuby¤Î¥é¥¤¥»¥ó¥¹¤Ë½àµò¤¹¤ë¡£ ¤Ê¤ª¡¢netcdf,ruby,narray¤Ë´Ø¤¹¤ë¾ðÊó¤Ï°Ê²¼¤ÎURL¤ò»²¾È²¼¤µ¤¤¡£ netcdf¤Î¥Û¡¼¥à¥Ú¡¼¥¸ http://www.unidata.ucar.edu/packages/netcdf/ ruby¤Î¥Û¡¼¥à¥Ú¡¼¥¸ http://www.ruby-lang.org/ narray¤Î¥Û¡¼¥à¥Ú¡¼¥¸ http://www.ruby-lang.org/en/raa-list.rhtml?name=NArray ***** End of the README_JP.txt ***** ruby-netcdf-0.7.2/doc/Ref_man.rd0000644000175000017500000013272512772251340016256 0ustar uwabamiuwabami=begin =RubyNetCDF Reference Manual RubyNetCDF version : 0.7.1 * (()) --------------------------------------------- ==Overview RubyNetCDF is the Ruby interface of the NetCDF library. Ruby is a free object-oriented scripting language and is freely available from (()). To handle numeric data, RubyNetCDF uses (()), which is the standard numeric multi-dimensional array class for Ruby. Thus, you have to have installed it before installing this library. An NArray object holds numeric data in a consecutive memory area pointed by a C pointer. Thus, it is computationally efficient. NArray is similar to NumPy for Python, but results of some benchmark tests suggests that NArray is more efficient than NumPy. Optionally, RubyNetCDF offers methods to handle data missing automatically. To use it, you will also need (()). See (()) for details. Currently, NetCDF-4 support is partial (the new data models have not been supported). ===Structure RubyNetCDF consists of the four classes in the following. * (()) -- the file class An NetCDF object represents a NetCDF file * (()) -- the dimension class Although in its C version a NetCDF dimension is represented by a combination of a file ID and a dimension ID, it is represented by only one NetCDFDim object in RubyNetCDF. * (()) -- the variable class Although in its C version a NetCDF variable is represented by a combination of a file ID and a variable ID, it is represented by only one NetCDFVar object in RubyNetCDF. * (()) -- the attribute class Although in its C version a NetCDF attribute is represented by a combination of file ID, variable ID, and its name, it is represented by only one NetCDFAtt object in RubyNetCDF. ===Data type All the NetCDF variable types char, byte, short, int, float, and double are supported in this Ruby interface. These types are called, however, differently in it to adhere to the convention of Ruby, or, more specifically, of NArray. These types are named to as "char", "byte", "sint", "int", "sfloat", and "float", respectively. Therefore, the vartype (=ntype) method of the NetCDFVar class returns one of these strings. The def_var method of the NetCDF class also accepts one of them to define a variable. It should be noted especially that "float" in this library means the double in the NetCDF terminology. This is due to the convention of Ruby -- the predefined Float class corresponds to the double in C, not the float. The "get" method of NetCDFVar class reads a variable in a NArray of the same type as in the file, except for the "char" type which is read into a "byte". This is because NArray does not have a "char" type. However, it not is not supposed to be a problem, since a byte NArray can easily handle string data. ===Error handling Errors are basically handled by raising exceptions. However, light errors in value-returning methods are handled by returning nil (e.g., if a non-existent attribute name is specified in attribute reading). Those methods that return nil on error are explicitly written as such in the following. ===Security features Security handling is done just as in the pre-defined File class. ===Usage To use the RubyNetCDF library, load the library first by placing the following line in your Ruby program to load the library: require 'numru/netcdf' If you want to use automatic data-missing-handling methods (of NetCDFVar class), use the following: require 'numru/netcdf_miss' This will call (({require 'numru/netcdf'})) inside at the beginning, so you do not have to call the both. The missing-data handling is done with (()), so you have have installed it. This is, however, not needed if you only call (({require 'numru/netcdf'})). Here, 'numru', which stands for "Numerical Ruby", is the name of the subdirectory in the user's load path where the RubyNetCDF library is placed. Then, it can be used as in the following: file = NumRu::NetCDF.create('tmp.nc') x = file.def_dim('x',10) y = file.def_dim('y',10) v = file.def_var('v','float',[x,y]) file.close Here, NumRu is the module that has the library in it. The reason why NetCDF library is wrapped in such a module is to avoid conflicts in the name space. Without this kind of treatment, problems happen if the user wants to use a library that happens to have a class or module with the same name as even one of the classes in this library. If such a problem is not expected to happen, the prefix "NumRu::" can be eliminated by "including" the NumRu module as in the following, so that to place "NumRu::" is not needed anymore in the current scope: include NumRu file = NetCDF.create('tmp.nc') ... For more examples, see demo and test programs included in the distribution package. --------------------------------------------- ==How to read this manual --- method_name(argument1, argument2, ...) -- arguments that can be omitted are expressed as Argument_name=Default_value Explanation of its function Arguments * name of argument1 (its class or possible values): explanation * name of argument2 (its class or possible values): explanation * ... Return value * Explanation of the return value Corresponding (dependent) function(s) in the C library of NetCDF * Name(s) in NetCDF ver 3. The function equivalent to the current method, if not in parenthesis. If no direct correspondence, dependent functions are listed in parentheses. --------------------------------------------- ==Method Index * (()) Class Methods * (()) returens wheather the linked library is NetCDF-4 (true/false) * (()) Set the file format created by NetCDF.create (for NetCDF-4 only). * (()) Returns the current setting of the creation format (for NetCDF-4 only). * (()) Opens a file (class method). If mode="w" and non-existent, a new * (()) Aliased to NetCDF.open * (()) Creates a NetCDF file (class method) * (()) Creates a temporary NetCDF file (class method) Instance Methods * (()) Closes the file. * (()) Returns the number of dimensions in the file * (()) Returns the number of variables in the file * (()) Returns the number of global attributes in the file * (()) Returns the unlimited dimension in the file * (()) Returns the path of the file (contents of the filename specified when opened/created) * (()) Switches to the define mode. Does nothing if already in it (nil returned). * (()) Switches to the data mode. Does nothing if already in it (nil returned). * (()) Inquire whether the file is in the define mode. * (()) Synchronizes the disk copy of a netCDF dataset with in-memory buffer * (()) Define a dimension * (()) Sets a global attribute * (()) Defines a variable * (()) Same as def_var but defines dimensions first if needed * (()) Opens an existing variable in the file * (()) Opens existing variables in the file * (()) Opens an existing dimension in the file * (()) Opens existing dimensions in the file * (()) Opens an existing global attribute in the file * (()) Sets a fill mode. (Default behavior of NetCDF is FILL.) * (()) Iterator regarding the dimensions in the file. * (()) Iterator regarding the variables in the file. * (()) Iterator regarding the global attributes of the file. * (()) Returns the names of all dimensions in the file * (()) Returns the names of all variables in the file * (()) Returns the names of all the global attributes of the file * (()) Class Methods Instance Methods * (()) Returns the length of the dimension * (()) Same as length but returns 0 for the unlimited dimension * (()) Rename the dimension * (()) Returns the name of the dimension * (()) Inquires whether the dimension is unlimited or not * (()) Class Methods * (()) Combines NetCDF.open and NetCDF#Var to open a variable with one line (no need to use this). * (()) Fix the NArray type to be used in (()) * (()) Returns the NArray type set by (()). Instance Methods * (()) Sets "deflation" (compression). (netCDF-4 only) * (()) Retuns present deflation parameters. (netCDF-4 only) * (()) Sets (changes) the endian. (netCDF-4 only) * (()) Retunrs the present endian setting. (netCDF-4 only) * (()) Inquires the dim_num-th dimension of the variable (dim_num=0,1,2,..) * (()) Returns an array of all the dimensions of the variable * (()) Returns the shape of the variable, but the length of the unlimited dimension is set to zero. * (()) Returns the current shape of the variable. ## * (()) Returns a combination of filename (path) and variable name as path+'?var='+varname * (()) Iterator regarding the global attributes of the variables. * (()) Returns the names of all the dimensions of the variable * (()) Returns the names of all the attributes of the variable * (()) Returns the name of the variable * (()) Rename the variable * (()) Number of dimensions of the variable (which is rank of the variable). * (()) aliased to ndims * (()) Aliased to vartype * (()) Inquires the data value type of the variable * (()) Inquires the data type of the variable (returns a typecode of NArray) * (()) Returns the number of the attributes of the variable * (()) Inquires the file that the variable is in * (()) Returns the attribute specified by its name * (()) Sets an attribute * (()) Aliased to (()) * (()) Set the values of the variable * (()) Pack a NArray (etc) using the attributes scale_factor and/or add_offset of self. * (()) Same as (()) but interprets the attributes scale_factor and/or add_offset using (()). * (()) Aliased to (()) * (()) Returns values of the variable * (()) Unpack a NArray (etc) using the attributes scale_factor and/or add_offset of self. * (()) Same as (()) but interprets the attributes scale_factor and/or add_offset using (()). * ((<[]>)) Same as NetCDFVar#get but a subset is specified as in the method [] of NArray. * ((<[]=>)) Same as NetCDFVar#put but a subset is specified as in the method []= of NArray. Instance Methods added by requiring "numru/netcdf_miss" * (()) Same as (()) but interprets data missing. * (()) Same as (()) but handles data scaling too. * (()) Same as (()) but interprets data missing. * (()) Same as (()) but handles data scaling too. * (()) Class Methods Instance Methods * (()) Returns the name of the attribute * (()) Rename the attribute * (()) Copies an attribute to a variable or a file. If file, becomes an global attribute * (()) Delete an attribute * (()) Sets the value of the attribute * (()) Returns the values of the attribute * (()) Inquires the type of attribute values * (()) Inquires the type of attribute values (returns a NArray typecode) --------------------------------------------- =class NetCDF ===constants * NC_NOWRITE, NC_WRITE, NC_SHARE, NC_CLOBBER, NC_NOCLOBBER, NC_64BIT_OFFSET, NC_NETCDF4, NC_CLASSIC_MODEL, NCVERSION, SUPPORT_BIGMEM : these constants can accessed by NumRu::NetCDF::NC_NOWRITE etc. ===Class Methods ---NetCDF.nc4? Returens wheather the linked NetCDF library is NetCDF-4 (true/false). false means that it is version 3. ---NetCDF.creation_format=(cmode) (Available only when NetCDF version 4 is used. Error is raised if not.) Set the file format created by NetCDF.create. The initial setting is "classic" (conventional netcdf 3 format). Arguments * cmode : one of the following: * 0, nil, or NetCDF::NC_CLASSIC_MODEL : the classic format (original NetCDF-3 format). This is the default setting of RubyNetCDF. * NetCDF::NC_64BIT_OFFSET : classic but supports larger variables * NetCDF::NC_NETCDF4 : The new NetCDF-4 format based on HDF5 * ( NetCDF::NC_NETCDF4 | NetCDF::NC_CLASSIC_MODEL) [bit "or" of NetCDF::NC_NETCDF4 and NetCDF::NC_CLASSIC_MODEL ]: the new NetCDF-4 format but new data models are disabled. ---NetCDF.creation_format (Available only when NetCDF version 4 is used. Error is raised if not.) Returns the current setting of the creation format. ---NetCDF.open(filename, mode="r", share=false) Opens a file (class method). If mode="w" and the file does not exist, a new file is created. Arguments * filename (String): file name (path) * mode (String) : IO mode "r" (read only); "w","w+" (write -- current contents are overwritten (eliminated!)); "r+","a","a+" (append -- writable while current contents are preserved). All the options permit reading, unlike the predefined File class. Note that to "append" will require extra time and disk space due to the limitations of the original NetCDF library, which is used in this library. * share (true or false) : Whether to use the "shared" mode or not (set true if a file being written may be read from other processes. See nc_open in Ch.5 of users' guide of the C version) Return value * a NetCDF object Corresponding (dependent) function(s) in the C library of NetCDF * nc_open, nc_create ---NetCDF.new Aliased to NetCDF.open ---NetCDF.create(filename, noclobber=false, share=false) Creates a NetCDF file (class method) Arguments * filename (String) : file name (path) * noclobber (true or false) : overwrite or not if the file exists * share (true or false) : Whether to use the shared mode or not (set true if a file being written may be read from other processes. See nc_open in Ch.5 of users' guide of the C version) Return value * a NetCDF object Corresponding (dependent) function(s) in the C library of NetCDF * nc_create ---NetCDF.create_tmp(tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'.', share=false) Creates a temporary NetCDF file (class method). Its name is automatically generated, and it is deleted when closed. Arguments * tmpdir (String) : directory to place the temporary file. By default, "." or a directory specified by an environmental variable (TMPDIR or TMP or TEMP) is used. In a secure mode, theses environmental variable is NOT used, and the default value is '.'. * share (true or false) : Whether to use the shared mode or not Return value * a NetCDF object Corresponding (dependent) function(s) in the C library of NetCDF * nc_create ===Instance Methods ---close Closes the file. Arguments * (none) Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_close ---ndims Returns the number of dimensions in the file Arguments * (none) Return value * Integer Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_ndims ---nvars Returns the number of variables in the file Arguments * (none) Return value * Integer Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_nvars ---natts Returns the number of global attributes in the file Arguments * (none) Return value * Integer Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_natts ---unlimited Returns the unlimited dimension in the file Arguments * (none) Return value * a NetCDFDim if it exists; nil if not Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_unlimdim ---path Returns the path of the file (contents of the filename specified when opened/created) Arguments * (none) Return value * String Corresponding (dependent) function(s) in the C library of NetCDF * (none) ---redef Switches to the define mode. Does nothing if already in it (nil returned). Arguments * (none) Return value * true if successfully switched to the define mode; nil if the file is already in the define mode. Exception is raised if unsuccessful for other reasons. Corresponding (dependent) function(s) in the C library of NetCDF * nc_redef ---enddef Switches to the data mode. Does nothing if already in it (nil returned). Arguments * (none) Return value * true if successfully switched to the data mode; nil if the file is already in the data mode. Exception is raised if unsuccessful for other reasons. Corresponding (dependent) function(s) in the C library of NetCDF * nc_enddef ---define_mode? Inquire whether the file is in the define mode. Arguments * (none) Return value * true if the data is in the define mode; false if the file is in the data mode; nil otherwise (possibly the file is read-only). Corresponding (dependent) function(s) in the C library of NetCDF * combination of nc_redef and nc_enddef ---sync Synchronizes the disk copy of a netCDF dataset with in-memory buffer Arguments * (none) Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_sync ---def_dim(dimension_name, length) Define a dimension Arguments * dimension_name (String) : Name of the dimension to be defined * length (Integer) : length of the dimension. 0 for unlimited. Return value * defined dimension (NetCDFDim object) Corresponding (dependent) function(s) in the C library of NetCDF * nc_def_dim ---put_att(attribute_name, value, atttype=nil) Sets a global attribute Arguments * attribute_name (String) : name of the global attribute * value (Numeric, String, Array of Numeric, or NArray) : value of the attribute * atttype (nil or String) : data type of the attribute value. nil lets it automatically determined from the value. "char" (or "string"), "byte", "sint", "int", "sfloat", or "float" specifies the type explicitly (1,1,2,4,4,8 bytes, respectively) Return value * created attribute (NetCDFAtt object) Corresponding (dependent) function(s) in the C library of NetCDF * nc_put_att_ ---def_var(name, vartype, dimensions) Defines a variable Arguments * name (String) : Name of the variable to define * vartype (String or Fixnum) : data type of the variable ("char", "byte", "sint", "sint", "int", "sfloat", or "float"), or a NArray typecodes(Fixnum) * dimensions (Array) : Dimensions of the variable. An Array of NetCDFDim, in the order from the fastest varying dimension to the slowest varying one; its length becomes the rank of the variable. Return value * defined variable (NetCDFVar object) Corresponding (dependent) function(s) in the C library of NetCDF * nc_def_var ---def_var_with_dim(name, vartype, shape_ul0, dimnames) Same as def_var but defines dimensions first if needed. Raise exception if it conflicts with the lengths of existing dimensions. Arguments * name (String) : Name of the variable to define * vartype (String) : data type of the variable ("char", "byte", "sint", "sint", "int", "sfloat", or "float") * shape_ul0 (Array of Integer) : Shape of the variable, i.e., lengths of dimensions. The unlimited dimension is specified by zero. The length of shape_ul0 determines the rank of the variable. * dimnames (Array of String) : Names of the dimensions. Its length (=>rank) must be equal to that of shape_ul0 Return value * defined variable (NetCDFVar object) Corresponding (dependent) function(s) in the C library of NetCDF * (nc_def_var) ---var(var_name) Opens an existing variable in the file Arguments * var_name (String) : Name of the variable to open Return value * a NetCDFVar object; nil if the variable does not exist Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_varid ---vars(names) Opens existing variables in the file Arguments * names (nil or Array of String): Names of the variables to open; all variables are returned if nil (default). Return value * Array of NetCDFVar objects; exception is raised if names has a non-existent name Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_varid ---dim(dimension_name) Opens an existing dimension in the file Arguments * dimension_name (String) : Name of the dimension to open Return value * a NetCDFDim object; nil if the dimension does not exist Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_dimid ---dims(names) Opens existing dimensions in the file Arguments * names (nil or Array of String): Names of the dimensions to open; all dimensions are returned if nil (default). Return value * Array of NetCDFDim objects; exception is raised if names has a non-existent name Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_dimid ---att(attribute_name) Opens an existing global attribute in the file Arguments * attribute_name (String) : Name of the global attribute to open Return value * a NetCDFAtt object if the attribute exists; nil if not Corresponding (dependent) function(s) in the C library of NetCDF * (nc_inq_attid used for inquiry) ---fill=(filemode) Sets a fill mode. (Default behavior of NetCDF is FILL.) Arguments * fillmode (true or false) Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_set_fill ---each_dim{ ... } Iterator regarding the dimensions in the file. Ex.: {|i| print i.name,"\n"} prints names of all dimensions Arguments * { ... } : Block for the iterator. A "do end" block is the alternative. Return value * self Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_ndims) ---each_var{ ... } Iterator regarding the variables in the file. Ex.: {|i| print i.name,"\n"} prints names of all variables Arguments * { ... } : Block for the iterator. A "do end" block is the alternative. Return value * self Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_nvars) ---each_att{ ... } Iterator regarding the global attributes of the file. Ex.: {|i| print i.name,"\n"} prints names of all of them. Arguments * { ... } : Block for the iterator. A "do end" block is the alternative. Return value * self Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_natts, nc_inq_attname) ---dim_names Returns the names of all dimensions in the file Arguments * (none) Return value * Array of NetCDFDim Corresponding (dependent) function(s) in the C library of NetCDF * (nc_inq_ndims, nc_inq_dimname) ---var_names Returns the names of all variables in the file Arguments * (none) Return value * Array of String Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_nvars, nc_inq_varname) ---att_names Returns the names of all the global attributes of the file Arguments * (none) Return value * Array of NetCDFAtt Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_natts, nc_inq_attname) --------------------------------------------- =class NetCDFDim ===Class Methods ===Instance Methods ---length Returns the length of the dimension Arguments * (none) Return value * Integer Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_dimlen ---length_ul0 Same as length but returns 0 for the unlimited dimension Arguments * (none) Return value * Integer Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_dimlen ---name=(dimension_newname) Rename the dimension Arguments * dimension_newname (String) : new name Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_rename_dim ---name Returns the name of the dimension Arguments * (none) Return value * String Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_dimname ---unlimited? Inquires whether the dimension is unlimited or not Arguments * (none) Return value * true or false Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_unlimdim) --------------------------------------------- =class NetCDFVar ===Class Methods ---NetCDFVar.new(file,varname,mode="r",share=false) open a NetCDF variable. This can also be done with NetCDF#var (instance method of NetCDF class), which is recommended over this method. Arguments * file (NetCDF or String) : a NetCDF file object (NetCDF) or the path of a NetCDF file (String). * varname (String) : name of the variable in the file * mode (String) : IO mode -- used if file is a String (see NetCDF.open) * share (true or false) : Whether to use the "shared" mode or not -- used if file is a String (see NetCDF.open) Return value * a NetCDFVar object Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_open, nc_create, nc_inq_varid etc.) ---NetCDFVar.unpack_type=(na_type) Fix the NArray type to be used in (()). Arguments * na_type (Integer) : NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, or NArray::FLOAT Return value * na_type (the argument) ---NetCDFVar.unpack_type Returns the NArray type set by (()). Return value * nil, NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, or NArray::FLOAT ===Instance Methods ---deflate(deflate_level, shuffle=false) (Available only when NetCDF version 4 is used. Error is raised if not.) Makes the current (newly created) variable "deflated" (=compressed). This method must be called after defining a variable (NetCDF#(())) and before calling NetCDF#(()). Arguments * deflate_level (Integer) :: 0 to 9. (0: no compression; 9: highest compression; recommended: 1 or 2). * shuffle (optional; true or false; default: false) if true, turn on the shuffle filter. * (()): ``The shuffle algorithm changes the byte order in the data stream; when used with integers that are all close together, this results in a better compression ratio. There is no benefit from using the shuffle filter without also using compression.'' * Note: shuffle is effective for float variables too (tested by horinouchi). Return value * self ---deflate_params (Available only when NetCDF version 4 is used. Error is raised if not.) Returns the present deflation parameters. Return value * [shuffle, deflate, deflate_level] (a 3-element Array), where the values of shuffle and deflate are true or false, and deflate_level is an Integer (0-9). ---endian=(endian) (Available only when NetCDF version 4 is used. Error is raised if not.) Sets (changes) the endian. See (()) for when to use it. Arguments * endian : one of the following constants: NetCDF::NC_ENDIAN_NATIVE (=0) (default), NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2). Return value * self ---endian (Available only when NetCDF version 4 is used. Error is raised if not.) Returns the current endian setting. Return value * one of the following constants: NetCDF::NC_ENDIAN_NATIVE (=0) (default), NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2). ---dim(dim_num) Inquires the dim_num-th dimension of the variable (dim_num=0,1,2,..) Arguments * dim_num (Fixnum) : 0,1,... 0 is the fastest varying dimension. Return value * a NetCDFDim object Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_vardimid) ---dims Returns an array of all the dimensions of the variable Arguments * (none) Return value * Array of NetCDFDim objects. Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_vardimid ---shape_ul0 Returns the shape of the variable, but the length of the unlimited dimension is set to zero. Good to define another variable. Arguments * (none) Return value * Array. [length of 0th dim, length of 1st dim,.. ] Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_vardimid, nc_inq_unlimdim etc) ---shape_current Returns the current shape of the variable. Arguments * (none) Return value * Array. [length of 0th dim, length of 1st dim,.. ] Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_vardimid etc) ---each_att{ ... } Iterator regarding the global attributes of the variables. Ex.: {|i| print i.name,"\n"} prints names of all of them. Arguments * { ... } : Block for the iterator. A "do end" block is the alternative. Return value * self Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_natts, nc_inq_attname) ---dim_names Returns the names of all the dimensions of the variable Arguments * (none) Return value * Array of String Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_varndims, nc_inq_vardimid, nc_inq_dimname) ---att_names Returns the names of all the attributes of the variable Arguments * (none) Return value * Array of String Corresponding (dependent) function(s) in the C library of NetCDF * (dependent on nc_inq_natts, nc_inq_attname) ---name Returns the name of the variable Arguments * (none) Return value * String Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_varname ---name=(variable_newname) Rename the variable Arguments * variable_newname (String) : new name Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_rename_var ---ndims Number of dimensions of the variable (which is rank of the variable). Arguments * (none) Return value * Integer Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_varndims ---rank Aliased to ndims ---ntype Aliased to vartype ---vartype Inquires the data value type of the variable Arguments * (none) Return value * String ("char","byte","sint","int","sfloat", or "float") Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_vartype ---typecode Inquires the data type of the variable (returns a typecode of NArray) Arguments * (none) Return value * a Fixnum (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT) Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_vartype ---natts Returns the number of the attributes of the variable Arguments * (none) Return value * Integer Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_varnatts ---file Inquires the file that the variable is in Arguments * (none) Return value * a NetCDF object Corresponding (dependent) function(s) in the C library of NetCDF * (none) ---att(attribute_name) Returns the attribute specified by its name Arguments * attribute_name (String) : Name of the attribute Return value * a NetCDFAtt object if the attribute exists; nil if not Corresponding (dependent) function(s) in the C library of NetCDF * (nc_inq_attid is used for inquiry) ---put_att(attribute_name, value, atttype=nil) Sets an attribute Arguments * attribute_name (String) : name of the attribute * value (Numeric, String, Array of Numeric, or NArray) : value of the attribute * atttype (nil or String) : data type of the attribute value. nil lets it automatically determined from the value. "char" (="string"), "byte", "sint", "int", "sfloat", or "float" specifies the type explicitly (1,1,2,4,4,8 bytes, respectively) Return value * a NetCDFAtt object Corresponding (dependent) function(s) in the C library of NetCDF * nc_put_att_ ---put(value, option=nil) Aliased to (()) ---simple_put(value, option=nil) Set the values of the variable Arguments * value : value to set (Numeric, Array of Numeric (1D only), or NArray (possibly multi-D)). If it is a Numeric or length==1, the value is set uniformly. * option (Hash) : Optional argument to limit the portion of the variable to output values. If omitted, the whole variable is subject to the output. This argument accepts a Hash whose keys contain either "index" or a combination of "start","end", and "stride". The value of "index" points the index of a scalar portion of the variable. The other case is used to designate a regularly ordered subset, where "start" and "end" specifies bounds in each dimension and "stride" specifies intervals in it. As in Array "start", "end", and "index" can take negative values to specify index backward from the end. However, "stride" has to be positive, so reversing the array must be done afterwards if you like. Example: If the variable is 2D: {"start"=>[2,5],"end"=>[6,-1],"stride"=>[2,4]} -- Specifies a subset made as follows: the 1st dimension from the element 2 to the element 6 (note that the count starts with 0, so that the element 2 is the 3rd one) with an interval of 2; the 2nd dimension from the element 6 to the last element (designated by -1) with an interval of 5. {"index"=>[0,0]}: Scalar of the fist element {"index"=>[0,-2]}: Scalar from the 1st element of with respect to the 1st dimension and the 2nd element from the last with respect to the 2nd dimension Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_put_var_, nc_put_vars_, nc_put_var1_ ---pack(na) Pack a NArray (etc) using the attributes scale_factor and/or add_offset of self. If scale_factor and/or add_offset is defined, returns (na-add_offset)/scale_factor. Returns na if not. Arguments * na : a numeric array to pack (NArray, NArrayMiss, or Array) Return value * a NArray or NArrayMiss ---scaled_put(value, option=nil) Same as (()) but interprets the attributes scale_factor and/or add_offset using (()). See the document for (()) for arguments etc. ---get(option=nil) Aliased to (()). ---simple_get(option=nil) Returns values of the variable Arguments * option (Hash) : Optional argument to limit the portion of the variable to get values. Its usage is the same as in the method put. Return value * an NArray object Corresponding (dependent) function(s) in the C library of NetCDF * nc_get_var_, nc_get_vars_, nc_get_var1_ ---unpack(na) Unpack a NArray (etc) using the attributes scale_factor and/or add_offset of self. If scale_factor and/or add_offset is defined, returns na * scale_factor + add_offset. Returns na if not. Type conversion is made by the coercing -- for example if na is sint and scale_factor and add_offset is sfloat, return value is sfloat. The type of the return value can be specified explicitly with (()). Arguments * na : a numeric array to unpack (NArray, or NArrayMiss) Return value * a NArray or NArrayMiss ---scaled_get(option=nil) Same as (()) but interprets the attributes scale_factor and/or add_offset using (()). See the document for (()) for arguments etc. ---[] Same as NetCDFVar#get but a subset is specified as in the method [] of NArray. In addition to the subset specifications supported by NArray, ranges with steps are supported, which is specified like {0..-1, 3}, i.e., a 1-element Hash with the key and value representing the range (Range) and the step (Integer), respectively. Unlike NArray, 1-dimensional indexing of multi-dimensional variables is not support. ---[]= Same as NetCDFVar#put but a subset is specified as in the method []= of NArray. In addition to the subset specifications supported by NArray, ranges with steps are supported, which is specified like {0..-1, 3}, i.e., a 1-element Hash with the key and value representing the range (Range) and the step (Integer), respectively. Unlike NArray, 1-dimensional indexing of multi-dimensional variables is not support. ===Instance Methods added by requiring "numru/netcdf_miss" ---get_with_miss(option=nil) Same as (()) but interprets data missing. Data missing is specified by the standard attributes valid_range, (valid_min and/or valid_max), or missing_value, with the precedence being this order. Unlike the recommendation in the NetCDF User's guide, missing_value is interpreted if present. If missing_value and valid_* present simultaneously, missing_value must be outside the valid range. Otherwise, exception is raised. If data missing is specified as stated above, this method returns a NArrayMiss. If not, it returns a NArray. Thus, you can use this whether data missing is defined or not. Arguments * See (()). Return value * an NArrayMiss (if data missing is specified) or an NArray (if data missing is NOT specified) Possible exception in addition to NetcdfError. * missing_value is in the valid range (see above). Corresponding (dependent) function(s) in the C library of NetCDF * See (()). This method is written in Ruby. EXAMPLE * The following is an example to replace (()) with (()). It will also make ((<[]>)) interpret data missing, since it calls (({get})) internally. file = NetCDF.open('hogehoge.nc') var = file.var('var') def var.get(*args); get_with_miss(*args); end p var.get # --> interprets data missing if defined p var[0..-1,0] # --> interprets data missing if defined (assumed 2D) ---get_with_miss_and_scaling(option=nil) Same as (()) but handles data scaling too using (()). Missing data handling using valid_* / missing_value is applied basically to packed data, which is consistent with most conventions. However, it is applied to unpacked data if and only if the type of valid_* / missing_value is not the same as the packed data and is the samed as the unpacked data. This treatment can handle all conventions. EXAMPLE * See above. The same thing applies. ---put_with_miss(value, option=nil) Same as (()) but interprets data missing. If (({value})) is an NArray, the methods behaves as (()). Data missing in (({value})) is interpreted if it is an NArrayMiss and data missing is specified by attributes in (({self})) (see (()) ). Namely, the data which are "invalid" in the (({value})) is replaced with a missing value when written in the file. (missing_value or _FillValue or a value outside the valid range). No check is made whether "valid" values in the NArrayMiss is within the valid range of (({self})). Arguments * value : NArrayMiss or what is allowed in (()). * option (Hash) : See (()). Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * See (()). This method is written in Ruby. EXAMPLE * The following is an example to replace (()) with (()). It will also make ((<[]=>)) interpret data missing, since it calls (({put})) internally. file = NetCDF.open('hogehoge.nc') var = file.var('var') def var.put(*args); put_with_miss(*args); end var.put = narray_miss # --> interprets data missing if defined var[0..-1,0] = narray_miss # --> interprets data missing if defined (assumed 2D) ---put_with_miss_and_scaling(value, option=nil) Same as (()) but handles data scaling too using (()). Missing data handling using valid_* / missing_value is applied basically to packed data, which is consistent with most conventions. However, it is applied to unpacked data if and only if the type of valid_* / missing_value is not the same as the packed data and is the samed as the unpacked data. This treatment can handle all conventions. EXAMPLE * See above. The same thing applies. --------------------------------------------- =class NetCDFAtt ===Class Methods ===Instance Methods ---name Returns the name of the attribute Arguments * (none) Return value * String Corresponding (dependent) function(s) in the C library of NetCDF * (none) ---name=(attribute_newname) Rename the attribute Arguments * attribute_newname (String) : New name Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_rename_att ---copy(var_or_file) Copies an attribute to a variable or a file. If file, becomes an global attribute Arguments * var_or_file (NetCDFVar or NetCDF) Return value * Resultant new attribute (NetCDFAtt) Corresponding (dependent) function(s) in the C library of NetCDF * nc_copy_att ---delete Delete an attribute Arguments * (none) Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_del_att ---put(value, atttype=nil) Sets the value of the attribute Arguments * value (Numeric, String, Array of Numeric, or NArray) : value of the attribute * atttype (nil or String) : data type of the attribute value. nil lets it automatically determined from the value. "char" (="string"), "byte", "sint", "int", "sfloat", or "float" specifies the type explicitly (1,1,2,4,4,8 bytes, respectively) Return value * nil Corresponding (dependent) function(s) in the C library of NetCDF * nc_put_att_ ---get Returns the values of the attribute Arguments * (none) Return value * String or an NArray object (NOTE: even a scalar is returned as an NArray of length 1) Corresponding (dependent) function(s) in the C library of NetCDF * nc_get_att_ ---atttype Inquires the type of attribute values Arguments * (none) Return value * "char","byte","sint","int","sfloat","float" Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_atttype ---atttype Inquires the type of attribute values (returns a NArray typecode) Arguments * (none) Return value * a Fixnum (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT) Corresponding (dependent) function(s) in the C library of NetCDF * nc_inq_atttype =end ruby-netcdf-0.7.2/doc/Ref_man_jp.rd0000644000175000017500000011441412772251340016742 0ustar uwabamiuwabami=begin =RubyNetCDF ¥ì¥Õ¥¡¥ì¥ó¥¹¥Þ¥Ë¥å¥¢¥ë RubyNetCDF version : 0.7.1 * ((<¥á¥½¥Ã¥É¥¤¥ó¥Ç¥Ã¥¯¥¹>)) --------------------------------------------- ==³µÍ× RubyNetCDF ¤Ï NetCDF ¥é¥¤¥Ö¥é¥ê¡¼¤Î Ruby ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ç¤¢¤ë¡£Ruby ¤Ï¥Õ¥ê¡¼¤Ê¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¥¹¥¯¥ê¥×¥È¸À¸ì¤Ç¤¢¤ê¡¢ ((<¤³¤³|URL:http://www.ruby-lang.org/>)) ¤«¤éÆþ¼ê¤Ç¤­¤ë¡£RubyNetCDF ¤Ï¿ôÃÍÇÛÎó¤È¤·¤Æ¡¢ Ruby ¤Ç°ìÈÌŪ¤Ë»È¤ï¤ì¤Æ¤¤¤ë¿¼¡¸µ¿ôÃÍÇÛÎó¥é¥¤¥Ö¥é¥ê¡¼ (()) ¤òÍѤë¤Î¤Ç¡¢¤¢¤é¤«¤¸¤á¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤ª¤¯É¬Íפ¬¤¢¤ë¡£ NArray ¤Ï¥Ç¡¼¥¿¤ò¡¢C ¤Î¥Ý¥¤¥ó¥¿¡¼¤¬»Ø¤¹Ï¢Â³¤·¤¿¥á¥â¥ê¡¼ÎÎ°è ¤ËÊÝ»ý¤·¡¢·×»»µ¡»ñ¸»¤ò¸úΨ¤è¤¯ÍøÍѤ¹¤ë¡£NArray ¤Ï Python ¤Ë¤ª¤±¤ë NumPy ¤È»÷¤ë¤¬¡¢´ö¤Ä¤«¤Î¥Æ¥¹¥È¤Ï NArray ¤Î¤Û¤¦¤¬ NumPy ¤è¤ê¸úΨ¤¬Îɤ¤ ¤³¤È¤ò¼¨º¶¤·¤Æ¤¤¤ë¡£ ¥ª¥×¥·¥ç¥ó¤È¤·¤Æ¡¢RubyNetCDF ¤Ï¥Ç¡¼¥¿·ç»¤Î¼«Æ°Åª¤Ê¼è¤ê°·¤¤¥á¥½¥Ã¥É¤ò Ä󶡤¹¤ë¡£¤³¤ì¤ò»È¤¦¤Ë¤Ï¡¢ (()) ¤¬É¬ÍפǤ¢¤ë¡£¾Ü¤·¤¯¤Ï((<»ÈÍÑË¡>))¤ò¸«¤è¡£ ¸½ºß NetCDF-4 ¤Î¥µ¥Ý¡¼¥È¤ÏÉôʬŪ¤Ç¤¢¤ë(¿·¤·¤¤¥Ç¡¼¥¿¥â¥Ç¥ë¤Ï¥µ¥Ý¡¼¥È¤·¤Æ¤Ê¤¤)¡£ ===¹½À® RubyNetCDF ¤Ï°Ê²¼¤Î£´¤Ä¤Î¥¯¥é¥¹¤«¤é¹½À®¤µ¤ì¤ë¡£ * ((<¥¯¥é¥¹ NetCDF>)) -- ¥Õ¥¡¥¤¥ë¤Î¥¯¥é¥¹ °ì¤Ä¤ÎNetCDF¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ï°ì¤Ä¤Î NetCDF ¥Õ¥¡¥¤¥ë¤ËÂбþ¤¹¤ë * ((<¥¯¥é¥¹ NetCDFDim>)) -- ¼¡¸µ¤Î¥¯¥é¥¹ C ÈÇ NetCDF ¤Ç¤Ï¡¢¼¡¸µ¤Ï¡¢¥Õ¥¡¥¤¥ë¤ÎID¤È¼¡¸µID¤È¤¤¤¦£²ÊÑ¿ô¤ÎÁȤÇɽ¤µ¤ì¤ë¤¬¡¢ Ruby ÈǤǤϰì¤Ä¤Î NetCDFDim ¥ª¥Ö¥¸¥§¥¯¥È¤ÇÂåɽ¤µ¤ì¤ë * ((<¥¯¥é¥¹ NetCDFVar>)) -- ÊÑ¿ô¤Î¥¯¥é¥¹ C ÈÇ NetCDF ¤Ç¤Ï¡¢ÊÑ¿ô¤Ï¡¢¥Õ¥¡¥¤¥ë¤ÎID¤ÈÊÑ¿ôID¤È¤¤¤¦£²ÊÑ¿ô¤ÎÁȤÇɽ¤µ¤ì¤ë¤¬¡¢ Ruby ÈǤǤϰì¤Ä¤Î NetCDFVar ¥ª¥Ö¥¸¥§¥¯¥È¤ÇÂåɽ¤µ¤ì¤ë * ((<¥¯¥é¥¹ NetCDFAtt>)) -- °À­¤Î¥¯¥é¥¹ C ÈÇ NetCDF ¤Ç¤Ï¡¢Â°À­¤Ï¡¢¥Õ¥¡¥¤¥ë¤ÎID¤ÈÊÑ¿ôID¤È°À­Ì¾¤ÎÁȤÇɽ¤µ¤ì¤ë¤¬¡¢ Ruby ÈǤǤϰì¤Ä¤Î NetCDFAtt ¥ª¥Ö¥¸¥§¥¯¥È¤ÇÂåɽ¤µ¤ì¤ë ===¥Ç¡¼¥¿·¿ Ëܥ饤¥Ö¥é¥ê¡¼¤Ç¤ÏÁ´¤Æ¤Î NetCDF ÊÑ¿ô¤Î·¿ char, byte, short, int, float, double ¤¬¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¡£¤·¤«¤·¡¢¤³¤ì¤é¤Ï Ruby ¤Î¡Ê¤è¤êÀµ³Î ¤Ë¸À¤¦¤È NArray ¤Î¡Ë´·Îã¤Ë½¾¤Ã¤Æ¡¢¤½¤ì¤¾¤ì "char", "byte", "sint", "int", "sfloat", "float" ¤È¸Æ¤Ð¤ì¤ë¡£½¾¤Ã¤Æ¡¢NetCDFVar ¥¯¥é¥¹¤Î vartype (=ntype) ¤Ï¤³¤ì¤é¤Îʸ»úÎó¤Î°ì¤Ä¤òÊÖ¤¹¡£¤Þ¤¿¡¢NetCDF¥¯¥é¥¹¤Î def_var ¥á ¥½¥Ã¥É¤Ï¡¢ÊÑ¿ô¤òÄêµÁ¤¹¤ëºÝ¡¢¤³¤ì¤é¤ò¼õ¤±ÉÕ¤±¤ë¡£ÆÃ¤ËÃí°Õ¤¹¤ëɬÍפ¬¤¢¤ë ¤Î¤Ï¡¢Ëܥ饤¥Ö¥é¥ê¡¼¤Ç¤Î "float" ¤Ï C ¤Ç¸À¤¦¤È¤³¤í¤Î double ¤ò°ÕÌ£¤¹¤ë ¤È¤¤¤¦¤³¤È¤Ç¤¢¤ë¡£¤³¤ì¤Ï Ruby ¤Î´·Îã¤Î¤»¤¤¤Ç¤¢¤ë -- ÁȤ߹þ¤ß¤Î Float ¥¯¥é¥¹¤Ï¡¢C ¤Î float ¤Ç¤Ê¤¯ double ¤ËÂбþ¤¹¤ë¤Î¤Ç¤¢¤ë¡£ NetCDFVar ¥¯¥é¥¹¤Î get ¥á¥½¥Ã¥É¤Ï¥Õ¥¡¥¤¥ëÃæ¤ÈƱ¤¸·¿¤Î NArray ÊÑ¿ô¤ËÃÍ ¤òÆÉ¤ß¹þ¤à¤¬¡¢"char" ·¿ÊÑ¿ô¤Ë¤Ä¤¤¤Æ¤Ï "byte" ·¿ NArray ¤ËÆÉ¤ß¹þ¤Þ¤ì¤ë¡£ ¤³¤ì¤Ï NArray ¤¬ "char" ·¿¤ò»ý¤¿¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£¤¿¤À¡¢¤½¤â¤½¤â NArray ¤Ï byte ·¿¤Çʸ»úÎó¤ò´Êñ¤Ë°·¤¨¤ë¤Î¤Ç¡¢ÆÃ¤ËÉÔÅÔ¹ç¤Ï¤Ê¤¤¤È¹Í¤¨¤é¤ì¤ë¡£ ===¥¨¥é¡¼½èÍý ¥¨¥é¡¼¤Ï´ðËÜŪ¤Ë¤ÏÎã³°¤òȯÀ¸¤¹¤ë¤³¤È¤Ë¤è¤êÂн褹¤ë¡£Ã¢¤·¡¢ÃͤòÊÖ¤¹¥á¥½¥Ã ¥É¤Ç¤Ï·ÚÈù¤Ê¥¨¥é¡¼¤Ï nil ¤òÊÖ¤¹¤³¤È¤ÇÂн褹¤ë¡Ê°À­ÃͤòÆÀ¤ë¤¿¤á¤Ë»ØÄê ¤µ¤ì¤¿Ì¾Á°¤Î°À­¤¬Â¸ºß¤·¤Ê¤¤¤È¤­¤Ê¤É¡Ë¡£Î㳰Ū¤Ê¾õ¶·¤Ç nil ¤òȯÀ¸¤¹¤ë ¥á¥½¥Ã¥É¤Ë¤Ä¤¤¤Æ¤Ï¥Þ¥Ë¥å¥¢¥ë¤ËÌÀµ­¤·¤Æ¤¢¤ë¡£ ===¥»¥­¥å¥ê¥Æ¥£ ÁȤ߹þ¤ß¤Î File ¥¯¥é¥¹¤ÈƱ¤¸¥»¥­¥å¥ê¥Æ¥£¡¼Âбþ¤ò¤·¤Æ¤¤¤Æ¤ë¡£ ===»ÈÍÑË¡ RubyNetCDF¥é¥¤¥Ö¥é¥ê¡¼¤òÍøÍѤ¹¤ë¤¿¤á¤Ë¤Ï¡¢¤Þ¤º¼¡¤Î¹Ô¤ò Ruby ¥×¥í¥°¥é¥à¤Ë½ñ¤¤ ¤Æ¥é¥¤¥Ö¥é¥ê¡¼¤ò¥í¡¼¥É¤¹¤ëɬÍפ¬¤¢¤ë¡£ require 'numru/netcdf' ¤â¤·¤â (NetCDFVar¥¯¥é¥¹¤Î) ¼«Æ°Åª¤Ê¥Ç¡¼¥¿·ç»½èÍý¥á¥½¥Ã¥É¤ò»È¤¤¤¿¤¤¾ì ¹ç¤Ï¡¢°Ê²¼¤ò¼Â¹Ô¤¹¤ëɬÍפ¬¤¢¤ë¡£ require 'numru/netcdf_miss' ¤³¤ì¤ÏÆâÉô¤Ç°ìÈֺǽé¤Ë (({require 'numru/netcdf'})) ¤ò¼Â¹Ô¤¹¤ë¤Î¤Ç¡¢ ¤³¤ì¤À¤±¸Æ¤Ù¤ÐÎɤ¤¡£¥Ç¡¼¥¿·ç»¤Î°·¤¤¤Ï (()) ¤Ë¤è¤ë¤Î¤Ç¡¢¤³¤ì¤ò¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤ª¤«¤Í¤Ð¤Ê¤é¤Ê¤¤¡£ ¤â¤·¤â (({require 'numru/netcdf'})) ¤À¤±¤ò¸Æ¤Ö¤Î¤Ê¤é¡¢NArrayMiss ¤ÏÉÔÍפǤ¢¤ë¡£ ¤³¤³¤Ç¡¢'numru' ("Numerical Ruby"¤«¤é¼è¤é¤ì¤¿) ¤Ï¥æ¡¼¥¶¡¼¤Î¥é¥¤¥Ö¥é¥ê¡¼ ¥í¡¼¥É¥Ñ¥¹Ãæ¤Î¥µ¥Ö¥Ç¥£¥ì¥¯¥È¥ê¡¼¤Ç¡¢RubyNetCDF ¥é¥¤¥Ö¥é¥ê¡¼¤¬ÃÖ¤«¤ì¤ë¡£ ¤¹¤ë¤È¡¢°Ê²¼¤Î¤è¤¦¤ËÍøÍѤǤ­¤ë¤è¤¦¤Ë¤Ê¤ë¡£ file = NumRu::NetCDF.create('tmp.nc') x = file.def_dim('x',10) y = file.def_dim('y',10) v = file.def_var('v','float',[x,y]) file.close ¤³¤³¤Ç¡¢NumRu ¤Ï¤³¤Î¥é¥¤¥Ö¥é¥ê¡¼¤ò´Þ¤à¥â¥¸¥å¡¼¥ë¤Ç¤¢¤ë¡£¤³¤Î¤è¤¦¤Ê¥â¥¸¥å¡¼ ¥ë¤Ë¤¯¤ë¤ó¤Ç¤¢¤ë¤Î¤Ï¡¢Ì¾Á°¶õ´Ö¤Ç¤Î¾×ÆÍ¤òÈò¤±¤ë¤¿¤á¤Ç¤¢¤ë¡£¤³¤Î¤è¤¦¤Ê°· ¤¤¤ò¤·¤Ê¤¤¾ì¹ç¡¢¤â¤·¤â¥æ¡¼¥¶¡¼¤¬¡¢Ëܥ饤¥Ö¥é¥ê¡¼Ãæ¤Î¥¯¥é¥¹¤È̾Á°¤¬¾×ÆÍ ¤¹¤ë¥¯¥é¥¹¤ä¥â¥¸¥å¡¼¥ë¤ò´Þ¤à¥é¥¤¥Ö¥é¥ê¡¼¤ò»È¤ª¤¦¤È¤¹¤ë¤È¡¢ÌäÂ꤬µ¯¤ë¡£ ¤³¤Î¤è¤¦¤ÊÌäÂ꤬µ¯¤³¤é¤Ê¤¤¤Ç¤¢¤í¤¦¾ì¹ç¤Ï¡¢"NumRu::" ¤È¤¤¤¦´§¤Ï¡¢NumRu ¥â¥¸¥å¡¼¥ë¤ò¡Ö¥¤¥ó¥¯¥ë¡¼¥É¡×¤¹¤ë¤³¤È¤Ç³°¤»¤ë¡Ê¸½ºß¤Î¥¹¥³¡¼¥×¤Ë¤ª¤¤¤Æ¤È ¤¤¤¦¤³¤Ç¤¢¤ë¡Ë¡£½¾¤Ã¤Æ¼¡¤Î¤è¤¦¤Ë½ñ¤±¤ë¡£ include NumRu file = NetCDF.create('tmp.nc') ... ¤µ¤é¤Ê¤ë»ÈÍÑÎã¤È¤·¤Æ¤Ï¥À¥¦¥ó¥í¡¼¥ÉÍѥѥ屡¼¥¸¤Ë´Þ¤Þ¤ì¤ë demo ¤ä test ¥×¥í¥°¥é¥à¤ò»²¾È¤»¤è¡£ --------------------------------------------- ==¥Þ¥Ë¥å¥¢¥ë¤Î¸«Êý --- ¥á¥½¥Ã¥É̾(°ú¿ô1, °ú¿ô2, ...) -- ¾Êά²Äǽ¤Ê°ú¿ô¤Ï °ú¿ô̾=¥Ç¥Õ¥©¥ë¥ÈÃÍ ¤Î·Á¤Ç¼¨¤¹ µ¡Ç½¤Î²òÀâ °ú¿ô * °ú¿ô1¤Î̾ (¤½¤Î¥¯¥é¥¹¤Þ¤¿¤Ï¼è¤êÆÀ¤ëÃÍ): ÀâÌÀ * °ú¿ô2¤Î̾ (¤½¤Î¥¯¥é¥¹¤Þ¤¿¤Ï¼è¤êÆÀ¤ëÃÍ): ÀâÌÀ * ... Ìá¤êÃÍ * Ìá¤êÃͤÎÀâÌÀ Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * NetCDF ver 3 ¤Î´Ø¿ô̾¡£³ç¸Ì¤¬¤Ê¤¤¾ì¹ç¡¢¤½¤Î´Ø¿ô¤ÈƱÅù¤Îµ¡Ç½¤òÍ­ ¤¹¤ë¤³¤È¤ò¼¨¤¹¡£Ä¾ÀÜŪ¤ÊÂбþ¤¬¤Ê¤¤¾ì¹ç¡¢³ç¸ÌÆâ¤Ë°Í¸¤¹¤ë´Ø¿ô¤òµó¤²¤ë¡£ --------------------------------------------- ==¥á¥½¥Ã¥É¥¤¥ó¥Ç¥Ã¥¯¥¹ * ((<¥¯¥é¥¹ NetCDF>)) ¥¯¥é¥¹¥á¥½¥Ã¥É * (()) ¥ê¥ó¥¯¤µ¤ì¤¿ NetCDF ¤¬ version 4 ¤«¤É¤¦¤«ÊÖ¤¹ * (()) NetCDF.create¤Çºî¤é¤ì¤ë¥Õ¥¡¥¤¥ë¥Õ¥©¡¼¥Þ¥Ã¥È¤òÀßÄꤹ¤ë (NetCDF-4 ÀìÍÑ). * (()) NetCDF.create¤Çºî¤é¤ì¤ë¥Õ¥¡¥¤¥ë¥Õ¥©¡¼¥Þ¥Ã¥È¤ÎÀßÄê¤òÊÖ¤¹. (NetCDF-4 ÀìÍÑ). * (()) ¥Õ¥¡¥¤¥ë¥ª¡¼¥×¥ó¡Ê¥¯¥é¥¹¥á¥½¥Ã¥É¡Ëmode="w" ¤Ç¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤±¤ì¤Ð¿·µ¬ºîÀ® * (()) NetCDF.open¥á¥½¥Ã¥É¤Î¥¨¥¤¥ê¥¢¥¹¤Ç¤¢¤ë * (()) NetCDF¥Õ¥¡¥¤¥ë¤òºî¤ë¡Ê¥¯¥é¥¹¥á¥½¥Ã¥É) * (()) ¥Æ¥ó¥Ý¥é¥ê¡¼NetCDF¥Õ¥¡¥¤¥ë¤òºî¤ë¡Ê¥¯¥é¥¹¥á¥½¥Ã¥É) ¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É * (()) ¥Õ¥¡¥¤¥ë¥¯¥í¡¼¥º * (()) ¥Õ¥¡¥¤¥ëÃæ¤Î¼¡¸µ¤Î¿ô¤òÊÖ¤¹ * (()) ¥Õ¥¡¥¤¥ëÃæ¤ÎÊÑ¿ô¤Î¿ô¤òÊÖ¤¹ * (()) ¥Õ¥¡¥¤¥ëÃæ¤Î¥°¥í¡¼¥Ð¥ë°À­¤Î¿ô¤òÊÖ¤¹ * (()) ¥Õ¥¡¥¤¥ëÃæ¤Îunlimited dimension¤òÊÖ¤¹ * (()) ¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹. open/create»þ¤Îfilename°ú¿ô¤ÎÃæ¿È¤òÊÖ¤¹. * (()) define mode¤Ë¤¹¤ë¡£´û¤Ë¤½¤¦¤Ê¤é²¿¤â¤»¤ºnil¤òÊÖ¤¹¡£ * (()) data mode ¤ËÆþ¤ë¡£´û¤Ë¤½¤¦¤Ê¤é²¿¤â¤»¤ºnil¤òÊÖ¤¹¡£ * (()) º£ÄêµÁ¥â¡¼¥É¤«¤É¤¦¤«Ìä¹ç¤ï¤»¤ë. * (()) ¥á¥â¥ê¡¼Ãæ¤Î¥Ð¥Ã¥Õ¥¡¡¼¤ò¥Ç¥£¥¹¥¯¾å¤ËÈ¿±Ç¤·¤Æ¥Õ¥¡¥¤¥ë¤òƱ´ü¤µ¤»¤ë * (()) dimension¤òÄêµÁ * (()) ¥°¥í¡¼¥Ð¥ë°À­¤òÀßÄê * (()) ÊÑ¿ô¤òÄêµÁ * (()) def_var¤ÈƱ¤¸¤À¤¬É¬Íפʤé¤Þ¤º¼¡¸µ¤òÄêµÁ¤¹¤ë¡£ * (()) ¥Õ¥¡¥¤¥ë¤Ë´û¸¤ÎÊÑ¿ô¤ò¥ª¡¼¥×¥ó * (()) ¥Õ¥¡¥¤¥ë¤Ë´û¸¤ÎÊÑ¿ô¤ò¤Þ¤È¤á¤Æ¥ª¡¼¥×¥ó * (()) ´û¸¤Î¼¡¸µ¤ò¥ª¡¼¥×¥ó * (()) ´û¸¤Î¼¡¸µ¤ò¤Þ¤È¤á¤Æ¥ª¡¼¥×¥ó * (()) ´û¸¤Î¥°¥í¡¼¥Ð¥ë°À­¤ò¥ª¡¼¥×¥ó * (()) fillmode¤ÎÊѹ¹¡£(NetCDF ¤Î¥Ç¥Õ¥©¥ë¥È¤Ï FILL ¤Ç¤¢¤ë¡£) * (()) ¼¡¸µ¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿. * (()) ÊÑ¿ô¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿. * (()) ¥°¥í¡¼¥Ð¥ë°À­¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿. * (()) ¥Õ¥¡¥¤¥ëÃæ¤ÎÁ´¼¡¸µ¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ * (()) ¥Õ¥¡¥¤¥ëÃæ¤ÎÁ´ÊÑ¿ô¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ * (()) ¥Õ¥¡¥¤¥ëÃæ¤ÎÁ´¥°¥í¡¼¥Ð¥ë°À­¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ * ((<¥¯¥é¥¹ NetCDFDim>)) ¥¯¥é¥¹¥á¥½¥Ã¥É ¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É * (()) ¼¡¸µ¤ÎŤµ¤òÊÖ¤¹ * (()) length ¤ÈƱ¤¸¤À¤¬¡¢ÌµÀ©¸Â¼¡¸µ¤Ë´Ø¤·¥¼¥í¤òÊÖ¤¹ * (()) ̾Á°¤ò¤Ä¤±¤«¤¨¤ë * (()) ̾Á°¤òÊÖ¤¹ * (()) ̵À©¸Â¼¡¸µ¤«¤É¤¦¤«¡© * ((<¥¯¥é¥¹ NetCDFVar>)) ¥¯¥é¥¹¥á¥½¥Ã¥É * (()) NetCDF.open ¤È NetCDF#Var ¤òÁȤ߹ç¤ï¤»¤Æ°ì¹Ô¤ÇºÑ¤Þ¤¹(»È¤ï¤Ê¤¯¤ÆÎɤ¤). * (()) (())¤Ç»È¤¦NArray¤Î·¿¤ò¸ÇÄꤹ¤ë * (()) (())¤ÇÀßÄꤷ¤¿NArray¤Î·¿¤òÊÖ¤¹ ¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É * (()) °µ½Ì (deflation) ¤òÀßÄê. (netCDF-4 only) * (()) ¸½ºß¤Î°µ½ÌÀßÄêÌä¹ç¤». (netCDF-4 only) * (()) ¥¨¥ó¥Ç¥£¥¢¥ó¤òÀßÄê (netCDF-4 only) * (()) ¥¨¥ó¥Ç¥£¥¢¥óÀßÄê¤òÊÖ¤¹. (netCDF-4 only) * (()) ¤½¤ÎÊÑ¿ô¤Ë¤ª¤±¤ë dim_num ÈÖÌÜ(0¤«¤é¿ô¤¨¤ë)¤Î¼¡¸µ¤òÌä¹ç¤ï¤»¤ë¡£ * (()) ¤½¤ÎÊÑ¿ô¤ÎÁ´¼¡¸µ¤òÇÛÎó¤Ë¤¤¤ì¤ÆÊÖ¤¹ * (()) ÊÑ¿ô¤Î·Á¤òÊÖ¤¹. ⤷̵À©¸Â¼¡¸µ¤ÎŤµ¤Ï¥¼¥í. * (()) ÊÑ¿ô¤Î¸½ºß¤Î·Á¤òÊÖ¤¹. * (()) ÊÑ¿ôÃæ¤ÎÁ´Â°À­(NetCDFAtt)¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿ * (()) ÊÑ¿ôÃæ¤ÎÁ´¼¡¸µ¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ * (()) ÊÑ¿ôÃæ¤ÎÁ´Â°À­¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ * (()) ÊÑ¿ô¤Î̾Á°¤òÊÖ¤¹ * (()) ̾Á°¤òÉÕ¤±Âؤ¨¤ë * (()) ¼¡¸µ¤Î¿ô¤òÌ䤦 * (()) ndims¤Î¥¨¥ê¥¢¥¹ * (()) vartype ¤ÎÊÌ̾ * (()) ÊÑ¿ôÃͤη¿¤òÌ䤦 * (()) ÊÑ¿ôÃͤη¿¤òÌ䤦(NArray¤Îtypecode¤ÇÊÖ¤¹) * (()) °À­¤Î¿ô¤òÌ䤦 * (()) ¤½¤ÎÊÑ¿ô¤¬Â°¤¹¤ë¥Õ¥¡¥¤¥ë¤òÌä¹ç¤ï¤»¤ë * (()) ̾Á°¤ò»ØÄꤷ¤¿Â°À­¤òÊÖ¤¹ * (()) °À­¤òÀßÄê * (()) ¡¡(())¤ÎÊÌ̾(alias) * (()) ÃͤòÆþ¤ì¤ë * (()) self¤Î°À­ scale_factor and/or add_offset ¤òÍѤ¤¤Æ NArray Åù¤ò "pack" ¤¹¤ë. * (()) (()) ¤ÈƱÍͤÀ¤¬¡¢(())¤Ë¤è¤ê°À­ scale_factor ¤È add_offset ¤ò²ò¼á¤¹¤ë * (()) ¡¡(())¤ÎÊÌ̾(alias) * (()) Ãͤò¼è¤ê½Ð¤¹ * (()) self¤Î°À­ scale_factor and/or add_offset ¤òÍѤ¤¤Æ NArray Åù¤ò "unpack" ¤¹¤ë. * (()) (()) ¤ÈƱÍͤÀ¤¬¡¢(())¤Ë¤è¤ê°À­ scale_factor ¤È add_offset ¤ò²ò¼á¤¹¤ë * ((<[]>)) NetCDFVar#get ¤ÈƱÍͤÀ¤¬¡¢¥µ¥Ö¥»¥Ã¥È¤ò NArray#[] ¤ÈƱÍͤ˻ØÄꤹ¤ë. * ((<[]=>)) NetCDFVar#put ¤ÈƱÍͤÀ¤¬¡¢¥µ¥Ö¥»¥Ã¥È¤ò NArray#[]= ¤ÈƱÍͤ˻ØÄꤹ¤ë. "numru/netcdf_miss" ¤ò require ¤¹¤ë¤³¤È¤ÇÄɲ䵤ì¤ë¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É * (()) ¡¡(())¤ÈƱÍͤÀ¤¬¡¢¥Ç¡¼¥¿·ç»¤ò½èÍý¤¹¤ë * (()) ¡¡(())¤ÈƱÍͤÀ¤¬¡¢(())¤Ë¤è¤ê¥¹¥±¡¼¥ê¥ó¥°¤â¹Ô¤¦. * (()) ¡¡(())¤ÈƱÍͤÀ¤¬¡¢¥Ç¡¼¥¿·ç»¤ò½èÍý¤¹¤ë * (()) ¡¡(())¤ÈƱÍͤÀ¤¬¡¢(())¤Ë¤è¤ê¥¹¥±¡¼¥ê¥ó¥°¤â¹Ô¤¦. * ((<¥¯¥é¥¹ NetCDFAtt>)) ¥¯¥é¥¹¥á¥½¥Ã¥É ¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É * (()) °À­¤Î̾Á°¤òÊÖ¤¹ * (()) °À­¤Î̾Á°¤òÊѹ¹ * (()) °À­¤òÊ̤ÎÊÑ¿ô¤Þ¤¿¤Ï¥Õ¥¡¥¤¥ë¤Ë¥³¥Ô¡¼¡£¥Õ¥¡¥¤¥ë¤Î¾ì¹ç¤Ï¥°¥í¡¼¥Ð¥ë°À­¤Ë¤Ê¤ë * (()) °À­¤òºï½ü * (()) °À­¤ÎÃͤòÀßÄê * (()) °À­¤ÎÃæ¿È¤ò¼è¤ê½Ð¤¹ * (()) °À­Ãͤη¿¤òÌ䤦 * (()) °À­Ãͤη¿¤òÌ䤦(NArray¤Îtypecode¤ÇÊÖ¤¹) --------------------------------------------- =¥¯¥é¥¹ NetCDF ===Äê¿ô * NC_NOWRITE, NC_WRITE, NC_SHARE, NC_CLOBBER, NC_NOCLOBBER, NC_64BIT_OFFSET, NC_NETCDF4, NC_CLASSIC_MODEL, NCVERSION, SUPPORT_BIGMEM : ¤³¤ì¤é¤Ï NumRu::NetCDF::NC_NOWRITE ¤Ê¤É¥¢¥¯¥»¥¹¤¹¤ë¡£ ===¥¯¥é¥¹¥á¥½¥Ã¥É ---NetCDF.nc4? ¤³¤Î¥é¥¤¥Ö¥é¥ê¤¬ NetCDF version 4 ¤ò»È¤¦¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ì¤Ð ¡Ê¥ê¥ó¥¯¤µ¤ì¤Æ¤ë NetCDF ¥é¥¤¥Ö¥é¥ê¤¬ver 4¤Ê¤é¡Ëtrue ¤ò¡¤ ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð (NetCDF 3¤Ê¤é) false ¤òÊÖ¤¹¡£ ---NetCDF.creation_format=(cmode) (¤³¤Î¥á¥½¥Ã¥É¤Ï NetCDF-4 ¤¬»È¤ï¤ì¤Æ¤ë¤È¤­¤Î¤ß»ÈÍѲÄǽ¡§¤½¤¦¤Ç¤Ê¤±¤ì¤Ð Îã³°¤¬È¯À¸¤¹¤ë). NetCDF.create ¤Çºî¤é¤ì¤ë¥Õ¥¡¥¤¥ë¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤ò»ØÄꤹ¤ë. ½é´üÀßÄê¤Ï "classic". °ú¿ô * cmode : °Ê²¼¤Î¤¤¤º¤ì¤«¡£ * 0, nil, or NetCDF::NC_CLASSIC_MODEL : classic format (°ÊÁ°¤«¤é¤Î NetCDF-3 ¤Î¥Õ¥©¡¼¥Þ¥Ã¥È). ¤³¤ì¤¬½é´üÀßÄê. * NetCDF::NC_64BIT_OFFSET : classic ¤À¤¬¡¤ÊÑ¿ô¤Î¥µ¥¤¥º¤òÂ礭¤¯½ÐÍè¤ë * NetCDF::NC_NETCDF4 : HDF5 ¥Ù¡¼¥¹¤Î NetCDF-4 ¿·¥Õ¥©¡¼¥Þ¥Ã¥È * ( NetCDF::NC_NETCDF4 | NetCDF::NC_CLASSIC_MODEL) [¤³¤ì¤Ï NetCDF::NC_NETCDF4 ¤È NetCDF::NC_CLASSIC_MODEL ¤Î bit "or"]: NetCDF-4 ¿·¥Õ¥©¡¼¥Þ¥Ã¥È¤À¤¬¡¤¿·¤·¤¤¥Ç¡¼¥¿¥â¥Ç¥ë¤Ï»È¤¨¤Ê¤¤¤è¤¦À©¸Â. ---NetCDF.creation_format (¤³¤Î¥á¥½¥Ã¥É¤Ï NetCDF-4 ¤¬»È¤ï¤ì¤Æ¤ë¤È¤­¤Î¤ß»ÈÍѲÄǽ¡§¤½¤¦¤Ç¤Ê¤±¤ì¤Ð Îã³°¤¬È¯À¸¤¹¤ë). NetCDF.create ¤Çºî¤é¤ì¤ë¥Õ¥¡¥¤¥ë¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤Î¸½ºß¤ÎÀßÄê¤òÊÖ¤¹. ---NetCDF.open(filename, mode="r", share=false) ¥Õ¥¡¥¤¥ë¥ª¡¼¥×¥ó¡Ê¥¯¥é¥¹¥á¥½¥Ã¥É¡Ëmode="w" ¤Ç¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤±¤ì¤Ð¿·µ¬ºîÀ® °ú¿ô * filename (String): ¥Õ¥¡¥¤¥ë̾ * mode (String) : Æþ½ÐÎϥ⡼¥É: "r"(ÆÉ¤ß¼è¤ê¤Î¤ß); "w","w+" (½ñ¤­ ¹þ¤ß -- ¸½ºß¤ÎÃæ¿È¤Ï¾å½ñ¤­(¾Ã¤¨¤ë!)); "r+","a","a+" (Äɲà -- ¸½ºß¤ÎÆâÍÆ¤Ï¤½¤Î¤Þ¤Þ¤Ë¡¢½ñ¤­¹þ¤ß²Ä)¡£ ÁȤ߹þ¤ß¤Î File ¥¯¥é¥¹¤È °ã¤¤¡¢¤É¤Î¥â¡¼¥É¤Ç¤âÆÉ¤ß¹þ¤ß¤Ï²Äǽ¡£Ãí°Õ¡§¸µ¤Ë¤Ê¤ë NetCDF¥é¥¤ ¥Ö¥é¥ê¡¼¤ÎÀ©¸Â¤Ë¤è¤ê¡¢¡ÖÄɲáפˤÏ;ʬ¤Ê»þ´Ö¤È¥Ç¥£¥¹¥¯¥¹¥Ú¡¼¥¹ ¤¬¤«¤«¤ë¡£ * share (true or false) : shared¥â¡¼¥É¤Ë¤¹¤ë¤« (½ñ¤­¹þ¤ßÃæ¤Î¥Õ¥¡ ¥¤¥ë¤Ë¾¤Î¥×¥í¥»¥¹¤«¤é¤ÎÆÉ¤ß¹þ¤ß¤¬¤¢¤êÆÀ¤ë¾ì¹ç¤Ë true ¤È¤¹¤ë¡£CÈǥ桼 ¥¶¡¼¥º¥¬¥¤¥ÉÂè5¾Ï¤Î nc_open ¤Î¹à¤ò»²¾È¤Î¤³¤È) Ìá¤êÃÍ * NetCDF¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_open, nc_create ---NetCDF.new NetCDF.open¥á¥½¥Ã¥É¤Î¥¨¥¤¥ê¥¢¥¹¤Ç¤¢¤ë ---NetCDF.create(filename, noclobber=false, share=false) NetCDF¥Õ¥¡¥¤¥ë¤òºî¤ë¡Ê¥¯¥é¥¹¥á¥½¥Ã¥É) °ú¿ô * filename (String) : ¥Õ¥¡¥¤¥ë̾ * noclobber (true or false) : ¾å½ñ¤­¤¹¤ë¤«¤·¤Ê¤¤¤« * share (true or false) : shared mode ¤ò»È¤¦¤« (½ñ¤­¹þ¤ßÃæ¤Î¥Õ¥¡ ¥¤¥ë¤Ë¾¤Î¥×¥í¥»¥¹¤«¤é¤ÎÆÉ¤ß¹þ¤ß¤¬¤¢¤êÆÀ¤ë¾ì¹ç¤Ë true ¤È¤¹¤ë¡£CÈǥ桼 ¥¶¡¼¥º¥¬¥¤¥ÉÂè5¾Ï¤Î nc_open ¤Î¹à¤ò»²¾È¤Î¤³¤È) Ìá¤êÃÍ * NetCDF¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_create ---NetCDF.create_tmp(tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'.', share=false) ¥Æ¥ó¥Ý¥é¥ê¡¼NetCDF¥Õ¥¡¥¤¥ë¤òºî¤ë¡Ê¥¯¥é¥¹¥á¥½¥Ã¥É) ̾Á°¤Ï¼«Æ°¤Ç·è¤Þ¤ë¡£¥¯¥í¡¼¥º¤µ¤ì¤ë¤È¾Ã¤µ¤ì¤ë¡£ °ú¿ô * tmpdir (String) : ¥Æ¥ó¥Ý¥é¥ê¡¼¥Õ¥¡¥¤¥ë¤òÃÖ¤¯¥Ç¥£¥ì¥¯¥È¥ê¡¼Ì¾¡£ ¥Ç¥Õ¥©¥ë¥È¤Ï´Ä¶­ÊÑ¿ô¤Ç»ØÄꤵ¤ì¤¿¥Ç¥£¥ì¥¯¥È¥ê¡¼¡ÊTMPDIR,TMP,or TEMP¡Ë¤Þ¤¿¤Ï '.'¡£¥»¥­¥å¥¢¡¼¥â¡¼¥É¤Ç¤Ï '.' ¤Î¤ß¤¬¥Ç¥Õ¥©¥ë¥È¤È¤Ê ¤ë¡£ * share (true or false) : shared mode ¤ò»È¤¦¤« Ìá¤êÃÍ * NetCDF¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_create ===¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É ---close ¥Õ¥¡¥¤¥ë¥¯¥í¡¼¥º °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_close ---ndims ¥Õ¥¡¥¤¥ëÃæ¤Î¼¡¸µ¤Î¿ô¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Integer Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_ndims ---nvars ¥Õ¥¡¥¤¥ëÃæ¤ÎÊÑ¿ô¤Î¿ô¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Integer Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_nvars ---natts ¥Õ¥¡¥¤¥ëÃæ¤Î¥°¥í¡¼¥Ð¥ë°À­¤Î¿ô¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Integer Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_natts ---unlimited ¥Õ¥¡¥¤¥ëÃæ¤Îunlimited dimension¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * ¸ºß¤¹¤ë¤È¤­NetCDFDim¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¡£¤Ê¤¤¤È¤­¤Ïnil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_unlimdim ---path ¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹. open/create»þ¤Îfilename°ú¿ô¤ÎÃæ¿È¤òÊÖ¤¹. °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * ¤Ê¤· ---redef define mode¤Ë¤¹¤ë¡£´û¤Ë¤½¤¦¤Ê¤é²¿¤â¤»¤ºnil¤òÊÖ¤¹¡£ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * true (ÄêµÁ¥â¡¼¥É¤Ø¤ÎÊѹ¹¤¬À®¸ù); nil (´û¤ËÄêµÁ¥â¡¼¥ÉÃæ). ¤½¤Î¾¤ÎÍýͳ¤ÇÊѹ¹¤Ç¤­¤Ê¤¤¾ì¹ç¤ÏÎ㳰ȯÀ¸. Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_redef ---enddef data mode ¤ËÆþ¤ë¡£´û¤Ë¤½¤¦¤Ê¤é²¿¤â¤»¤ºnil¤òÊÖ¤¹¡£ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * true (¥Ç¡¼¥¿¥â¡¼¥É¤Ø¤ÎÊѹ¹¤¬À®¸ù); nil (´û¤Ë¥Ç¡¼¥¿¥â¡¼¥ÉÃæ). ¤½¤Î¾¤ÎÍýͳ¤ÇÊѹ¹¤Ç¤­¤Ê¤¤¾ì¹ç¤ÏÎ㳰ȯÀ¸. Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_endef ---define_mode? º£ÄêµÁ¥â¡¼¥É¤«¤É¤¦¤«Ìä¹ç¤ï¤»¤ë. °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * true (º£ÄêµÁ¥â¡¼¥É); false (º£¥Ç¡¼¥¿¥â¡¼¥É); nil (¤½¤Î¾ -- ÆÉ¤ß½Ð¤·ÀìÍѤʤÉ). Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_redef ¤È nc_enddef ¤ÎÁȤ߹ç¤ï¤» ---sync ¥á¥â¥ê¡¼Ãæ¤Î¥Ð¥Ã¥Õ¥¡¡¼¤ò¥Ç¥£¥¹¥¯¾å¤ËÈ¿±Ç¤·¤Æ¥Õ¥¡¥¤¥ë¤òƱ´ü¤µ¤»¤ë °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_sync ---def_dim(dimension_name, length) dimension¤òÄêµÁ °ú¿ô * dimension_name (String) : ÄêµÁ¤¹¤ëdimension¤Î̾Á° * length (Integer) : dimension¤ÎŤµ¡£ÌµÀ©¸Â¼¡¸µ¤Ï 0¡£ Ìá¤êÃÍ * ÄêµÁ¤µ¤ì¤¿¼¡¸µ (NetCDFDim¥ª¥Ö¥¸¥§¥¯¥È) Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_def_dim ---put_att(attribute_name, value, atttype=nil) ¥°¥í¡¼¥Ð¥ë°À­¤òÀßÄê °ú¿ô * attribute_name (String) : ¥°¥í¡¼¥Ð¥ë°À­¤Î̾Á° * value (Numeric, String, Array of Numeric, or NArray) : ÀßÄꤹ¤ëÃÍ * atttype (nil or String) : °À­¤Î·¿. "char"(="string"),"byte", "sint","int","sfloat", "float" (¤½¤ì ¤¾¤ì,1,1,2,4,4,8 ¥Ð¥¤¥È)) ¤Þ¤¿¤Ï nil (¤Ä¤Þ¤ê¤ªÇ¤¤») Ìá¤êÃÍ * ÀßÄꤵ¤ì¤¿Â°À­ (NetCDFAtt¥ª¥Ö¥¸¥§¥¯¥È) Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_put_att_ ---def_var(variable_name, vartype, dimensions) ÊÑ¿ô¤òÄêµÁ °ú¿ô * variable_name (String) : ÄêµÁ¤¹¤ëvariable¤Î̾Á° * vartype (String or Fixnum) : ÊÑ¿ô¤Î¥¿¥¤¥× ("char", "byte", "sint", "sint", "int", "sfloat", "float" ¤Î¤¤¤º¤ì¤«¡¢¤Þ¤¿¤ÏNArray¤Îtypecode(Fixnum)) * dimensions (Array) : variable¤Î¼¡¸µ¡£NetCDFDim ¤Î Array¡£ºÇ¤â ¡Ö®¤¯²ó¤ë¡×¼¡¸µ¤«¤é¡ÖÃÙ¤¯²ó¤ë¡×¼¡¸µ¤Î½ç¤Ë¡£¤½¤ÎŤµ¤¬ÊÑ¿ô¤Î rank ¤È¤Ê¤ë¡£ Ìá¤êÃÍ * ÄêµÁ¤·¤¿ÊÑ¿ô(NetCDFVar¥ª¥Ö¥¸¥§¥¯¥È) Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_def_var ---def_var_with_dim(variable_name, vartype, shape_ul0, dimnames) def_var¤ÈƱ¤¸¤À¤¬É¬Íפʤé¤Þ¤º¼¡¸µ¤òÄêµÁ¤¹¤ë¡£ ´û¸¼¡¸µ¤ÎŤµ¤È¹ç¤ï¤Ê¤¤¾ì¹çÎã³°¡£ °ú¿ô * variable_name (String) : ÄêµÁ¤¹¤ëvariable¤Î̾Á° * vartype (String) : ÊÑ¿ô¤Î¥¿¥¤¥× ("char", "byte", "sint", "sint", "int", "sfloat", "float" ¤Î¤¤¤º¤ì¤«) * shape_ul0 (Array of Integer) : ÊÑ¿ô¤Î·Á¡¢Â¨¤Á¡¢³Æ¼¡¸µ¤ÎŤµ¡£Ìµ À©¸Â¼¡¸µ¤Ï¥¼¥í¤Çɽ¤¹¡£Ä¹¤µ¤¬ÊÑ¿ô¤Î rank ¤È¤Ê¤ë¡£ * dimnames (Array of String) : ³Æ¼¡¸µ¤Î̾Á°. Ťµ(=>rank) ¤Ï shape_ul0 ¤ÈÅù¤·¤¯¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£ Ìá¤êÃÍ * ÄêµÁ¤·¤¿ÊÑ¿ô(NetCDFVar¥ª¥Ö¥¸¥§¥¯¥È) Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_def_var) ---var(var_name) ¥Õ¥¡¥¤¥ë¤Ë´û¸¤ÎÊÑ¿ô¤ò¥ª¡¼¥×¥ó °ú¿ô * var_name (String) : ¥ª¡¼¥×¥ó¤¹¤ëÊÑ¿ô̾ Ìá¤êÃÍ * NetCDFVar ¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¡£Â¸ºß¤·¤Ê¤±¤ì¤Ð nil¡£ Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_varid ---vars(names = nil) ¥Õ¥¡¥¤¥ëÃæ¤ÎÊÑ¿ô¤ò¤Þ¤È¤á¤Æ¥ª¡¼¥×¥ó °ú¿ô * names (nil or Array of String) : ¥ª¡¼¥×¥ó¤¹¤ëÊÑ¿ô̾. nil¤Ê¤éÁ´Éô¡Ê¥Ç¥Õ¥©¥ë¥È¡Ë Ìá¤êÃÍ * NetCDFVar¥ª¥Ö¥¸¥§¥¯¥È¤ÎArray¡£names¤Ë¸ºß¤·¤Ê¤¤ÊÑ¿ô̾¤¬´Þ¤Þ¤ì¤ì¤ÐÎ㳰ȯÀ¸¡£ Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_varid ---dim(dimension_name) ´û¸¤Î¼¡¸µ¤ò¥ª¡¼¥×¥ó °ú¿ô * dimension_name (String) : ¥ª¡¼¥×¥ó¤¹¤ë¼¡¸µÌ¾ Ìá¤êÃÍ * NetCDFDim¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¡£Â¸ºß¤·¤Ê¤±¤ì¤Ð nil¡£ Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_dimid ---dims(names = nil) ¥Õ¥¡¥¤¥ëÃæ¤Î¼¡¸µ¤ò¤Þ¤È¤á¤Æ¥ª¡¼¥×¥ó °ú¿ô * names (nil or Array of String) : ¥ª¡¼¥×¥ó¤¹¤ë¼¡¸µÌ¾. nil¤Ê¤éÁ´Éô¡Ê¥Ç¥Õ¥©¥ë¥È¡Ë Ìá¤êÃÍ * NetCDFDim¥ª¥Ö¥¸¥§¥¯¥È¤ÎArray¡£names¤Ë¸ºß¤·¤Ê¤¤¼¡¸µÌ¾¤¬´Þ¤Þ¤ì¤ì¤ÐÎ㳰ȯÀ¸¡£ Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_dimid ---att(attribute_name) ´û¸¤Î¥°¥í¡¼¥Ð¥ë°À­¤ò¥ª¡¼¥×¥ó °ú¿ô * attribute_name (String) : ¥ª¡¼¥×¥ó¤¹¤ë¥°¥í¡¼¥Ð¥ë°À­Ì¾ Ìá¤êÃÍ * ¸ºß¤¹¤ì¤Ð NetCDFAtt¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È¡£Â¸ºß¤·¤Ê¤±¤ì¤Ðnil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_attid¤ò¸¡ºº¤ËÍøÍÑ) ---fill=(filemode) fillmode¤ÎÊѹ¹¡£(NetCDF ¤Î¥Ç¥Õ¥©¥ë¥È¤Ï FILL ¤Ç¤¢¤ë¡£) °ú¿ô * fillmode (true for FILL or false for NOFILL) Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_set_fill ---each_dim{ ... } ¼¡¸µ¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿. Îã: {|i| print i.name,"\n"} ¤ÇÁ´¼¡¸µ¤Î̾Á°¤òɽ¼¨. °ú¿ô * { ... } : ¥¤¥Æ¥ì¡¼¥¿¡¼ÍÑ¥Ö¥í¥Ã¥¯¡£do end¥Ö¥í¥Ã¥¯¤Ç¤â¤è¤¤¡£ Ìá¤êÃÍ * self Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_ndims¤òÍøÍÑ) ---each_var{ ... } ÊÑ¿ô¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿. Îã: {|i| print i.name,"\n"} ¤ÇÁ´ÊÑ¿ô¤Î̾Á°¤òɽ¼¨. °ú¿ô * { ... } : ¥¤¥Æ¥ì¡¼¥¿¡¼ÍÑ¥Ö¥í¥Ã¥¯¡£do end¥Ö¥í¥Ã¥¯¤Ç¤â¤è¤¤¡£ Ìá¤êÃÍ * self Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_nvars¤òÍøÍÑ) ---each_att{ ... } ¥°¥í¡¼¥Ð¥ë°À­¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿. Îã: {|i| print i.name,"\n"} ¤ÇÁ´Â°À­¤Î̾Á°¤òɽ¼¨. °ú¿ô * { ... } : ¥¤¥Æ¥ì¡¼¥¿¡¼ÍÑ¥Ö¥í¥Ã¥¯¡£do end¥Ö¥í¥Ã¥¯¤Ç¤â¤è¤¤¡£ Ìá¤êÃÍ * self Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_natts, nc_inq_attname¤òÍøÍÑ) ---dim_names ¥Õ¥¡¥¤¥ëÃæ¤ÎÁ´¼¡¸µ¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String ¤Î Array Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_ndims, nc_inq_dimname¤òÍøÍÑ) ---var_names ¥Õ¥¡¥¤¥ëÃæ¤ÎÁ´ÊÑ¿ô¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String ¤Î Array Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_nvars, nc_inq_varname¤òÍøÍÑ) ---att_names ¥Õ¥¡¥¤¥ëÃæ¤ÎÁ´¥°¥í¡¼¥Ð¥ë°À­¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String ¤Î Array Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_natts, nc_inq_attname¤òÍøÍÑ) --------------------------------------------- =¥¯¥é¥¹ NetCDFDim ===¥¯¥é¥¹¥á¥½¥Ã¥É ===¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É ---length ¼¡¸µ¤ÎŤµ¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Integer Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_dimlen ---length_ul0 length ¤ÈƱ¤¸¤À¤¬¡¢ÌµÀ©¸Â¼¡¸µ¤Ë´Ø¤·¥¼¥í¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Integer Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_dimlen ---name=(dimension_newname) ̾Á°¤ò¤Ä¤±¤«¤¨¤ë °ú¿ô * dimension_newname (String) : ¿·¤·¤¤Ì¾Á° Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_rename_dim ---name ̾Á°¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_dimname ---unlimited? ̵À©¸Â¼¡¸µ¤«¤É¤¦¤«¡© °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * true or false Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_unlimdim ¤òÍøÍÑ) --------------------------------------------- =¥¯¥é¥¹ NetCDFVar ===¥¯¥é¥¹¥á¥½¥Ã¥É ---NetCDFVar.new(file,varname,mode="r",share=false) NetCDFÊÑ¿ô¤ò¥ª¡¼¥×¥ó¤¹¤ë¡£¤³¤ì¤Ï¡¢NetCDF#var (NetCDF¥¯¥é¥¹¤Î¥¤¥ó ¥¹¥¿¥ó¥¹¥á¥½¥Ã¥Évar) ¤ò»È¤Ã¤Æ¤â½ÐÍè¤ë¤·¡¢¤½¤Á¤é¤Î¤Û¤¦¤ò¿ä¾©¤¹¤ë¡£ °ú¿ô * file (NetCDF or String) : NetCDF¥ª¥Ö¥¸¥§¥¯¥È(NetCDF) ¤Þ¤¿¤Ï NetCDF ¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹(String) * varname (String) : fileÃæ¤ÎÊÑ¿ô̾ * mode (String) : Æþ½ÐÎϥ⡼¥É¡£file¤¬ String ¤Î»þ¤Ë»È¤ï¤ì¤ë¡£ ¡ÊNetCDF.open¤Î¹à¤ò¸«¤è¡Ë * share (true or false) : shared¥â¡¼¥É¤Ë¤¹¤ë¤«¡£ file¤¬ String ¤Î»þ¤Ë»È¤ï¤ì¤ë¡£¡ÊNetCDF.open¤Î¹à¤ò¸«¤è¡Ë Ìá¤êÃÍ * NetCDFVar¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_open, nc_create, nc_inq_varid Åù¤òÍøÍѤ¹¤ë) ---NetCDFVar.unpack_type=(na_type) (())¤Ç»È¤¦NArray¤Î·¿¤ò¸ÇÄꤹ¤ë. °ú¿ô * na_type (Integer) : NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, or NArray::FLOAT Ìá¤êÃÍ * na_type (°ú¿ô) ---NetCDFVar.unpack_type (())¤ÇÀßÄꤷ¤¿NArray¤Î·¿¤òÊÖ¤¹. Ìá¤êÃÍ * nil, NArray::BYTE, NArray::SINT, NArray::INT, NArray::SFLOAT, or NArray::FLOAT ===¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É ---deflate(deflate_level, shuffle=false) (¤³¤Î¥á¥½¥Ã¥É¤Ï NetCDF-4 ¤¬»È¤ï¤ì¤Æ¤ë¤È¤­¤Î¤ß»ÈÍѲÄǽ¡§¤½¤¦¤Ç¤Ê¤±¤ì¤Ð Îã³°¤¬È¯À¸¤¹¤ë). (¿·¤·¤¯ºîÀ®¤µ¤ì¤¿)ÊÑ¿ô¤¬°µ½Ì(deflate)¤µ¤ì¤ë¤è¤¦¤Ë¤¹¤ë. ¤³¤Î¥á¥½¥Ã¥É¤Ï¡¤ ÊÑ¿ô¤òºîÀ® (NetCDF#(())) ¤·¤¿¸å¡¤NetCDF#(()) ¤ò¸Æ¤ÖÁ°¤Ë¸Æ¤Ð¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤. °ú¿ô * deflate_level (Integer) :: 0 to 9. (0: no compression; 9: highest compression; recommended: 1 or 2). * shuffle (optional; true or false; default: false) if true, turn on the shuffle filter. * (()): ``The shuffle algorithm changes the byte order in the data stream; when used with integers that are all close together, this results in a better compression ratio. There is no benefit from using the shuffle filter without also using compression.'' * Note: shuffle is effective for float variables too (tested by horinouchi). Ìá¤êÃÍ * self ---deflate_params (¤³¤Î¥á¥½¥Ã¥É¤Ï NetCDF-4 ¤¬»È¤ï¤ì¤Æ¤ë¤È¤­¤Î¤ß»ÈÍѲÄǽ¡§¤½¤¦¤Ç¤Ê¤±¤ì¤Ð Îã³°¤¬È¯À¸¤¹¤ë). ¸½ºß¤Î°µ½Ì(deflation)¥Ñ¥é¥á¥¿¡¼¤òÊÖ¤¹¡£ Ìá¤êÃÍ * [shuffle, deflate, deflate_level] (a 3-element Array). shuffle ¤È deflate ¤Ï true ¤Þ¤¿¤Ï false. deflate_level ¤ÏÀ°¿ô(0-9). ---endian=(endian) (¤³¤Î¥á¥½¥Ã¥É¤Ï NetCDF-4 ¤¬»È¤ï¤ì¤Æ¤ë¤È¤­¤Î¤ß»ÈÍѲÄǽ¡§¤½¤¦¤Ç¤Ê¤±¤ì¤Ð Îã³°¤¬È¯À¸¤¹¤ë). ¥¨¥ó¥Ç¥£¥¢¥ó¤òÀßÄꤹ¤ë¡£»ÈÍÑ¥¿¥¤¥ß¥ó¥°¤Ï (()) ¤ÈƱ¤¸¡£ Arguments * endian : ¼¡¤Î¤¤¤º¤ì¤«: NetCDF::NC_ENDIAN_NATIVE (=0) (default), NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2). Return value * self ---endian (¤³¤Î¥á¥½¥Ã¥É¤Ï NetCDF-4 ¤¬»È¤ï¤ì¤Æ¤ë¤È¤­¤Î¤ß»ÈÍѲÄǽ¡§¤½¤¦¤Ç¤Ê¤±¤ì¤Ð Îã³°¤¬È¯À¸¤¹¤ë). ¸½ºß¤Î¥¨¥ó¥Ç¥£¥¢¥óÀßÄê¤òÊÖ¤¹. Return value * ¼¡¤Î¤¤¤º¤ì¤«: NetCDF::NC_ENDIAN_NATIVE (=0) (default), NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2). ---dim(dim_num) ¤½¤ÎÊÑ¿ô¤Ë¤ª¤±¤ë dim_num ÈÖÌÜ(0¤«¤é¿ô¤¨¤ë)¤Î¼¡¸µ¤òÌä¹ç¤ï¤»¤ë¡£ °ú¿ô * dim_num (Fixnum) : 0,1,2,...¡£ºÇ¤â®¤¯²ó¤ë¼¡¸µ¤¬0¡£ Ìá¤êÃÍ * NetCDFDim¥ª¥Ö¥¸¥§¥¯¥È Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_vardimidÍøÍÑ) ---dims ¤½¤ÎÊÑ¿ô¤ÎÁ´¼¡¸µ¤òÇÛÎó¤Ë¤¤¤ì¤ÆÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * NetCDFDim¥ª¥Ö¥¸¥§¥¯¥È¤ÎArray Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_vardimid ---shape_ul0 ÊÑ¿ô¤Î·Á¤òÊÖ¤¹. ⤷̵À©¸Â¼¡¸µ¤ÎŤµ¤Ï¥¼¥í. ¾¤ÎÊÑ¿ô¤ÎÄêµÁ¤ËÊØÍø. °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Array. [0¼¡¸µÌܤÎŤµ, 1¼¡¸µÌܤÎŤµ,.. ] Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_vardimid, nc_inq_unlimdim Åù¤òÍøÍÑ) ---shape_current ÊÑ¿ô¤Î¸½ºß¤Î·Á¤òÊÖ¤¹. °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Array. [0¼¡¸µÌܤÎŤµ, 1¼¡¸µÌܤÎŤµ,.. ] Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_vardimid Åù¤òÍøÍÑ) ---each_att{ ... } ÊÑ¿ôÃæ¤ÎÁ´Â°À­(NetCDFAtt)¤Ë´Ø¤¹¤ë¥¤¥Æ¥ì¡¼¥¿ °ú¿ô * { ... } : ·«¤êÊÖ¤¹¥Ö¥í¥Ã¥¯ Ìá¤êÃÍ * self Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_natts, nc_inq_attname¤òÍøÍÑ) ---dim_names ÊÑ¿ôÃæ¤ÎÁ´¼¡¸µ¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String ¤Î Array Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_varndims, nc_inq_vardimid, nc_inq_dimname ¤òÍøÍÑ) ---att_names ÊÑ¿ôÃæ¤ÎÁ´Â°À­¤Î̾Á°¤òÇÛÎó¤ËÆþ¤ì¤ÆÊÖ¤¹¡£ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String ¤Î Array Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_natts, nc_inq_attname¤òÍøÍÑ) ---name ÊÑ¿ô¤Î̾Á°¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_varname ---name=(variable_newname) ̾Á°¤òÉÕ¤±Âؤ¨¤ë °ú¿ô * variable_newname (String) : ¿·¤·¤¤Ì¾Á° Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_rename_var ---ndims ¼¡¸µ¤Î¿ô¤òÌ䤦 °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Integer Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_varndims ---rank ndims¤Î¥¨¥ê¥¢¥¹ ---ntype vartype¤ÎÊÌ̾ ---vartype ÊÑ¿ôÃͤη¿¤òÌ䤦 °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String ("char","byte","sint","int","sfloat", or "float") Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_vartype ---typecode ÊÑ¿ôÃͤη¿¤òÌ䤦(NArray¤Îtypecode¤ÇÊÖ¤¹) °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Fixnum¥ª¥Ö¥¸¥§¥¯¥È (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT) Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_vartype ---natts °À­¤Î¿ô¤òÌ䤦 °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Integer Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_varnatts ---file ¤½¤ÎÊÑ¿ô¤¬Â°¤¹¤ë¥Õ¥¡¥¤¥ë¤òÌä¹ç¤ï¤»¤ë °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * NetCDF¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * ¤Ê¤· ---att(attribute_name) ̾Á°¤ò»ØÄꤷ¤¿Â°À­¤òÊÖ¤¹ °ú¿ô * attribute_name (String) : ¼è¤ê½Ð¤¹Â°À­Ì¾ Ìá¤êÃÍ * NetCDFAtt¥ª¥Ö¥¸¥§¥¯¥È. ¸ºß¤·¤Ê¤±¤ì¤Ðnil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (nc_inq_attid¤ò¸¡ºº¤ËÍøÍÑ) ---put_att(attribute_name, value, atttype=nil) °À­¤òÀßÄê °ú¿ô * attribute_name (String) : attribute̾ * value (Numeric, String, Array of Numeric, or NArray) : ÀßÄꤹ¤ëÃÍ * atttype (nil or String) : °À­¤Î·¿. "char"(="string"),"byte", "sint","int","sfloat", "float" (¤½¤ì ¤¾¤ì,1,1,2,4,4,8 ¥Ð¥¤¥È)) ¤Þ¤¿¤Ï nil (¤Ä¤Þ¤ê¤ªÇ¤¤») Ìá¤êÃÍ * NetCDFAtt¤Î¥ª¥Ö¥¸¥§¥¯¥È Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_put_att_ ---put(value, option=nil) (())¤ÎÊÌ̾(alias) ---simple_put(value, option=nil) ÃͤòÆþ¤ì¤ë °ú¿ô * value : Æþ¤ì¤ëÃÍ (Numeric,Array(Numeric¤Î1¼¡¸µÇÛÎó)¡¢NArray) ¥¹¥«¥é¡¼(Numeric)¤Þ¤¿¤ÏŤµ£±¤Î¾ì¹ç¤Ï¡¢¤½¤ÎÃͤò°ìÍͤËÀßÄꤹ¤ë¡£ * option (Hash) : ÊÑ¿ô¤Î°ìÉôʬ¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥ª¥×¥·¥ç¥ó°ú¿ô¡£¾Ê ά¤¹¤ì¤Ð¡¢ÊÑ¿ôÁ´ÂΤ¬ÂоݤȤʤ롣¥Ï¥Ã¥·¥å¤Î¥­¡¼¤È¤·¤Æ¤Ï¡¢ "start","end","stride"¤ÎÁÈ¡¢¤Þ¤¿¤Ï"index"¤¬»ÈÍѤǤ­¤ë¡£"index" ¤Ï1Í×Áǡʥ¹¥«¥é¡¼¡Ë¤ò»Ø¤¹¡£"end","stride"¤Ï¾Êά²Ä¡£¾Êά¤¹¤ë¤Ë¤· ¤í¤·¤Ê¤¤¤Ë¤·¤í¡¢½ñ¤­¤³¤à¤Ù¤­Í×ÁǤοô¤¬ value¤Î¤½¤ì¤È°ìÃפ¹¤ë¤è¤¦¤Ë¤· ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£start,end,index¤Ç¤ÏArray¤Î¾ì¹ç¤ÈƱÍÍ¡¢Éé¤ÎÃͤǸå¤í ¤«¤é¤Î°ÌÃÖ¤ò»ØÄê¤Ç¤­¤ë¡£"stride"¤ÏÀµ¤ÎÃͤΤ߼õ¤±ÉÕ¤±¤ë¤Î¤Ç¡¢ÇÛ Îó¤ò°ú¤Ã¤¯¤êÊÖ¤·¤¿¤±¤ì¤Ð¸å¤«¤éÊÌÅÓ¤ä¤ë¤³¤È¤Ë¤Ê¤ë¡£ Îã¡§ ÊÑ¿ô¤¬2¼¡¸µ¤Î¾ì¹ç: {"start"=>[2,5],"end"=>[6,-1],"stride"=>[2,4]} -- Âè1¼¡¸µÌܤϡ¢ Í×ÁÇ 2 ¤«¤é 6 ¤Þ¤Ç 1 ¤Ä¤ª¤­ (0¤«¤é¿ô¤¨¤ë¤Î¤ÇÍ×ÁÇ 2 ¤Ï 3 ÈÖÌܤǤ¢ ¤ë¤³¤È¤ËÃí°Õ)¡¢Âè2¼¡¸µÌܤϡ¢Í×ÁÇ 6 ¤«¤é ºÇ¸å(=-1)¤Þ¤Ç 3 ¤Ä¤ª¤­ ¤Ë¤È¤Ã¤¿¥µ¥Ö¥»¥Ã¥È¡£ {"index"=>[0,0]}: ºÇ½é¤ÎÍ×ÁǤˤ¢¤¿ ¤ë¥¹¥«¥é¡¼ÃÍ {"index"=>[0,-2]}: 1¼¡¸µÌܤϺǽé, 2¼¡¸µÌܤϺǸ夫¤é2ÈÖÌܤˤ¢¤¿ ¤ë¥¹¥«¥é¡¼ÃÍ Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_put_var_, nc_put_vars_, nc_put_var1_ ---pack(na) self¤Î°À­ scale_factor and/or add_offset ¤òÍѤ¤¤Æ NArray Åù¤ò "pack" ¤¹¤ë. ¤â¤·¤â scale_factor and/or add_offset ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ì¤Ð (na-add_offset)/scale_factor ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð na ¤òÊÖ¤¹¡£ °ú¿ô * na : pack ¤¹¤ë¿ôÃÍÇÛÎó (NArray, NArrayMiss, Array) Ìá¤êÃÍ * a NArray or NArrayMiss ---scaled_put(value, option=nil) (()) ¤ÈƱÍͤÀ¤¬¡¢(())¤Ë¤è¤ê°À­ scale_factor ¤È add_offset ¤ò²ò¼á¤¹¤ë °ú¿ôÅù¤Ë¤Ä¤¤¤Æ¤Ï put ¤Î²òÀâ¤ò»²¾È¤Î¤³¤È ---get(option=nil) (())¤ÎÊÌ̾(alias) ---simple_get(option=nil) Ãͤò¼è¤ê½Ð¤¹ °ú¿ô * option (Hash) : ÊÑ¿ô¤Î°ìÉôʬ¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥ª¥×¥·¥ç¥ó°ú¿ô¡£»Å ÍÍ¤Ï put ¤ËƱ¤¸¡£ Ìá¤êÃÍ * NArray¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_get_var_, nc_get_vars_, nc_get_var1_ ---unpack(na) self¤Î°À­ scale_factor and/or add_offset ¤òÍѤ¤¤Æ NArray Åù¤ò "unpack" ¤¹¤ë. ¤â¤·¤â scale_factor and/or add_offset ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ì¤Ð na * scale_factor + add_offset ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð na ¤òÊÖ¤¹¡£ coerce ¤Ë¤è¤Ã¤Æ·¿¤¬ÊѲ½¤¹¤ë -- Î㤨¤Ð¡¢¤â¤· na ¤¬ sint ¤Ç scale_factor ¤È add_offset ¤¬ sfloat ¤Ç¤¢¤ì¤Ð¡¢ÊÖ¤êÃÍ¤Ï sfloat ¤Ë¤Ê¤ë¡£ÊÖ¤êÃͤη¿¤Ï (()) ¤ò»È¤Ã¤Æ Íۤ˻ØÄꤹ¤ë¤³¤È¤â¤Ç¤­¤ë¡£ °ú¿ô * na : unpack ¤¹¤ë¿ôÃÍÇÛÎó (NArray, or NArrayMiss) Ìá¤êÃÍ * a NArray or NArrayMiss ---scaled_get(option=nil) (()) ¤ÈƱÍͤÀ¤¬¡¢(())¤Ë¤è¤ê°À­ scale_factor ¤È add_offset ¤ò²ò¼á¤¹¤ë °ú¿ôÅù¤Ë¤Ä¤¤¤Æ¤Ï put ¤Î²òÀâ¤ò»²¾È¤Î¤³¤È ---[] NetCDFVar#get ¤ÈƱÍͤÀ¤¬¡¢¥µ¥Ö¥»¥Ã¥È¤ò NArray#[] ¤ÈƱÍͤ˻ØÄꤹ¤ë. NArray¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥µ¥Ö¥»¥Ã¥È»ØÄêÊýË¡¤Ë²Ã¤¨¤Æ¡¢¥¹¥Æ¥Ã¥×ÉÕ ¤­¤ÎÈϰϤò»ØÄê¤Ç¤­¤ë¡£¤³¤ì¤Ï {0..-1,2} ¤Ê¤É¤È¤¹¤ë¡£¤Ä¤Þ¤ê¡¢Í×ÁÇ ¿ô¤¬£±¤Î¥Ï¥Ã¥·¥å¤Î¥­¡¼¤ËÈϰÏ(Range)¡¢Ãͤ˥¹¥Æ¥Ã¥×(Integer)¤ò»ØÄê ¤¹¤ë¡£NArray¤È°ã¤¤¡¢£²¼¡¸µ°Ê¾å¤ÎÊÑ¿ô¤ò£±¼¡¸µ¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤Ç »ØÄꤹ¤ë¤³¤È¤Ï½ÐÍè¤Ê¤¤¡£ ---[]= NetCDFVar#put ¤ÈƱÍͤÀ¤¬¡¢¥µ¥Ö¥»¥Ã¥È¤ò NArray#[]= ¤ÈƱÍͤ˻ØÄꤹ¤ë. NArray¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¥µ¥Ö¥»¥Ã¥È»ØÄêÊýË¡¤Ë²Ã¤¨¤Æ¡¢¥¹¥Æ¥Ã¥×ÉÕ ¤­¤ÎÈϰϤò»ØÄê¤Ç¤­¤ë¡£¤³¤ì¤Ï {0..-1,2} ¤Ê¤É¤È¤¹¤ë¡£¤Ä¤Þ¤ê¡¢Í×ÁÇ ¿ô¤¬£±¤Î¥Ï¥Ã¥·¥å¤Î¥­¡¼¤ËÈϰÏ(Range)¡¢Ãͤ˥¹¥Æ¥Ã¥×(Integer)¤ò»ØÄê ¤¹¤ë¡£NArray¤È°ã¤¤¡¢£²¼¡¸µ°Ê¾å¤ÎÊÑ¿ô¤ò£±¼¡¸µ¤Î¥¤¥ó¥Ç¥Ã¥¯¥¹¤Ç »ØÄꤹ¤ë¤³¤È¤Ï½ÐÍè¤Ê¤¤¡£ ==="numru/netcdf_miss" ¤ò require ¤¹¤ë¤³¤È¤ÇÄɲ䵤ì¤ë¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É ---get_with_miss(option=nil) (())¤ÈƱÍͤÀ¤¬¡¢¥Ç¡¼¥¿·ç»¤ò½èÍý¤¹¤ë ¥Ç¡¼¥¿·ç»¤Ïɸ½à°À­ valid_range, (valid_min and/or valid_max), ¤Þ¤¿¤Ï missing_value ¤Ë¤è¤ê»ØÄꤵ¤ì¤ë¡£²ò¼á¤ÎÍ¥Àè½ç°Ì¤Ï¤³¤Î½çÈÖ¤Ç ¤¢¤ë¡£¡Ö¥æ¡¼¥¶¡¼¥º¥¬¥¤¥É¡×¤Î¿ä¾©¤È°ã¤¤¡¢¤³¤³¤Ç¤Ï missin_value ¤â ²ò¼á¤µ¤ì¤ë¡£¤â¤· missing_value ¤È valid_* ¤¬Æ±»þ¤Ë¸ºß¤¹¤ë¾ì¹ç¡¢ missng_value ¤ÏÍ­¸ú¥Ç¡¼¥¿Èϰϳ°¤Ë¤¢¤Ã¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¤½¤Î¾ì¹ç¡¢Îã³° ¤¬È¯À¸¤¹¤ë¡£ ¾åµ­¤Î¤è¤¦¤Ë¤â¤·¥Ç¡¼¥¿·ç»¡Ê¤Î»ÅÊý¡Ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤ì¤Ð¡¢¤³¤Î¥á¥½¥Ã ¥É¤Ï NArrayMiss ¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð NArray ¤òÊÖ¤¹¡£ °ú¿ô * (())¤ò¸«¤è. Ìá¤êÃÍ * NArrayMiss¥ª¥Ö¥¸¥§¥¯¥È (¥Ç¡¼¥¿·ç»¤¬»ØÄꤵ¤Æ¤¤¤ë¾ì¹ç) ¤Þ¤¿¤Ï NArray ¥ª¥Ö¥¸¥§¥¯¥È (¥Ç¡¼¥¿·ç»¤¬»ØÄꤵ¤Æ¤Ê¤¤¾ì¹ç) NetcdfError °Ê³°¤ÎÎ㳰ȯÀ¸ * missing_value ¤¬¥Ç¡¼¥¿Í­¸úÈϰϤˤʤ¤ (¾åµ­»²¾È¤Î¤³¤È). Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (()) ¤ò¸«¤è. ¤³¤Î¥á¥½¥Ã¥É¤Ï Ruby ¤Î¤ß¤Ç½ñ¤«¤ì¤Æ¤¤¤ë. Îã * ¼¡¤ÎÎã¤Ç¤Ï (()) ¤ò (()) ¤òÃÖ¤­´¹¤¨¤Æ¤¤¤ë. ¤³¤¦¤¹¤ë¤È ((<[]>)) ¤â¥Ç¡¼¥¿·ç»¤ò²ò¼á¤¹¤ë¤è¤¦¤Ë¤Ê¤ë (ÆâÉô¤Ç (({get})) ¤ò¸Æ¤ó¤Ç¤ë¤Î¤Ç). file = NetCDF.open('hogehoge.nc') var = file.var('var') def var.get(*args); get_with_miss(*args); end p var.get # --> inteprets data missing if defined p var[0..-1,0] # --> inteprets data missing if defined (assumed 2D) ---get_with_miss_and_scaling(option=nil) (())¤ÈƱÍͤÀ¤¬¡¢(())¤Ë¤è¤ê¥¹¥±¡¼¥ê¥ó¥°¤â¹Ô¤¦. ·ç»ÃͽèÍý¤Ï´ðËÜŪ¤Ë¤Ï pack ¤·¤¿¥Ç¡¼¥¿¤òÂоݤ˹Ԥ¦(¤³¤ì¤Ï¿¤¯¤Î ¥³¥ó¥Ù¥ó¥·¥ç¥óºÎÍѤµ¤ì¤Æ¤¤¤ë)¡£¤¿¤À¤·¡¢valid_* / missing_value ¤Î·¿¤¬ pack ¤·¤¿¥Ç¡¼¥¿¤Î·¿¤È°Û¤Ê¤ê¡¢¤«¤Ä unpack¤·¤¿¥Ç¡¼¥¿¤Î·¿¤È °ìÃפ¹¤ë¤È¤­¡Ê¤Ë¸Â¤ê¡Ë unpack ¤·¤¿¥Ç¡¼¥¿¤òÂоݤȤ¹¤ë¡£ ¤³¤ì¤Ç´ðËÜŪ¤ËÁ´¤Æ¤Î¥³¥ó¥Ù¥ó¥·¥ç¥ó¤ËÂбþ¤Ç¤­¤ë¡£ Îã * ¾åµ­»²¾È¡£Æ±¤¸¤³¤È¤¬¤Ç¤­¤ë¡£ ---put_with_miss(value, option=nil) (())¤ÈƱÍͤÀ¤¬¡¢¥Ç¡¼¥¿·ç»¤ò½èÍý¤¹¤ë ¤â¤·¤â (({value})) ¤¬ NArray ¤Ê¤é¡¢¤³¤Î¥á¥½¥Ã¥É¤Ï (()) ¤ËƱ ¤¸. ¤â¤·(({value})) ¤¬ NArrayMiss ¤Ç¤«¤Ä self ¤Î°À­¤Ë¤è¤ê¥Ç¡¼¥¿·ç»¤¬ ÄêµÁ¤µ¤ì¤Æ¤¤¤ì¤Ð ((())¤ò»²¾È¤Î¤³¤È)¡¢(({value})) Ãæ¤Î¥Ç¡¼¥¿·ç»¤¬²ò¼á¤µ¤ì¤ë¡£Â¨¤Á¡¢(({value}))Ãæ¤Î·ç»¥Ç¡¼¥¿¤Ï¡¢ ¤¢¤ë·ç»ÃÍ (missing_value ¤Þ¤¿¤Ï _FillValue ¤Þ¤¿¤Ï¥Ç¡¼¥¿Í­¸úÈÏ°Ï ³°¤ÎŬÅö¤ÊÃÍ) ¤ËÃÖ¤­´¹¤¨¤é¤ì¤¿¾å¤Ç¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤Þ¤ì¤ë¡£ (({value})) Ãæ¤ÎÈó·ç»¥Ç¡¼¥¿¤¬ (({self})) ¤Ë¤ª¤±¤ëÍ­¸úÈÏ°Ï¤ËÆþ¤Ã¤Æ ¤¤¤ë¤«¤É¤¦¤«¤Ï¥Á¥§¥Ã¥¯¤µ¤ì¤Ê¤¤¡£ °ú¿ô * value : NArrayMiss ¤Þ¤¿¤Ï (()) ¤Çµö¤µ¤ì¤Æ¤¤¤ë¥¯¥é¥¹¤Î¥ª¥Ö¥¸¥§¥¯¥È. * option (Hash) : (()) ¤ò¸«¤è. Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * (()) ¤ò¸«¤è. ¤³¤Î¥á¥½¥Ã¥É¤Ï Ruby ¤Î¤ß¤Ç½ñ¤«¤ì¤Æ¤¤¤ë. Îã * ¼¡¤ÎÎã¤Ç¤Ï (()) ¤ò (()) ¤òÃÖ¤­´¹¤¨¤Æ¤¤¤ë. ¤³¤¦¤¹¤ë¤È ((<[]=>)) ¤â¥Ç¡¼¥¿·ç»¤ò²ò¼á¤¹¤ë¤è¤¦¤Ë¤Ê¤ë (ÆâÉô¤Ç (({put})) ¤ò¸Æ¤ó¤Ç¤ë¤Î¤Ç). file = NetCDF.open('hogehoge.nc') var = file.var('var') def var.put(*args); put_with_miss(*args); end var.put = narray_miss # --> inteprets data missing if defined var[0..-1,0] = narray_miss # --> inteprets data missing if defined (assumed 2D) ---put_with_miss_and_scaling(value, option=nil) (())¤ÈƱÍͤÀ¤¬¡¢(())¤Ë¤è¤ê¥¹¥±¡¼¥ê¥ó¥°¤â¹Ô¤¦. ·ç»ÃͽèÍý¤Ï´ðËÜŪ¤Ë¤Ï pack ¤·¤¿¥Ç¡¼¥¿¤òÂоݤ˹Ԥ¦(¤³¤ì¤Ï¿¤¯¤Î ¥³¥ó¥Ù¥ó¥·¥ç¥óºÎÍѤµ¤ì¤Æ¤¤¤ë)¡£¤¿¤À¤·¡¢valid_* / missing_value ¤Î·¿¤¬ pack ¤·¤¿¥Ç¡¼¥¿¤Î·¿¤È°Û¤Ê¤ê¡¢¤«¤Ä unpack¤·¤¿¥Ç¡¼¥¿¤Î·¿¤È °ìÃפ¹¤ë¤È¤­¡Ê¤Ë¸Â¤ê¡Ë unpack ¤·¤¿¥Ç¡¼¥¿¤òÂоݤȤ¹¤ë¡£ ¤³¤ì¤Ç´ðËÜŪ¤ËÁ´¤Æ¤Î¥³¥ó¥Ù¥ó¥·¥ç¥ó¤ËÂбþ¤Ç¤­¤ë¡£ Îã * ¾åµ­»²¾È¡£Æ±¤¸¤³¤È¤¬¤Ç¤­¤ë¡£ --------------------------------------------- =¥¯¥é¥¹ NetCDFAtt ===¥¯¥é¥¹¥á¥½¥Ã¥É ===¥¤¥ó¥¹¥¿¥ó¥¹¥á¥½¥Ã¥É ---name °À­¤Î̾Á°¤òÊÖ¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * String Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * ¤Ê¤· ---name=(attribute_newname) °À­¤Î̾Á°¤òÊѹ¹ °ú¿ô * attribute_newname (String) : ¿·¤·¤¤Ì¾Á° Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_rename_att ---copy(var_or_file) °À­¤òÊ̤ÎÊÑ¿ô¤Þ¤¿¤Ï¥Õ¥¡¥¤¥ë¤Ë¥³¥Ô¡¼¡£¥Õ¥¡¥¤¥ë¤Î¾ì¹ç¤Ï¥°¥í¡¼¥Ð¥ë°À­¤Ë¤Ê¤ë °ú¿ô * var_or_file (NetCDFVar or NetCDF) Ìá¤êÃÍ * ¥³¥Ô¡¼¤·¤Æºî¤é¤ì¤¿Â°À­ (NetCDFAtt) Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_copy_att ---delete °À­¤òºï½ü °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_del_att ---put(value, atttype=nil) °À­¤ÎÃͤòÀßÄê °ú¿ô * value (Numeric, String, Array of Numeric, or NArray) : Æþ¤ì¤ëÃÍ * atttype (nil or String) : °À­¤Î·¿. "char"(="string"),"byte", "sint","int","sfloat", "float" (¤½¤ì ¤¾¤ì,1,1,2,4,4,8 ¥Ð¥¤¥È)) ¤Þ¤¿¤Ï nil (¤Ä¤Þ¤ê¤ªÇ¤¤») Ìá¤êÃÍ * nil Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_put_att_ ---get °À­¤ÎÃæ¿È¤ò¼è¤ê½Ð¤¹ °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * ʸ»úÎó¤Þ¤¿¤ÏNArray¥ª¥Ö¥¸¥§¥¯¥È (Ãí°Õ: ¥¹¥«¥é¡¼¤Î¾ì¹ç¤âŤµ1¤Î NArray¤Ë¤Ê¤ë) Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_get_att_ ---atttype °À­Ãͤη¿¤òÌ䤦 °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * "char","byte","sint","int","sfloat","float" Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_atttype ---typecode °À­Ãͤη¿¤òÌ䤦(NArray¤Îtypecode¤ÇÊÖ¤¹) °ú¿ô * ¤Ê¤· Ìá¤êÃÍ * Fixnum¥ª¥Ö¥¸¥§¥¯¥È (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT) Âбþ¤¹¤ë(ÍøÍѤ¹¤ë) C ÈÇ NetCDF ¤Î´Ø¿ô * nc_inq_atttype =end ruby-netcdf-0.7.2/Rakefile0000644000175000017500000000175412772251340015255 0ustar uwabamiuwabami# -* coding: utf-8 -*- require 'rake/testtask' require 'rake/extensiontask' require 'rake/packagetask' begin require 'bundler/gem_helper' # instead of 'bundler/gem_tasks' -> need manual # calls of install_tasks (see below) rescue LoadError puts 'If you want to create gem, You must install Bundler' end # manual calls of install_tasks to support multiple gemspec files Bundler::GemHelper.install_tasks(name: "ruby-netcdf") #Bundler::GemHelper.install_tasks(name: "ruby-netcdf-bigmem") require './lib/numru/netcdf/version' def version NumRu::NetCDF::VERSION end task :default => :test task :test => :compile Rake::TestTask.new do |t| t.libs << 'lib' << 'test' t.test_files = FileList['test/*.rb'] end Rake::ExtensionTask.new do |ext| ext.name = 'netcdfraw' ext.ext_dir = 'ext/numru' ext.lib_dir = 'lib/numru' end Rake::PackageTask.new('ruby-netcdf', "#{version}") do |t| t.need_tar_gz = true t.package_files.include `git ls-files`.split("\n") end ruby-netcdf-0.7.2/ruby-netcdf-bigmem.gemspec0000644000175000017500000000232512772251340020630 0ustar uwabamiuwabami# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'numru/netcdf/version' Gem::Specification.new do |spec| spec.name = "ruby-netcdf-bigmem" spec.version = NumRu::NetCDF::VERSION spec.authors = ["Takeshi Horinouchi", "Tsuyoshi Koshiro",\ "Shigenori Otsuka", "Seiya Nishizawa", "T Sakakima"] spec.email = ['eriko@gfd-dennou.org'] spec.summary = %q{Ruby interface to NetCDF} spec.description = %q{RubyNetCDF is the Ruby interface to the NetCDF library built on the NArray library, which is an efficient multi-dimensional numeric array class for Ruby. This version works with Ruby2.0.} spec.homepage = 'http://www.gfd-dennou.org/arch/ruby/products/ruby-netcdf/' spec.licenses = ["BSD-2-Clause"] spec.files = `git ls-files -z`.split("\x0") spec.test_files = spec.files.grep(%r{^(test|demo)/}) spec.require_paths = ["ext","lib"] spec.extensions << "ext/numru/extconf.rb" spec.required_ruby_version = Gem::Requirement.new(">= 1.8") spec.add_runtime_dependency(%q, [">= 0"]) spec.add_runtime_dependency(%q, [">= 0"]) end ruby-netcdf-0.7.2/ext/0000755000175000017500000000000012772251340014401 5ustar uwabamiuwabamiruby-netcdf-0.7.2/ext/numru/0000755000175000017500000000000012772251340015547 5ustar uwabamiuwabamiruby-netcdf-0.7.2/ext/numru/extconf.rb0000644000175000017500000001271712772251340017552 0ustar uwabamiuwabamirequire "mkmf" require "rubygems" unless defined?(Gem) ar = ARGV.grep( /^--with-netcdf-version=/ ) if ar.length > 0 ncversion = ar[0].sub(/^--with-netcdf-version=/,"") else ncversion = nil end if Gem.respond_to?(:find_files) and Gem.find_files("narray.h").length > 0 require "rbconfig" so = RbConfig::CONFIG["DLEXT"] narray_include = File.expand_path(File.dirname(Gem.find_files("narray.h")[0])) narray_lib = File.expand_path(File.dirname(Gem.find_files("narray." + so)[0])) else gem_home=(`gem environment GEM_HOME`).chomp narray_dir = Dir.glob("#{gem_home}/gems/narray-*/ext/narray").sort[-1] if narray_dir narray_include = narray_lib = narray_dir else narray_include = narray_lib = [ $sitearchdir, $vendorarchdir] end end dir_config('narray', narray_include, narray_lib) dir_config('netcdf', '/usr/local') if ( ! ( have_header("narray.h") && have_header("narray_config.h") ) ) then print < 4.2.1 else ncversion = "3.0.0" # assume version 3 (only for compilation) # For compilation, there is no difference among subversions of netcdf 3 end end ncver0 = ncversion[0..0] # "3" or "4" ncver = ncversion.gsub(/\./,'') unless /^\d\d\d$/ =~ ncver # 3 digits raise("Invalid netcdf version: #{ncversion}. Use --with-netcdf-version=") end $CFLAGS += ' -DNCVER='+ncver case ncver0 when "4" if xsystem("nc-config --libs") # for NetCDF 4 cflags = `nc-config --cflags`.gsub(/\n/, " ") libs = `nc-config --libs`.gsub(/\n/, " ") prefix_nc = `nc-config --prefix`.gsub(/\n/, "") dir_config("netcdf",prefix_nc) $CFLAGS += ' ' + cflags $LOCAL_LIBS += ' ' + libs end when "3" # for NetCDF 3, which needs external libraries for OpenDAP if xsystem("ncdap-config --libs") libncdods = "nc-dap" cflags = `ncdap-config --cflags`.gsub(/\n/, " ") libs = `ncdap-config --libs`.gsub(/\n/, " ") prefix_dods = `ncdap-config --prefix`.gsub(/\n/, "") elsif xsystem("opendap-config --libs") libncdods = "nc-dods" cflags = `opendap-config --cflags`.gsub(/\n/, " ") libs = `opendap-config --libs-nc`.gsub(/\n/, " ") prefix_dods = `opendap-config --prefix`.gsub(/\n/, "") end if (enable_config('opendap',true) && ( xsystem("opendap-config --libs") || xsystem("ncdap-config --libs") ) ) dir_config(libncdods,prefix_dods) if (!have_library(libncdods)) print <<-EOS ** ERROR ** Library not found: nc-dods (OPeNDAP/DODS-enabled NetCDF lib) Install it, or run extconf.rb with option --disable-opendap. ^^^^^^^^^^^^^^^^^ EOS exit(-1) else print <<-EOS ** Message ** Compiling with OPeNDAP/DODS-enabled NetCDF library. This is because the command opendap-config is found in your system. If you want to use the ordinary (non-DODS) version of NetCDF, run extconf.rb with option --disable-opendap. ^^^^^^^^^^^^^^^^^ EOS end $CFLAGS += ' '+cflags $LOCAL_LIBS += ' ' + libs # non portable treatments: should be improved (by Horinouchi) CONFIG['LDSHARED'].sub!(/gcc/,'g++') $LIBS.sub!(/-lc\s/,'') ; $LIBS.sub!(/-lc$/,'') print <<-EOS ** Warning ** non-portable treatments are made, which was sucessfull redhat linux 9: * gcc was replaced with g++ in CONFIG['LDSHARED'] * -lc library was removed if in $LIBS EOS # p '@@@' # ary = [] # CONFIG.each{|k,v| ary.push([k,v])} # ary.sort.each{|x| p x} else if ( ! ( have_header("netcdf.h") && have_library("netcdf") ) )then print <<-EOS ** configure error ** Header netcdf.h or the compiled netcdf library is not found. If you have the library installed under /netcdfdir (that is, netcdf.h is in /netcdfdir/include and the library in /netcdfdir/lib/), try the following: % ruby extconf.rb --with-netcdf-dir=/netcdfdir Alternatively, you can specify the two directory separately with --with-netcdf-include and --with-netcdf-lib. EOS exit(-1) end end else raise "Netcdf version #{ncver0} is not supported" end if /cygwin|mingw/ =~ RUBY_PLATFORM have_library("narray") || raise("ERROR: narray library is not found") end create_makefile "numru/netcdfraw" ###### Modify Makefile: ####### File.rename("Makefile","Makefile.orig") oldmkfl = File.open("Makefile.orig") newmkfl = File.open("Makefile","w") oldmkfl.each_line{ |line| case(line) when /^distclean:/ newmkfl.puts(line) newmkfl.puts("\t\t@$(RM) *.nc demo/*.nc demo/*~ lib/*~ doc/*~ test/*.nc test/*~ Makefile.orig") when /^all:/ newmkfl.puts(line) newmkfl.puts("") newmkfl.puts("test: all") # insert the "test" target newmkfl.puts("\t\t@cd test && ruby test.rb && echo 'test did not fail :-p (please ignore the warnings)' && cd ..") # when /lib\/netcdf/ # line = line.chomp! + "/" # newmkfl.puts(line) else newmkfl.puts(line) end } newmkfl.close ruby-netcdf-0.7.2/ext/numru/netcdfraw.c0000644000175000017500000035500412772251340017677 0ustar uwabamiuwabami#include #include "ruby.h" #include "narray.h" #include #include /* for compatibility with ruby 1.6 */ #ifndef RSTRING_PTR #define RSTRING_PTR(s) (RSTRING(s)->ptr) #endif #ifndef RSTRING_LEN #define RSTRING_LEN(s) (RSTRING(s)->len) #endif #ifndef RARRAY_PTR #define RARRAY_PTR(a) (RARRAY(a)->ptr) #endif #ifndef RARRAY_LEN #define RARRAY_LEN(a) (RARRAY(a)->len) #endif #ifndef StringValueCStr #define StringValueCStr(s) STR2CSTR(s) #endif #ifndef SafeStringValue #define SafeStringValue(s) Check_SafeStr(s) #endif /* for compatibility for NArray and NArray with big memory patch */ #ifndef NARRAY_BIGMEM typedef int na_shape_t; #endif /* Data to NArray */ /* memcpy(ary->ptr,nc_ptr,na_sizeof[NA_SINT]*ary->total); \ */ #define Cbyte_to_NArray(v, rank, shape, up) \ { \ struct NARRAY *ary; \ v = na_make_object(NA_BYTE, rank, shape, cNArray); \ GetNArray(v,ary); \ up = (unsigned char *)ary->ptr; \ } #define Csint_to_NArray(v, rank, shape, sp) \ { \ struct NARRAY *ary; \ v = na_make_object(NA_SINT, rank, shape, cNArray); \ GetNArray(v, ary); \ sp = (short *)ary->ptr; \ } #define Clint_to_NArray(v, rank, shape, lp) \ { \ struct NARRAY *ary; \ v = na_make_object(NA_LINT, rank, shape, cNArray); \ GetNArray(v, ary); \ lp = (int *)ary->ptr; \ } #define Cfloat_to_NArray(v, rank, shape, fp) \ { \ struct NARRAY *ary; \ v = na_make_object(NA_SFLOAT, rank, shape, cNArray); \ GetNArray(v, ary); \ fp = (float *)ary->ptr; \ } #define Cdouble_to_NArray(v, rank, shape, dp); \ { \ struct NARRAY *ary; \ v = na_make_object(NA_DFLOAT, rank, shape, cNArray); \ GetNArray(v, ary); \ dp = (double *)ary->ptr; \ } /* Array or NArray to pointer and length (with no new allocation) */ #define Array_to_Cfloat_len(obj, ptr, len) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_SFLOAT); \ GetNArray(obj, na); \ ptr = (float *) NA_PTR(na,0); \ len = na->total; \ } #define Array_to_Cfloat_len_shape(obj, ptr, len, shape) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_SFLOAT); \ GetNArray(obj, na); \ ptr = (float *) NA_PTR(na,0); \ len = na->total; \ shape = na->shape; \ } #define Array_to_Cdouble_len(obj, ptr, len) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_DFLOAT); \ GetNArray(obj, na); \ ptr = (double *) NA_PTR(na,0); \ len = na->total; \ } #define Array_to_Cdouble_len_shape(obj, ptr, len, shape) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_DFLOAT); \ GetNArray(obj, na); \ ptr = (double *) NA_PTR(na,0); \ len = na->total; \ shape = na->shape; \ } #define Array_to_Cbyte_len(obj, ptr, len) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_BYTE); \ GetNArray(obj, na); \ ptr = (u_int8_t *) NA_PTR(na,0); \ len = na->total; \ } #define Array_to_Cbyte_len_shape(obj, ptr, len, shape) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_BYTE); \ GetNArray(obj, na); \ ptr = (u_int8_t *) NA_PTR(na,0); \ len = na->total; \ shape = na->shape; \ } #define Array_to_Csint_len(obj, ptr, len) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_SINT); \ GetNArray(obj, na); \ ptr = (int16_t *) NA_PTR(na,0); \ len = na->total; \ } #define Array_to_Csint_len_shape(obj, ptr, len, shape) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_SINT); \ GetNArray(obj, na); \ ptr = (int16_t *) NA_PTR(na,0); \ len = na->total; \ shape = na->shape; \ } #define Array_to_Clint_len(obj, ptr, len) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_LINT); \ GetNArray(obj, na); \ ptr = (int32_t *) NA_PTR(na,0); \ len = na->total; \ } #define Array_to_Clint_len_shape(obj, ptr, len, shape) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_LINT); \ GetNArray(obj, na); \ ptr = (int32_t *) NA_PTR(na,0); \ len = na->total; \ shape = na->shape; \ } /* Array or NArray to pointer (with no new allocation) */ #define Array_to_Cfloat(obj, ptr) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_SFLOAT); \ GetNArray(obj, na); \ ptr = (float *) NA_PTR(na,0); \ } #define Array_to_Cdouble(obj, ptr) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_DFLOAT); \ GetNArray(obj, na); \ ptr = (double *) NA_PTR(na,0); \ } #define Array_to_Cbyte(obj, ptr) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_BYTE); \ GetNArray(obj, na); \ ptr = (u_int8_t *) NA_PTR(na,0); \ } #define Array_to_Csint(obj, ptr) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_SINT); \ GetNArray(obj, na); \ ptr = (int16_t *) NA_PTR(na,0); \ } #define Array_to_Clint(obj, ptr) \ { \ struct NARRAY *na; \ obj = na_cast_object(obj, NA_LINT); \ GetNArray(obj, na); \ ptr = (int32_t *) NA_PTR(na,0); \ } #define NC_RAISE(status) rb_raise(err_status2class(status),"%s",(nc_strerror(status))) #define NC_RAISE2(status, str) rb_raise(err_status2class(status),"%s (%s)",nc_strerror(status),(str) ) static VALUE mNumRu = 0; static VALUE cNetCDF; static VALUE cNetCDFDim; static VALUE cNetCDFAtt; static VALUE cNetCDFVar; static VALUE rb_eNetcdfError; static VALUE rb_eNetcdfBadid; static VALUE rb_eNetcdfNfile; static VALUE rb_eNetcdfExist; static VALUE rb_eNetcdfInval; static VALUE rb_eNetcdfPerm; static VALUE rb_eNetcdfNotindefine; static VALUE rb_eNetcdfIndefine; static VALUE rb_eNetcdfInvalcoords; static VALUE rb_eNetcdfMaxdims; static VALUE rb_eNetcdfNameinuse; static VALUE rb_eNetcdfNotatt; static VALUE rb_eNetcdfMaxatts; static VALUE rb_eNetcdfBadtype; static VALUE rb_eNetcdfBaddim; static VALUE rb_eNetcdfUnlimpos; static VALUE rb_eNetcdfMaxvars; static VALUE rb_eNetcdfNotvar; static VALUE rb_eNetcdfGlobal; static VALUE rb_eNetcdfNotnc; static VALUE rb_eNetcdfSts; static VALUE rb_eNetcdfMaxname; static VALUE rb_eNetcdfUnlimit; static VALUE rb_eNetcdfNorecvars; static VALUE rb_eNetcdfChar; static VALUE rb_eNetcdfEdge; static VALUE rb_eNetcdfStride; static VALUE rb_eNetcdfBadname; static VALUE rb_eNetcdfRange; static VALUE rb_eNetcdfNomem; /* Special Error */ /* Global error status */ static VALUE rb_eNetcdfFatal; /* Global options variable. Used to determine behavior of error handler. */ static VALUE rb_eNetcdfEntool; static VALUE rb_eNetcdfExdr; static VALUE rb_eNetcdfSyserr; struct Netcdf{ int ncid; char *name; int closed; }; struct NetCDFDim{ int dimid; int ncid; }; struct NetCDFVar{ int varid; int ncid; VALUE file; }; struct NetCDFAtt{ int varid; int ncid; char *name; }; static struct Netcdf * NetCDF_init(int ncid,char *filename) { struct Netcdf *Netcdffile; Netcdffile=xmalloc(sizeof(struct Netcdf)); Netcdffile->ncid=ncid; Netcdffile->closed=0; Netcdffile->name=xmalloc((strlen(filename)+1)*sizeof(char)); strcpy(Netcdffile->name,filename); return(Netcdffile); } static struct NetCDFDim * NetCDF_dim_init(int ncid,int dimid) { struct NetCDFDim *Netcdf_dim; Netcdf_dim=xmalloc(sizeof(struct NetCDFDim)); Netcdf_dim->dimid=dimid; Netcdf_dim->ncid=ncid; return(Netcdf_dim); } static struct NetCDFVar * NetCDF_var_init(int ncid,int varid,VALUE file) { struct NetCDFVar *Netcdf_var; Netcdf_var=xmalloc(sizeof(struct NetCDFVar)); Netcdf_var->varid=varid; Netcdf_var->ncid=ncid; Netcdf_var->file=file; return(Netcdf_var); } static struct NetCDFAtt * NetCDF_att_init(int ncid,int varid,char *attname) { struct NetCDFAtt *Netcdf_att; Netcdf_att=xmalloc(sizeof(struct NetCDFAtt)); Netcdf_att->ncid=ncid; Netcdf_att->varid=varid; Netcdf_att->name=xmalloc((strlen(attname)+1)*sizeof(char)); strcpy(Netcdf_att->name,attname); return(Netcdf_att); } void Netcdf_att_free(struct NetCDFAtt *Netcdf_att) { free(Netcdf_att->name); free(Netcdf_att); } void NetCDF_var_free(struct NetCDFVar *Netcdf_var) { free(Netcdf_var); } void NetCDF_dim_free(struct NetCDFDim *Netcdf_dim) { free(Netcdf_dim); } void NetCDF_free(struct Netcdf *Netcdffile) { if (!Netcdffile->closed){ nc_close(Netcdffile->ncid); /* no error check -- not to stop during GC */ } free(Netcdffile->name); free(Netcdffile); } static VALUE err_status2class(int status) { if(NC_ISSYSERR(status)){ return(rb_eNetcdfSyserr); } switch(status) { case(NC_EBADID): return(rb_eNetcdfBadid);break; case(NC_ENFILE): return(rb_eNetcdfNfile);break; case(NC_EEXIST): return(rb_eNetcdfExist);break; case(NC_EINVAL): return(rb_eNetcdfInval);break; case(NC_EPERM): return(rb_eNetcdfPerm);break; case(NC_ENOTINDEFINE): return(rb_eNetcdfNotindefine);break; case(NC_EINDEFINE): return(rb_eNetcdfIndefine);break; case(NC_EINVALCOORDS): return(rb_eNetcdfInvalcoords);break; case(NC_EMAXDIMS): return(rb_eNetcdfMaxdims);break; case(NC_ENAMEINUSE): return(rb_eNetcdfNameinuse);break; case(NC_ENOTATT): return(rb_eNetcdfNotatt);break; case(NC_EMAXATTS): return(rb_eNetcdfMaxatts);break; case(NC_EBADTYPE): return(rb_eNetcdfBadtype);break; case(NC_EBADDIM): return(rb_eNetcdfBaddim);break; case(NC_EUNLIMPOS): return(rb_eNetcdfUnlimpos);break; case(NC_EMAXVARS): return(rb_eNetcdfMaxvars);break; case(NC_ENOTVAR): return(rb_eNetcdfNotvar);break; case(NC_EGLOBAL): return(rb_eNetcdfGlobal);break; case(NC_ENOTNC): return(rb_eNetcdfNotnc);break; case(NC_ESTS): return(rb_eNetcdfSts);break; case(NC_EMAXNAME): return(rb_eNetcdfMaxname);break; case(NC_EUNLIMIT): return(rb_eNetcdfUnlimit);break; case(NC_ENORECVARS): return(rb_eNetcdfNorecvars);break; case(NC_ECHAR): return(rb_eNetcdfChar);break; case(NC_EEDGE): return(rb_eNetcdfEdge);break; case(NC_ESTRIDE): return(rb_eNetcdfStride);break; case(NC_EBADNAME): return(rb_eNetcdfBadname);break; case(NC_ERANGE): return(rb_eNetcdfRange);break; case(NC_ENOMEM): return(rb_eNetcdfNomem);break; /* case(NC_ENTOOL): return(rb_eNetcdfEntool);break; */ case(NC_EXDR): return(rb_eNetcdfExdr);break; case(NC_SYSERR): return(rb_eNetcdfSyserr);break; case(NC_FATAL): return(rb_eNetcdfFatal);break; } return rb_eNetcdfError; } static const char* nctype2natype(int nctype){ switch(nctype){ case NC_CHAR: return("char"); case NC_BYTE: return("byte"); case NC_SHORT: return("sint"); case NC_INT: return("int"); case NC_FLOAT: return("sfloat"); case NC_DOUBLE: return("float"); default: rb_raise(rb_eNetcdfError, "No such netcdf type number %d\n",nctype); } } static int nctype2natypecode(int nctype){ switch(nctype){ case NC_CHAR: return(NA_BYTE); case NC_BYTE: return(NA_BYTE); case NC_SHORT: return(NA_SINT); case NC_INT: return(NA_LINT); case NC_FLOAT: return(NA_SFLOAT); case NC_DOUBLE: return(NA_DFLOAT); default: rb_raise(rb_eNetcdfError, "No such netcdf type number %d\n",nctype); } } static int natype2nctype(char *natype) { if(strcmp(natype,"byte")==0) return(NC_BYTE); else if(strcmp(natype,"char")==0) return(NC_CHAR); else if(strcmp(natype,"text")==0) return(NC_CHAR); /* alias of char */ else if(strcmp(natype,"string")==0) return(NC_CHAR); /* alias of char */ else if(strcmp(natype,"sint")==0) return(NC_SHORT); else if(strcmp(natype,"int")==0) return(NC_INT); else if(strcmp(natype,"sfloat")==0) return(NC_FLOAT); else if(strcmp(natype,"float")==0) return(NC_DOUBLE); else rb_raise(rb_eNetcdfError, "No such NArray type '%s'",natype); } static int natypecode2nctype(int natypecode) { if(natypecode==NA_BYTE) return(NC_BYTE); else if(natypecode==NA_SINT) return(NC_SHORT); else if(natypecode==NA_LINT) return(NC_INT); else if(natypecode==NA_SFLOAT) return(NC_FLOAT); else if(natypecode==NA_DFLOAT) return(NC_DOUBLE); else rb_raise(rb_eNetcdfError, "No such NArray typecode '%d'",natypecode); } static void nc_mark_obj(struct NetCDFVar *netcdf_var) { VALUE ptr; ptr = netcdf_var->file; rb_gc_mark(ptr); } VALUE NetCDF_clone(VALUE file) { VALUE clone; struct Netcdf *nc1, *nc2; Data_Get_Struct(file, struct Netcdf, nc1); nc2 = NetCDF_init(nc1->ncid, nc1->name); clone = Data_Wrap_Struct(cNetCDF, 0, NetCDF_free, nc2); CLONESETUP(clone, file); return clone; } VALUE NetCDF_dim_clone(VALUE dim) { VALUE clone; struct NetCDFDim *nd1, *nd2; Data_Get_Struct(dim, struct NetCDFDim, nd1); nd2 = NetCDF_dim_init(nd1->ncid, nd1->dimid); clone = Data_Wrap_Struct(cNetCDFDim, 0, NetCDF_dim_free, nd2); CLONESETUP(clone, dim); return clone; } VALUE NetCDF_att_clone(VALUE att) { VALUE clone; struct NetCDFAtt *na1, *na2; Data_Get_Struct(att, struct NetCDFAtt, na1); na2 = NetCDF_att_init(na1->ncid, na1->varid, na1->name); clone = Data_Wrap_Struct(cNetCDFAtt, 0, Netcdf_att_free, na2); CLONESETUP(clone, att); return clone; } VALUE NetCDF_var_clone(VALUE var) { VALUE clone; struct NetCDFVar *nv1, *nv2; Data_Get_Struct(var, struct NetCDFVar, nv1); nv2 = NetCDF_var_init(nv1->ncid, nv1->varid, nv1->file); clone = Data_Wrap_Struct(cNetCDFVar, nc_mark_obj, NetCDF_var_free, nv2); CLONESETUP(clone, var); return clone; } VALUE NetCDF_inq_libvers(VALUE mod) { VALUE str; str = rb_str_new2(nc_inq_libvers()); return(str); } VALUE NetCDF_close(file) VALUE file; { int status; int ncid; struct Netcdf *Netcdffile; if (rb_safe_level() >= 3 && !OBJ_TAINTED(file)) { rb_raise(rb_eSecurityError, "Insecure: can't close"); } Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid=Netcdffile->ncid; if(!Netcdffile->closed){ status = nc_close(ncid); if(status != NC_NOERR) NC_RAISE(status); Netcdffile->closed = 1; } else { rb_warn("file %s is already closed", Netcdffile->name); } return Qnil; } VALUE NetCDF_def_dim(VALUE file,VALUE dim_name,VALUE length) { char* c_dim_name; size_t c_length; int ncid; int dimidp; int status; struct Netcdf *Netcdffile; struct NetCDFDim *Netcdf_dim; VALUE Dimension; rb_secure(3); Data_Get_Struct(file,struct Netcdf,Netcdffile); Check_Type(dim_name,T_STRING); c_dim_name=RSTRING_PTR(dim_name); c_length=NUM2UINT(length); ncid=Netcdffile->ncid; status = nc_def_dim(ncid,c_dim_name,c_length,&dimidp); if(status !=NC_NOERR) NC_RAISE(status); Netcdf_dim = NetCDF_dim_init(ncid,dimidp); Dimension = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim); return Dimension; } static VALUE NetCDF_put_att_char(int ncid, char *name,VALUE value,VALUE atttype, int varid) { int status; struct NetCDFAtt *ncatt; /* check atttype (not necessarily needed but it's better to do it) */ if (TYPE(atttype) == T_STRING){ if ( natype2nctype(RSTRING_PTR(atttype)) != NC_CHAR ) { rb_raise(rb_eNetcdfError, "attribute type must be 'char' (or nil) for a String value"); } } else if (TYPE(atttype) != T_NIL) { rb_raise(rb_eNetcdfError, "type specfication must be by a string or nil"); } /* put value */ Check_Type(value,T_STRING); status = nc_put_att_text(ncid, varid, name, RSTRING_LEN(value), RSTRING_PTR(value)); if(status != NC_NOERR) NC_RAISE(status); ncatt = NetCDF_att_init(ncid,varid,name); return (Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,ncatt)); } static VALUE NetCDF_put_att_numeric(int ncid, char *name,VALUE value,VALUE atttype, int varid) { VALUE val; struct NARRAY *na_val; int na_typecode, status, len; char *ptr; struct NetCDFAtt *ncatt; /* check atttype and cast to an appropriate NArray if needed */ if (TYPE(atttype) != T_NIL){ na_typecode = na_get_typecode(atttype); GetNArray( na_cast_object(value, na_typecode), na_val ); } else { if (TYPE(value)==T_ARRAY) { val = RARRAY_PTR(value)[0]; /* to check the 1st elemnt if Array */ } else { val = value; } switch(TYPE(val)){ case T_FIXNUM: case T_BIGNUM: na_typecode = NA_LINT; GetNArray( na_cast_object(value, na_typecode), na_val ); break; case T_FLOAT: na_typecode = NA_DFLOAT; GetNArray( na_cast_object(value, na_typecode), na_val ); break; case T_DATA: if ( IsNArray(value) ){ GetNArray(value,na_val); na_typecode = na_val->type; } else { rb_raise(rb_eNetcdfError,"value has a wrong data type"); } break; default: rb_raise(rb_eNetcdfError, "value (or its first element) has a wrong type"); } } /* put value */ len = na_val->total; ptr = na_val->ptr; switch(na_typecode){ case NA_BYTE: status = nc_put_att_uchar(ncid,varid,name,NC_BYTE,len,(unsigned char *)ptr); break; case NA_SINT: status = nc_put_att_short(ncid,varid,name,NC_SHORT,len,(short *)ptr); break; case NA_LINT: status = nc_put_att_int(ncid,varid,name,NC_INT,len,(int *)ptr); break; case NA_SFLOAT: status = nc_put_att_float(ncid,varid,name,NC_FLOAT,len,(float *)ptr); break; case NA_DFLOAT: status = nc_put_att_double(ncid,varid,name,NC_DOUBLE,len,(double*)ptr); break; default: rb_raise(rb_eNetcdfError, "unsupported type. code = %d",na_typecode); } if(status != NC_NOERR) NC_RAISE(status); ncatt = NetCDF_att_init(ncid,varid,name); return (Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,ncatt)); } static VALUE NetCDF_put_att__(int ncid, char *name, VALUE value, VALUE atttype, int varid) /* * atttype: nil or a String ("string","int",etc). If nil, * the type of attribute is determined from the type of value */ { switch(TYPE(value)){ case T_STRING: return(NetCDF_put_att_char(ncid, name, value, atttype, varid)); default: return(NetCDF_put_att_numeric(ncid, name, value, atttype, varid)); } } VALUE NetCDF_put_att(VALUE file,VALUE att_name,VALUE value,VALUE atttype) /* * atttype: nil or a String ("string","int",etc). If nil, * the type of attribute is determined from the type of value */ { struct Netcdf *ncfile; char *name; rb_secure(3); Data_Get_Struct(file,struct Netcdf,ncfile); Check_Type(att_name,T_STRING); name = RSTRING_PTR(att_name); return( NetCDF_put_att__(ncfile->ncid, name, value, atttype, NC_GLOBAL) ); } VALUE NetCDF_put_att_var(VALUE var,VALUE att_name,VALUE value,VALUE atttype) /* * atttype: nil or a String ("string","int",etc). If nil, * the type of attribute is determined from the type of value */ { struct NetCDFVar *ncvar; char *name; rb_secure(3); Data_Get_Struct(var,struct NetCDFVar,ncvar); Check_Type(att_name,T_STRING); name = RSTRING_PTR(att_name); return( NetCDF_put_att__(ncvar->ncid, name, value, atttype, ncvar->varid)); } VALUE NetCDF_def_var(VALUE file,VALUE var_name,VALUE vartype,VALUE dimensions) { int ncid; char *c_var_name; static int xtype; long c_ndims; int varidp; int dimidp; int i=0; int status; char *c_dim_name; int c_dimids[NC_MAX_DIMS]; struct Netcdf *Netcdffile; struct NetCDFVar *Netcdf_var; struct NetCDFDim *Netcdf_dim; VALUE Var; rb_secure(3); Check_Type(var_name,T_STRING); Check_Type(dimensions,T_ARRAY); c_var_name=RSTRING_PTR(var_name); c_ndims=RARRAY_LEN(dimensions); Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid=Netcdffile->ncid; if (TYPE(vartype) == T_STRING){ xtype = natype2nctype(RSTRING_PTR(vartype)); } else if (TYPE(vartype) == T_FIXNUM){ xtype = natypecode2nctype(NUM2INT(vartype)); } else { rb_raise(rb_eNetcdfError, "type specfication must be by a string or nil"); } for(i=0;idimid; break; default: rb_raise(rb_eNetcdfError, "No such object of the netCDF dimension class."); } } status = nc_def_var(ncid,c_var_name,xtype,c_ndims,c_dimids,&varidp); if(status != NC_NOERR) NC_RAISE(status); Netcdf_var = NetCDF_var_init(ncid,varidp,file); Var=Data_Wrap_Struct(cNetCDFVar,nc_mark_obj,NetCDF_var_free,Netcdf_var); return Var; } VALUE NetCDF_dim(VALUE file,VALUE dim_name) { int ncid; char *c_dim_name; int dimidp; int status; struct Netcdf *Netcdffile; struct NetCDFDim *Netcdf_dim; VALUE Dimension; Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid=Netcdffile->ncid; Check_Type(dim_name,T_STRING); c_dim_name=RSTRING_PTR(dim_name); status = nc_inq_dimid(ncid,c_dim_name,&dimidp); if(status !=NC_NOERR){ if(status == NC_EBADDIM){ return(Qnil); /*2003/08/27 back to orig (from changes on 2003/02/03)*/ } else{ NC_RAISE(status); } } Netcdf_dim=NetCDF_dim_init(ncid,dimidp); Dimension = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim); return Dimension; } VALUE NetCDF_var(VALUE file,VALUE var_name) { int ncid; int status; int varidp; char *c_var_name; struct Netcdf *Netcdffile; struct NetCDFVar *Netcdf_var; VALUE Variable; Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid=Netcdffile->ncid; Check_Type(var_name,T_STRING); c_var_name=RSTRING_PTR(var_name); status=nc_inq_varid(ncid,c_var_name,&varidp); if(status != NC_NOERR){ if(status == NC_ENOTVAR){ return(Qnil); /*2003/08/27 back to orig (from changes on 2003/02/03)*/ } else{ NC_RAISE(status); } } Netcdf_var = NetCDF_var_init(ncid,varidp,file); Variable = Data_Wrap_Struct(cNetCDFVar,nc_mark_obj,NetCDF_var_free,Netcdf_var); return Variable; } VALUE NetCDF_att(VALUE file,VALUE att_name) { int ncid; int status; int attnump; char *c_att_name; struct Netcdf *Netcdffile; struct NetCDFAtt *Netcdf_att; VALUE Attribute; Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid=Netcdffile->ncid; Check_Type(att_name,T_STRING); c_att_name=RSTRING_PTR(att_name); status = nc_inq_attid(ncid,NC_GLOBAL,c_att_name,&attnump); if(status != NC_NOERR){ if(status == NC_ENOTATT){ return(Qnil); } else{ NC_RAISE(status); } } Netcdf_att = NetCDF_att_init(ncid,NC_GLOBAL,c_att_name); Attribute = Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att); return Attribute; } VALUE NetCDF_fill(VALUE file,VALUE mode) { int ncid; int status; struct Netcdf *Netcdffile; int old_modep; Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid = Netcdffile->ncid; if(mode==Qfalse){ status = nc_set_fill(ncid,NC_NOFILL,&old_modep); if(status != NC_NOERR) NC_RAISE(status); } else if(mode == Qtrue){ status = nc_set_fill(ncid,NC_FILL,&old_modep); if(status != NC_NOERR) NC_RAISE(status); } else rb_raise(rb_eNetcdfError,"Usage:self.fill(true) or self.fill(false)"); return Qnil; } VALUE NetCDF_redef(VALUE file) { int ncid; int status; struct Netcdf *Netcdffile; rb_secure(3); Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid=Netcdffile->ncid; status = nc_redef(ncid); if(status !=NC_NOERR){ if(status == NC_EINDEFINE){ return Qnil; } else{ NC_RAISE(status); } } return Qtrue; } VALUE NetCDF_enddef(VALUE file) { int ncid; int status; struct Netcdf *Netcdffile; rb_secure(3); Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid=Netcdffile->ncid; status = nc_enddef(ncid); if(status !=NC_NOERR){ if(status == NC_ENOTINDEFINE){ return Qnil; } else{ NC_RAISE(status); } } return Qtrue; } VALUE NetCDF_whether_in_define_mode(VALUE file) { /* returns true if the NetCDF object is currently in the define mode, false if in the data mode, and nil if else (possibly the file is read-only, or some other error occurred) */ int ncid; int status; struct Netcdf *Netcdffile; rb_secure(3); Data_Get_Struct(file,struct Netcdf,Netcdffile); ncid=Netcdffile->ncid; status = nc_redef(ncid); if(status == NC_EINDEFINE){ return Qtrue; } else if(status == NC_NOERR) { /* was in the data mode --> recover the data mode and report false */ status = nc_enddef(ncid); if(status == NC_NOERR) { return Qfalse; } else { return Qnil; } } else { return Qnil; } } VALUE NetCDF_open(VALUE mod,VALUE filename,VALUE omode) { int status; int ncid; char* c_filename; int c_omode; struct Netcdf *ncfile; VALUE retval; Check_Type(filename,T_STRING); SafeStringValue(filename); c_filename=RSTRING_PTR(filename); Check_Type(omode,T_FIXNUM); c_omode=NUM2INT(omode); status = nc_open(c_filename,c_omode,&ncid); if(status !=NC_NOERR){NC_RAISE2(status,c_filename);} ncfile = NetCDF_init(ncid,c_filename); retval = Data_Wrap_Struct(cNetCDF,0,NetCDF_free,ncfile); return( retval ); } VALUE NetCDF_create(VALUE mod,VALUE filename,VALUE cmode) { int ncid; int status; char* c_filename; int c_cmode; struct Netcdf *ncfile; Check_Type(filename,T_STRING); SafeStringValue(filename); c_filename=RSTRING_PTR(filename); Check_Type(cmode,T_FIXNUM); c_cmode=NUM2INT(cmode); status = nc_create(c_filename,c_cmode,&ncid); if(status != NC_NOERR) NC_RAISE2(status, c_filename); ncfile = NetCDF_init(ncid,c_filename); return( Data_Wrap_Struct(cNetCDF,0,NetCDF_free,ncfile) ); } VALUE NetCDF_ndims(VALUE file) { int ncid; int ndimsp; VALUE Integer; int status; struct Netcdf *ncfile; Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; status = nc_inq_ndims(ncid,&ndimsp); if(status != NC_NOERR) NC_RAISE (status); Integer = INT2NUM(ndimsp); return Integer; } VALUE NetCDF_nvars(VALUE file) { int ncid; int nvarsp; int status; VALUE Integer; struct Netcdf *ncfile; Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; status = nc_inq_nvars(ncid,&nvarsp); if(status != NC_NOERR) NC_RAISE (status); Integer = INT2NUM(nvarsp); return Integer; } VALUE NetCDF_natts(VALUE file) { int ncid; int nattsp; int status; VALUE Integer; struct Netcdf *ncfile; Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; status=nc_inq_natts(ncid,&nattsp); if(status != NC_NOERR) NC_RAISE (status); Integer = INT2NUM(nattsp); return Integer; } VALUE NetCDF_unlimited(VALUE file) { int ncid; int unlimdimidp; int status; struct Netcdf *ncfile; struct NetCDFDim *Netcdf_dim; VALUE Dimension; Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; status=nc_inq_unlimdim(ncid,&unlimdimidp); if(status !=NC_NOERR) NC_RAISE(status); Netcdf_dim = NetCDF_dim_init(ncid,unlimdimidp); /* If unlimdimidp=-1,No unlimited dimension is defined in the netCDF dataset */ if(unlimdimidp != -1) { Dimension = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim); return Dimension; } else { return Qnil; } } #if NCVER >= 400 VALUE NetCDF_format(VALUE file) { int ncid; int formatp; int status; VALUE Integer; struct Netcdf *ncfile; Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; status=nc_inq_format(ncid,&formatp); if(status != NC_NOERR) NC_RAISE (status); Integer = INT2NUM(formatp); /* one of NC_FORMAT_CLASSIC (1), NC_FORMAT_64BIT (2), NC_FORMAT_NETCDF4 (3), NC_FORMAT_NETCDF4_CLASSIC (4) */ return Integer; } #endif VALUE NetCDF_sync(VALUE file) { int ncid; int status; struct Netcdf *ncfile; rb_secure(3); Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; status = nc_sync(ncid); if(status !=NC_NOERR) NC_RAISE (status); return Qnil; } VALUE NetCDF_path(VALUE file) { char *path; struct Netcdf *ncfile; Data_Get_Struct(file,struct Netcdf,ncfile); path=ncfile->name; return(rb_str_new2(path)); } VALUE NetCDF_dim_length(VALUE Dim) { int ncid; int status; int dimid; size_t lengthp; struct NetCDFDim *Netcdf_dim; Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim); ncid=Netcdf_dim->ncid; dimid=Netcdf_dim->dimid; status = nc_inq_dimlen(ncid,dimid,&lengthp); if(status != NC_NOERR) NC_RAISE(status); return(INT2NUM(lengthp)); } VALUE NetCDF_dim_name(VALUE Dim,VALUE dimension_newname) { int ncid; int status; int dimid; char *c_dim_name; struct NetCDFDim *Netcdf_dim; rb_secure(3); Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim); ncid=Netcdf_dim->ncid; dimid=Netcdf_dim->dimid; Check_Type(dimension_newname,T_STRING); c_dim_name = StringValueCStr(dimension_newname); status = nc_rename_dim(ncid,dimid,c_dim_name); if(status !=NC_NOERR) NC_RAISE(status); return Qnil; } VALUE NetCDF_dim_inqname(VALUE Dim) { int ncid; int status; int dimid; char c_dim_name[NC_MAX_NAME]; struct NetCDFDim *Netcdf_dim; VALUE str; Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim); ncid=Netcdf_dim->ncid; dimid=Netcdf_dim->dimid; status = nc_inq_dimname(ncid,dimid,c_dim_name); if(status !=NC_NOERR) NC_RAISE(status); str = rb_str_new2(c_dim_name); OBJ_TAINT(str); return(str); } VALUE NetCDF_dim_whether_unlimited(VALUE Dim) { int status; int uldid; struct NetCDFDim *Netcdf_dim; Data_Get_Struct(Dim,struct NetCDFDim,Netcdf_dim); status=nc_inq_unlimdim(Netcdf_dim->ncid,&uldid); if(status !=NC_NOERR) NC_RAISE(status); if(Netcdf_dim->dimid == uldid){ return(Qtrue); } else { return(Qfalse); } } VALUE NetCDF_att_inq_name(VALUE Att) { char *c_att_name; struct NetCDFAtt *Netcdf_att; VALUE str; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); c_att_name=Netcdf_att->name; str = rb_str_new2(c_att_name); OBJ_TAINT(str); return(str); } VALUE NetCDF_att_rename(VALUE Att,VALUE new_att_name) { int ncid; int status; int varid; char *c_att_name; char *c_new_att_name; struct NetCDFAtt *Netcdf_att; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid=Netcdf_att->ncid; varid=Netcdf_att->varid; c_att_name=Netcdf_att->name; Check_Type(new_att_name,T_STRING); SafeStringValue(new_att_name); c_new_att_name=StringValueCStr(new_att_name); status = nc_rename_att(ncid,varid,c_att_name,c_new_att_name); if(status != NC_NOERR) NC_RAISE(status); strcpy(Netcdf_att->name,c_new_att_name); return Qnil; } VALUE NetCDF_id2dim(VALUE file,VALUE dimid) { int ncid; int c_dimid; struct Netcdf *ncfile; struct NetCDFDim *Netcdf_dim; VALUE Dim; Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; Check_Type(dimid,T_FIXNUM); c_dimid=NUM2INT(dimid); Netcdf_dim = NetCDF_dim_init(ncid,c_dimid); Dim=Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim); return(Dim); } VALUE NetCDF_id2var(VALUE file,VALUE varid) { int ncid; int c_varid; struct Netcdf *ncfile; struct NetCDFVar *Netcdf_var; VALUE Var; Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; Check_Type(varid,T_FIXNUM); c_varid=NUM2INT(varid); Netcdf_var = NetCDF_var_init(ncid,c_varid,file); Var=Data_Wrap_Struct(cNetCDFVar,nc_mark_obj,NetCDF_var_free,Netcdf_var); return(Var); } VALUE NetCDF_id2att(VALUE file,VALUE attnum) { int ncid; int c_attnum; int status; struct Netcdf *ncfile; struct NetCDFAtt *Netcdf_att; char *c_att_name; VALUE Att; c_att_name=ALLOCA_N(char,NC_MAX_NAME); Data_Get_Struct(file,struct Netcdf,ncfile); ncid=ncfile->ncid; Check_Type(attnum,T_FIXNUM); c_attnum=NUM2INT(attnum); status = nc_inq_attname(ncid,NC_GLOBAL,c_attnum,c_att_name); if(status != NC_NOERR) NC_RAISE(status); Netcdf_att=NetCDF_att_init(ncid,NC_GLOBAL,c_att_name); Att=Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att); return(Att); } #if NCVER >= 400 /* USAGE NetCDFVar#deflate(deflate_level, shuffle=false) */ VALUE NetCDF_var_deflate(int argc, VALUE *argv, VALUE Var) { int ncid, varid, status; struct NetCDFVar *Netcdf_var; int shuffle; /* If non-zero, turn on the shuffle filter. http://www.unidata.ucar.edu/software/netcdf/papers/AMS_2008.pdf : The shuffle algorithm changes the byte order in the data stream; when used with integers that are all close together, this results in a better compression ratio. There is no benefit from using the shuffle filter without also using compression. MEMO by horinouchi: shuffling filter was also effective for float variables in some test (demo5-netcdf4.rb). */ int deflate_level; int deflate=1; /* Always set to non-zero: See https://www.unidata.ucar.edu/software/netcdf/docs/netcdf-c/nc_005fdef_005fvar_005fdeflate.html#nc_005fdef_005fvar_005fdeflate If non-zero, turn on the deflate filter at the level specified by the deflate_level parameter. */ if (argc>2 || argc<1) rb_raise(rb_eArgError, "wrong # of arguments (%d). It must be 1 or 2", argc); Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid = Netcdf_var->ncid; varid = Netcdf_var->varid; deflate_level = NUM2INT(argv[0]); if (argc==1) { shuffle = 0; /* default: false */ } else { if ( argv[1] == Qnil || argv[1] == Qfalse ) { shuffle = 0; } else { shuffle = 1; } } status = nc_def_var_deflate(ncid, varid, shuffle, deflate, deflate_level); if(status != NC_NOERR) NC_RAISE(status); return(Var); } VALUE NetCDF_var_deflate_params(VALUE Var) { int ncid, varid, status; struct NetCDFVar *Netcdf_var; int shufflep, deflatep, deflate_levelp; VALUE sh, df, params; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid = Netcdf_var->ncid; varid = Netcdf_var->varid; status = nc_inq_var_deflate(ncid, varid, &shufflep, &deflatep, &deflate_levelp); if(status != NC_NOERR) NC_RAISE(status); if (shufflep==0) {sh=Qfalse;} else {sh=Qtrue;} if (deflatep==0) {df=Qfalse;} else {df=Qtrue;} params = rb_ary_new3(3, sh, df, INT2NUM(deflate_levelp) ); return(params); } VALUE NetCDF_var_set_endian(VALUE Var, VALUE endian) { int ncid, varid, status; struct NetCDFVar *Netcdf_var; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid = Netcdf_var->ncid; varid = Netcdf_var->varid; status = nc_def_var_endian(ncid, varid, NUM2INT(endian)); if(status != NC_NOERR) NC_RAISE(status); return(Var); } VALUE NetCDF_var_endian(VALUE Var) { int ncid, varid, status; struct NetCDFVar *Netcdf_var; int endian; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid = Netcdf_var->ncid; varid = Netcdf_var->varid; status = nc_inq_var_endian(ncid, varid, &endian); if(status != NC_NOERR) NC_RAISE(status); return(INT2FIX(endian)); } #endif VALUE NetCDF_var_id2att(VALUE Var,VALUE attnum) { int ncid; int c_attnum; int status; int c_varid; struct NetCDFVar *Netcdf_var; struct NetCDFAtt *Netcdf_att; char *c_att_name; VALUE Att; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid=Netcdf_var->ncid; c_varid=Netcdf_var->varid; Check_Type(attnum,T_FIXNUM); c_attnum=NUM2INT(attnum); c_att_name=ALLOCA_N(char,NC_MAX_NAME); status = nc_inq_attname(ncid,c_varid,c_attnum,c_att_name); if(status != NC_NOERR) NC_RAISE(status); Netcdf_att=NetCDF_att_init(ncid,c_varid,c_att_name); Att=Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att); return(Att); } VALUE NetCDF_var_dims(VALUE Var) { int ncid, *dimids, ndims, varid, i, status; struct NetCDFVar *Netcdf_var; struct NetCDFDim *Netcdf_dim; VALUE Dims; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid = Netcdf_var->ncid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); dimids=ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Dims = rb_ary_new(); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); if(c_ith < 0 || c_ith >= ndims) { rb_raise(rb_eNetcdfError, "dimension count less than zero or greater than ndims-1"); } dimids=ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Netcdf_dim = NetCDF_dim_init(ncid,dimids[ndims-1-c_ith]); Dim = Data_Wrap_Struct(cNetCDFDim,0,NetCDF_dim_free,Netcdf_dim); return(Dim); } VALUE NetCDF_att_copy(VALUE Att,VALUE Var_or_File) { int ncid_in,ncid_out; int status; int varid_in,varid_out; char *att_name; struct NetCDFAtt *Netcdf_att; struct NetCDFVar *Netcdf_var; struct Netcdf *ncfile; struct NetCDFAtt *Netcdf_att_out; rb_secure(3); Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid_in=Netcdf_att->ncid; varid_in=Netcdf_att->varid; att_name=Netcdf_att->name; if( rb_obj_is_kind_of(Var_or_File, cNetCDFVar) ){ Data_Get_Struct(Var_or_File,struct NetCDFVar, Netcdf_var); ncid_out=Netcdf_var->ncid; varid_out=Netcdf_var->varid; } else if ( rb_obj_is_kind_of(Var_or_File, cNetCDF) ){ Data_Get_Struct(Var_or_File,struct Netcdf, ncfile); ncid_out=ncfile->ncid; varid_out=NC_GLOBAL; } else { rb_raise(rb_eNetcdfError,"The argument must be a NetCDFVar or a NetCDF"); } status = nc_copy_att(ncid_in,varid_in,att_name,ncid_out,varid_out); if(status != NC_NOERR) NC_RAISE(status); Netcdf_att_out = NetCDF_att_init(ncid_out,varid_out,att_name); return (Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att_out)); } VALUE NetCDF_att_atttype(VALUE Att) { int ncid; int varid; int status; char *att_name; const char *Attname; struct NetCDFAtt *Netcdf_att; nc_type xtypep; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid = Netcdf_att->ncid; varid = Netcdf_att->varid; att_name = Netcdf_att->name; status = nc_inq_atttype(ncid,varid,att_name,&xtypep); if(status != NC_NOERR) NC_RAISE(status); Attname = nctype2natype(xtypep); return(rb_str_new2(Attname)); } VALUE NetCDF_att_typecode(VALUE Att) { int ncid; int varid; int status; char *att_name; struct NetCDFAtt *Netcdf_att; nc_type xtypep; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid = Netcdf_att->ncid; varid = Netcdf_att->varid; att_name = Netcdf_att->name; status = nc_inq_atttype(ncid,varid,att_name,&xtypep); if(status != NC_NOERR) NC_RAISE(status); return(INT2NUM(nctype2natypecode(xtypep))); } VALUE NetCDF_att_delete(VALUE Att) { int ncid; int status; int varid; char *c_att_name; struct NetCDFAtt *Netcdf_att; rb_secure(3); Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid=Netcdf_att->ncid; varid=Netcdf_att->varid; c_att_name=Netcdf_att->name; status = nc_del_att(ncid,varid,c_att_name); if(status != NC_NOERR) NC_RAISE(status); return Qnil; } VALUE NetCDF_att_put(VALUE Att,VALUE value,VALUE atttype) /* * atttype: nil or a String ("string","int",etc). If nil, * the type of attribute is determined from the type of value */ { struct NetCDFAtt *ncatt; rb_secure(3); Data_Get_Struct(Att,struct NetCDFAtt,ncatt); return( NetCDF_put_att__(ncatt->ncid, ncatt->name, value, atttype, ncatt->varid) ); } VALUE NetCDF_att_get(VALUE Att) { int ncid; int varid; char *c_attname; int status; struct NetCDFAtt *Netcdf_att; nc_type xtypep; size_t lenp; na_shape_t attlen[1]; /* NArray uses int instead of size_t */ char *tp; unsigned char *up; short *sp; int *ip; float *fp; double *dp; VALUE NArray; VALUE str; Data_Get_Struct(Att,struct NetCDFAtt,Netcdf_att); ncid = Netcdf_att->ncid; varid = Netcdf_att->varid; c_attname = Netcdf_att->name; status = nc_inq_atttype(ncid,varid,c_attname,&xtypep); if(status != NC_NOERR) NC_RAISE(status); switch(xtypep){ case NC_CHAR: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); tp = ALLOCA_N(char,lenp+1); tp[lenp]= '\0'; status = nc_get_att_text(ncid,varid,c_attname,tp); if(status != NC_NOERR) NC_RAISE(status); str = rb_str_new2(tp); OBJ_TAINT(str); return(str); break; case NC_BYTE: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Cbyte_to_NArray(NArray,1,attlen,up); status = nc_get_att_uchar(ncid,varid,c_attname,up); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; case NC_SHORT: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Csint_to_NArray(NArray,1,attlen,sp); status = nc_get_att_short(ncid,varid,c_attname,sp); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; case NC_INT: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Clint_to_NArray(NArray,1,attlen,ip); status = nc_get_att_int(ncid,varid,c_attname,ip); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; case NC_FLOAT: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Cfloat_to_NArray(NArray,1,attlen,fp); status = nc_get_att_float(ncid,varid,c_attname,fp); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; case NC_DOUBLE: status = nc_inq_attlen(ncid,varid,c_attname,&lenp); if(status != NC_NOERR) NC_RAISE(status); attlen[0]=lenp; Cdouble_to_NArray(NArray,1,attlen,dp); status = nc_get_att_double(ncid,varid,c_attname,dp); if(status != NC_NOERR) NC_RAISE(status); OBJ_TAINT(NArray); return NArray; break; default: rb_raise(rb_eNetcdfError,"atttype isn't supported in netCDF"); } return Qnil; } VALUE NetCDF_var_inq_name(VALUE Var) { int ncid; int status; int varid; char c_var_name[NC_MAX_NAME]; struct NetCDFVar *Netcdf_var; VALUE Var_name; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid=Netcdf_var->ncid; varid=Netcdf_var->varid; status = nc_inq_varname(ncid,varid,c_var_name); if(status != NC_NOERR) NC_RAISE(status); Var_name=rb_str_new2(c_var_name); OBJ_TAINT(Var_name); return Var_name; } VALUE NetCDF_var_ndims(VALUE Var) { int ncid; int status; int varid; int ndimsp; struct NetCDFVar *Netcdf_var; VALUE Var_ndims; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid=Netcdf_var->ncid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); Var_ndims=INT2FIX(ndimsp); return Var_ndims; } VALUE NetCDF_var_vartype(VALUE Var) { int ncid; int status; int varid; nc_type xtypep; struct NetCDFVar *Netcdf_var; const char *Vartype; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid=Netcdf_var->ncid; varid=Netcdf_var->varid; status = nc_inq_vartype(ncid,varid,&xtypep); if(status != NC_NOERR) NC_RAISE(status); Vartype=nctype2natype(xtypep); return(rb_str_new2(Vartype)); } VALUE NetCDF_var_typecode(VALUE Var) { int ncid; int status; int varid; nc_type xtypep; struct NetCDFVar *Netcdf_var; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid=Netcdf_var->ncid; varid=Netcdf_var->varid; status = nc_inq_vartype(ncid,varid,&xtypep); if(status != NC_NOERR) NC_RAISE(status); return(INT2NUM(nctype2natypecode(xtypep))); } VALUE NetCDF_var_natts(VALUE Var) { int ncid; int status; int varid; int nattsp; struct NetCDFVar *Netcdf_var; VALUE Var_natts; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid=Netcdf_var->ncid; varid=Netcdf_var->varid; status= nc_inq_varnatts(ncid,varid,&nattsp); if(status !=NC_NOERR) NC_RAISE(status); Var_natts=INT2FIX(nattsp); return Var_natts; } VALUE NetCDF_var_file(VALUE Var) { struct NetCDFVar *Netcdf_var; /* VALUE file; */ Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); return (Netcdf_var->file); } VALUE NetCDF_var_rename(VALUE Var,VALUE var_new_name) { int ncid; int status; int varid; char *c_var_new_name; struct NetCDFVar *Netcdf_var; rb_secure(3); Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid=Netcdf_var->ncid; varid=Netcdf_var->varid; Check_Type(var_new_name,T_STRING); c_var_new_name=StringValueCStr(var_new_name); status = nc_rename_var(ncid,varid,c_var_new_name); if(status !=NC_NOERR) NC_RAISE(status); return Qnil; } VALUE NetCDF_var_att(VALUE Var,VALUE att_name) { int ncid; int status; int varid; char *c_att_name; int c_attnump; struct NetCDFVar *Netcdf_var; struct NetCDFAtt *Netcdf_att; VALUE Att; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid=Netcdf_var->ncid; varid=Netcdf_var->varid; Check_Type(att_name,T_STRING); c_att_name=StringValueCStr(att_name); status = nc_inq_attid(ncid,varid,c_att_name,&c_attnump); if(status == NC_NOERR){ Netcdf_att=NetCDF_att_init(ncid,varid,c_att_name); Att=Data_Wrap_Struct(cNetCDFAtt,0,Netcdf_att_free,Netcdf_att); return Att; } else if(status == NC_ENOTATT){ return Qnil; } else{ NC_RAISE(status); return Qnil; } } /* Redifinition of the "==" and "eql?" methods */ VALUE NetCDF_eql(VALUE filea,VALUE fileb) { struct Netcdf *ncfilea; struct Netcdf *ncfileb; if( rb_obj_is_kind_of(fileb, cNetCDF) ){ Data_Get_Struct(filea,struct Netcdf,ncfilea); Data_Get_Struct(fileb,struct Netcdf,ncfileb); if(ncfilea->ncid == ncfileb->ncid && strcmp(ncfilea->name,ncfileb->name)==0){ return Qtrue; } else { return Qfalse; } } else { return Qfalse; } } VALUE NetCDF_var_eql(VALUE Vara,VALUE Varb) { struct NetCDFVar *Netcdf_vara; struct NetCDFVar *Netcdf_varb; if( rb_obj_is_kind_of(Varb, cNetCDFVar) ){ Data_Get_Struct(Vara,struct NetCDFVar,Netcdf_vara); Data_Get_Struct(Varb,struct NetCDFVar,Netcdf_varb); if(Netcdf_vara->ncid == Netcdf_varb->ncid && Netcdf_vara->varid == Netcdf_varb->varid){ return Qtrue; } else { return Qfalse; } } else { return Qfalse; } } VALUE NetCDF_dim_eql(VALUE Dima,VALUE Dimb) { struct NetCDFDim *Netcdf_dima; struct NetCDFDim *Netcdf_dimb; if( rb_obj_is_kind_of(Dimb, cNetCDFDim) ){ Data_Get_Struct(Dima,struct NetCDFDim,Netcdf_dima); Data_Get_Struct(Dimb,struct NetCDFDim,Netcdf_dimb); if(Netcdf_dima->ncid == Netcdf_dimb->ncid && Netcdf_dima->dimid == Netcdf_dimb->dimid){ return Qtrue; } else { return Qfalse; } } else { return Qfalse; } } VALUE NetCDF_att_eql(VALUE Atta,VALUE Attb) { struct NetCDFAtt *Netcdf_atta; struct NetCDFAtt *Netcdf_attb; if( rb_obj_is_kind_of(Attb, cNetCDFAtt) ){ Data_Get_Struct(Atta,struct NetCDFAtt,Netcdf_atta); Data_Get_Struct(Attb,struct NetCDFAtt,Netcdf_attb); if(Netcdf_atta->ncid == Netcdf_atta->ncid && Netcdf_atta->varid == Netcdf_attb->varid && strcmp(Netcdf_atta->name,Netcdf_attb->name)==0){ return Qtrue; } else { return Qfalse; } } else { return Qfalse; } } /* Follow methods is to connect "NArray" with "Netcdf" */ VALUE NetCDF_get_var_char(VALUE Var) { int ncid; int varid; int status; unsigned char *ptr; struct NetCDFVar *Netcdf_var; int i=0; int ndimsp; int *dimids; size_t lengthp; na_shape_t *shape; /* NArray uses int instead of size_t */ VALUE NArray; Data_Get_Struct(Var,struct NetCDFVar,Netcdf_var); ncid = Netcdf_var->ncid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndimsp); if (ndimsp != 0){ shape = ALLOCA_N(na_shape_t,ndimsp); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndimsp); if (ndimsp != 0){ shape = ALLOCA_N(na_shape_t,ndimsp); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndimsp); if (ndimsp != 0){ shape = ALLOCA_N(na_shape_t,ndimsp); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndimsp); if (ndimsp != 0){ shape = ALLOCA_N(na_shape_t,ndimsp); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndimsp); if (ndimsp != 0){ shape = ALLOCA_N(na_shape_t,ndimsp); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndimsp); if (ndimsp != 0){ shape = ALLOCA_N(na_shape_t,ndimsp); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR)NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); c_count=ALLOCA_N(na_shape_t,ndims); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR)NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); c_count=ALLOCA_N(na_shape_t,ndims); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR) NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); c_count=ALLOCA_N(na_shape_t,ndims); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR)NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); c_count=ALLOCA_N(na_shape_t,ndims); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR)NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); c_count=ALLOCA_N(na_shape_t,ndims); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR)NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError,"Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); c_count=ALLOCA_N(na_shape_t,ndims); for(i=0;incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims){ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start = ALLOCA_N(size_t,ndims); for(i=0; incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims){ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start = ALLOCA_N(size_t,ndims); for(i=0; incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims){ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start = ALLOCA_N(size_t,ndims); for(i=0; incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims){ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start = ALLOCA_N(size_t,ndims); for(i=0; incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims){ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start = ALLOCA_N(size_t,ndims); for(i=0; incid; varid = Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); if(ndims == 0) { rb_raise(rb_eNetcdfError,"Cannot specify a subset of a rank-0 scalar\n"); } dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims){ rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start = ALLOCA_N(size_t,ndims); for(i=0; incid; varid=Netcdf_var->varid; Array_to_Cbyte_len(NArray,ptr,len); status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); for(i=0;incid; varid=Netcdf_var->varid; Array_to_Cbyte_len(NArray,ptr,len); status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); for(i=0;incid; varid=Netcdf_var->varid; Array_to_Csint_len(NArray,ptr,len); status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); for(i=0;incid; varid=Netcdf_var->varid; Array_to_Clint_len(NArray,ptr,len); status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); for(i=0;incid; varid=Netcdf_var->varid; Array_to_Cfloat_len(NArray,ptr,len); status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); for(i=0;incid; varid=Netcdf_var->varid; Array_to_Cdouble_len(NArray,ptr,len); status = nc_inq_varndims(ncid,varid,&ndimsp); if(status != NC_NOERR) NC_RAISE(status); for(i=0;incid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) ncid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) ncid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) ncid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) ncid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) ncid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid,varid,&ndims); if(status != NC_NOERR) NC_RAISE(status); dimids = ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid,varid,dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) ncid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR) NC_RAISE(status); dimids=ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid, varid, dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); for(i=0; incid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR) NC_RAISE(status); dimids=ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid, varid, dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); for(i=0; incid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR) NC_RAISE(status); dimids=ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid, varid, dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); for(i=0; incid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR) NC_RAISE(status); dimids=ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid, varid, dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); for(i=0; incid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR) NC_RAISE(status); dimids=ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid, varid, dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); for(i=0; incid; varid=Netcdf_var->varid; status = nc_inq_varndims(ncid, varid, &ndims); if(status != NC_NOERR) NC_RAISE(status); dimids=ALLOCA_N(int,ndims); status = nc_inq_vardimid(ncid, varid, dimids); if(status != NC_NOERR) NC_RAISE(status); Check_Type(start,T_ARRAY); if(RARRAY_LEN(start) < ndims) { rb_raise(rb_eNetcdfError, "Length of 'start' is too short\n"); } c_start=ALLOCA_N(size_t,ndims); for(i=0; i= 400 rb_define_const(cNetCDF, "NC_64BIT_OFFSET", INT2FIX(NC_64BIT_OFFSET)); /* NC_64BIT_OFFSET supports large files in the class data format */ rb_define_const(cNetCDF, "NC_NETCDF4", INT2FIX(NC_NETCDF4)); rb_define_const(cNetCDF, "NC_CLASSIC_MODEL", INT2FIX(NC_CLASSIC_MODEL)); /* for use as ( NC_NETCDF4 | NC_CLASSIC_MODEL ) to ensure the classic data model in NetCDF4 by disabling new features like groups */ rb_define_const(cNetCDF, "NC_ENDIAN_NATIVE", INT2FIX(NC_ENDIAN_NATIVE)); rb_define_const(cNetCDF, "NC_ENDIAN_LITTLE", INT2FIX(NC_ENDIAN_LITTLE)); rb_define_const(cNetCDF, "NC_ENDIAN_BIG", INT2FIX(NC_ENDIAN_BIG)); rb_define_const(cNetCDF, "NC_FORMAT_CLASSIC", INT2FIX(NC_FORMAT_CLASSIC)); rb_define_const(cNetCDF, "NC_FORMAT_64BIT", INT2FIX(NC_FORMAT_64BIT)); rb_define_const(cNetCDF, "NC_FORMAT_NETCDF4", INT2FIX(NC_FORMAT_NETCDF4)); rb_define_const(cNetCDF, "NC_FORMAT_NETCDF4_CLASSIC", INT2FIX(NC_FORMAT_NETCDF4_CLASSIC)); #endif #ifdef NARRAY_BIGMEM rb_define_const(cNetCDF, "SUPPORT_BIGMEM", Qtrue); #else rb_define_const(cNetCDF, "SUPPORT_BIGMEM", Qfalse); #endif /* Difinitions of the ruby methods */ /* The methods of the NetCDF class */ rb_define_singleton_method(cNetCDF,"libvers",NetCDF_inq_libvers,0); rb_define_singleton_method(cNetCDF,"nc_open",NetCDF_open,2); rb_define_method(cNetCDF,"clone",NetCDF_clone,0); rb_define_method(cNetCDF,"close",NetCDF_close,0); /* rb_define_singleton_method(cNetCDF,"new",NetCDF_open,2); */ rb_define_singleton_method(cNetCDF,"nc_create",NetCDF_create,2); rb_define_method(cNetCDF,"def_dim",NetCDF_def_dim,2); rb_define_method(cNetCDF,"def_var",NetCDF_def_var,3); rb_define_method(cNetCDF,"put_attraw",NetCDF_put_att,3); rb_define_method(cNetCDF,"redef",NetCDF_redef,0); rb_define_method(cNetCDF,"enddef",NetCDF_enddef,0); rb_define_method(cNetCDF,"define_mode?",NetCDF_whether_in_define_mode,0); rb_define_method(cNetCDF,"fill",NetCDF_fill,1); rb_define_method(cNetCDF,"ndims",NetCDF_ndims,0); rb_define_method(cNetCDF,"nvars",NetCDF_nvars,0); rb_define_method(cNetCDF,"natts",NetCDF_natts,0); #if NCVER >= 400 rb_define_method(cNetCDF,"format",NetCDF_format,0); #endif rb_define_method(cNetCDF,"sync",NetCDF_sync,0); rb_define_method(cNetCDF,"path",NetCDF_path,0); rb_define_method(cNetCDF,"dim",NetCDF_dim,1); rb_define_method(cNetCDF,"var",NetCDF_var,1); rb_define_method(cNetCDF,"att",NetCDF_att,1); rb_define_method(cNetCDF,"unlimited",NetCDF_unlimited,0); rb_define_private_method(cNetCDF,"id2var",NetCDF_id2var,1); rb_define_private_method(cNetCDF,"id2dim",NetCDF_id2dim,1); rb_define_private_method(cNetCDF,"id2att",NetCDF_id2att,1); rb_define_method(cNetCDF,"==",NetCDF_eql,1); /* rb_define_method(cNetCDF,"eql?",NetCDF_eql,1); */ /* The methods of the NetCDFDim class */ rb_define_method(cNetCDFDim,"clone",NetCDF_dim_clone,0); rb_define_method(cNetCDFDim,"length",NetCDF_dim_length,0); rb_define_method(cNetCDFDim,"name=",NetCDF_dim_name,1); rb_define_method(cNetCDFDim,"name",NetCDF_dim_inqname,0); rb_define_method(cNetCDFDim,"unlimited?",NetCDF_dim_whether_unlimited,0); rb_define_method(cNetCDFDim,"==",NetCDF_dim_eql,1); /* rb_define_method(cNetCDFDim,"eql?",NetCDF_dim_eql,1); */ /* The methods of the NetCDFAtt class */ rb_define_method(cNetCDFAtt,"clone",NetCDF_att_clone,0); rb_define_method(cNetCDFAtt,"name",NetCDF_att_inq_name,0); rb_define_method(cNetCDFAtt,"name=",NetCDF_att_rename,1); rb_define_method(cNetCDFAtt,"delete",NetCDF_att_delete,0); rb_define_method(cNetCDFAtt,"copy",NetCDF_att_copy,1); rb_define_method(cNetCDFAtt,"atttype",NetCDF_att_atttype,0); rb_define_method(cNetCDFAtt,"typecode",NetCDF_att_typecode,0); rb_define_method(cNetCDFAtt,"==",NetCDF_att_eql,1); /* rb_define_method(cNetCDFAtt,"eql?",NetCDF_att_eql,1); */ rb_define_method(cNetCDFAtt,"putraw",NetCDF_att_put,2); rb_define_method(cNetCDFAtt,"get",NetCDF_att_get,0); /* The methods of the NetCDFVar class */ #if NCVER >= 400 rb_define_method(cNetCDFVar,"deflate",NetCDF_var_deflate,-1); rb_define_method(cNetCDFVar,"deflate_params",NetCDF_var_deflate_params,0); rb_define_method(cNetCDFVar,"endian=",NetCDF_var_set_endian,1); rb_define_method(cNetCDFVar,"endian",NetCDF_var_endian,0); #endif rb_define_method(cNetCDFVar,"clone",NetCDF_var_clone,0); rb_define_method(cNetCDFVar,"name",NetCDF_var_inq_name,0); rb_define_method(cNetCDFVar,"ndims",NetCDF_var_ndims,0); rb_define_method(cNetCDFVar,"vartype",NetCDF_var_vartype,0); rb_define_method(cNetCDFVar,"typecode",NetCDF_var_typecode,0); rb_define_method(cNetCDFVar,"ntype",NetCDF_var_vartype,0); rb_define_method(cNetCDFVar,"natts",NetCDF_var_natts,0); rb_define_method(cNetCDFVar,"file",NetCDF_var_file,0); rb_define_method(cNetCDFVar,"name=",NetCDF_var_rename,1); rb_define_method(cNetCDFVar,"att",NetCDF_var_att,1); rb_define_method(cNetCDFVar,"put_attraw",NetCDF_put_att_var,3); rb_define_method(cNetCDFVar,"dims",NetCDF_var_dims,0); rb_define_method(cNetCDFVar,"dim",NetCDF_var_dim,1); /*rb_define_private_method(cNetCDFVar,"id2dim",NetCDF_var_id2dim,1); */ rb_define_private_method(cNetCDFVar,"id2att",NetCDF_var_id2att,1); rb_define_method(cNetCDFVar,"==",NetCDF_var_eql,1); /* rb_define_method(cNetCDFVar,"eql?",NetCDF_var_eql,1); */ /* The "get*" or "put*" methods in the NetCDFVar class */ rb_define_method(cNetCDFVar,"put_var_char",NetCDF_put_var_char,1); rb_define_method(cNetCDFVar,"put_var_byte",NetCDF_put_var_byte,1); rb_define_method(cNetCDFVar,"put_var_sint",NetCDF_put_var_short,1); rb_define_method(cNetCDFVar,"put_var_int",NetCDF_put_var_int,1); rb_define_method(cNetCDFVar,"put_var_sfloat",NetCDF_put_var_float,1); rb_define_method(cNetCDFVar,"put_var_float",NetCDF_put_var_double,1); rb_define_method(cNetCDFVar,"put_vars_char",NetCDF_put_vars_char,4); rb_define_method(cNetCDFVar,"put_vars_byte",NetCDF_put_vars_byte,4); rb_define_method(cNetCDFVar,"put_vars_sint",NetCDF_put_vars_sint,4); rb_define_method(cNetCDFVar,"put_vars_int",NetCDF_put_vars_int,4); rb_define_method(cNetCDFVar,"put_vars_sfloat",NetCDF_put_vars_float,4); rb_define_method(cNetCDFVar,"put_vars_float",NetCDF_put_vars_double,4); rb_define_method(cNetCDFVar,"put_var1_char",NetCDF_put_var1_char,2); rb_define_method(cNetCDFVar,"put_var1_byte",NetCDF_put_var1_byte,2); rb_define_method(cNetCDFVar,"put_var1_sint",NetCDF_put_var1_sint,2); rb_define_method(cNetCDFVar,"put_var1_int",NetCDF_put_var1_int,2); rb_define_method(cNetCDFVar,"put_var1_sfloat",NetCDF_put_var1_float,2); rb_define_method(cNetCDFVar,"put_var1_float",NetCDF_put_var1_double,2); rb_define_method(cNetCDFVar,"get_var_char",NetCDF_get_var_char,0); rb_define_method(cNetCDFVar,"get_var_byte",NetCDF_get_var_byte,0); rb_define_method(cNetCDFVar,"get_var_sint",NetCDF_get_var_sint,0); rb_define_method(cNetCDFVar,"get_var_int",NetCDF_get_var_int,0); rb_define_method(cNetCDFVar,"get_var_sfloat",NetCDF_get_var_float,0); rb_define_method(cNetCDFVar,"get_var_float",NetCDF_get_var_double,0); rb_define_method(cNetCDFVar,"get_vars_char",NetCDF_get_vars_char,3); rb_define_method(cNetCDFVar,"get_vars_byte",NetCDF_get_vars_byte,3); rb_define_method(cNetCDFVar,"get_vars_sint",NetCDF_get_vars_sint,3); rb_define_method(cNetCDFVar,"get_vars_int",NetCDF_get_vars_int,3); rb_define_method(cNetCDFVar,"get_vars_sfloat",NetCDF_get_vars_float,3); rb_define_method(cNetCDFVar,"get_vars_float",NetCDF_get_vars_double,3); rb_define_method(cNetCDFVar,"get_var1_char",NetCDF_get_var1_char,1); rb_define_method(cNetCDFVar,"get_var1_byte",NetCDF_get_var1_byte,1); rb_define_method(cNetCDFVar,"get_var1_sint",NetCDF_get_var1_sint,1); rb_define_method(cNetCDFVar,"get_var1_int",NetCDF_get_var1_int,1); rb_define_method(cNetCDFVar,"get_var1_sfloat",NetCDF_get_var1_float,1); rb_define_method(cNetCDFVar,"get_var1_float",NetCDF_get_var1_double,1); } ruby-netcdf-0.7.2/Gemfile0000644000175000017500000000014012772251340015067 0ustar uwabamiuwabamisource 'https://rubygems.org' # Specify your gem's dependencies in ruby-netcdf.gemspec gemspec ruby-netcdf-0.7.2/demo/0000755000175000017500000000000012772251340014525 5ustar uwabamiuwabamiruby-netcdf-0.7.2/demo/README0000644000175000017500000000113312772251340015403 0ustar uwabamiuwabami * demo1-create.rb a basic test of file creation. creates a file and prints its contents. * demo1-create-alt.rb an alternative way to write demo1-create.rb * demo2-graphic.rb creates a file and close it. Then reopens and visualize it using AdvancedDCL (AdvancedDCL at http://www.gfd-dennou.org/arch/ruby/ must have been installed) * demo3-ncepclim.rb plots arbitrary 2D slices the 4D distribution of global temperature climatology from the NCEP reanalysis data. The data (8MB) is downloaded by anonymous ftp if not found in the user's run-time directory and he or she wants it. ruby-netcdf-0.7.2/demo/demo5-netcdf4.rb0000644000175000017500000000206512772251340017413 0ustar uwabamiuwabamirequire "numru/netcdf" include NumRu file3 = NetCDF.create("test_nc3.nc") NetCDF.creation_format = ( NetCDF::NC_NETCDF4 | NetCDF::NC_CLASSIC_MODEL ) file4 = NetCDF.create("test_nc4.nc") nx, ny = 100, 50 [ file3, file4 ].each do |file| xdim = file.def_dim("x",nx) ydim = file.def_dim("y",ny) x = file.def_var("x","sfloat",[xdim]) y = file.def_var("y","sfloat",[ydim]) v1 = file.def_var("v1","sfloat",[xdim,ydim]) v2 = file.def_var("v2","int",[xdim,ydim]) if /nc4/ =~ file.path v1.deflate(2) # set the deflation (compression) level 2 v2.deflate(2,true) # set the deflation level 2 with the shuffle filter puts "v1 deflate params:" p v1.deflate_params puts "v2 deflate params:" p v2.deflate_params end file.enddef x.put( NArray.float(nx).indgen! ) y.put( NArray.float(ny).indgen! ) z = NArray.float(nx,ny).indgen! + 1000000 z[true,ny/2..-1] = 0 # to see the impac v1.put(z) v2.put(z) file.close end puts "Created test_nc3.nc test_nc4.nc.", "File size comparison:" print `ls -l test_nc3.nc test_nc4.nc` ruby-netcdf-0.7.2/demo/demo1-create.rb0000644000175000017500000000164412772251340017325 0ustar uwabamiuwabamirequire "numru/netcdf" include NumRu file = NetCDF.create("test.nc") nx, ny = 10, 5 xdim = file.def_dim("x",nx) ydim = file.def_dim("y",ny) tdim = file.def_dim("t",0) require "date" file.put_att("history","created by #{$0} #{Date.today}") x = file.def_var("x","sfloat",[xdim]) y = file.def_var("y","sfloat",[ydim]) t = file.def_var("t","sfloat",[tdim]) v1 = file.def_var("v1","sfloat",[xdim,ydim]) v1.put_att("long_name","test 1") v1.put_att("units","1") v2 = file.def_var("v2","sfloat",[xdim,ydim,tdim]) v2.put_att("long_name","test 2") v2.put_att("units","1") file.enddef x.put( NArray.float(nx).indgen! ) y.put( NArray.float(ny).indgen! ) z = NArray.float(nx,ny).indgen!*0.1 v1.put(z) v1.put( NArray.float(nx).add!(20), "start"=>[0,2],"end"=>[-1,2]) v2.put(z, "start"=>[0,0,0],"end"=>[-1,-1,0]) t.put( 0, "index"=>[0]) v2.put(-z, "start"=>[0,0,1],"end"=>[-1,-1,1]) t.put( 1, "index"=>[1]) file.close print `ncdump test.nc` ruby-netcdf-0.7.2/demo/demo4-copy.rb0000644000175000017500000000130012772251340017024 0ustar uwabamiuwabami=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 ruby-netcdf-0.7.2/demo/demo2-graphic.rb0000644000175000017500000000241512772251340017475 0ustar uwabamiuwabamirequire "numru/dcl" require "numru/netcdf" include NumRu include NMath ## < create a sample netcdf file > def write_file file = NetCDF.create("test.nc") nx, ny = 21, 21 xdim = file.def_dim("x",nx) ydim = file.def_dim("y",ny) x = file.def_var("x","sfloat",["x"]) y = file.def_var("y","sfloat",["y"]) var = file.def_var("var","float",["x","y"]) var.put_att("long_name","test variable") file.enddef vx = NArray.float(nx).indgen! * (2*(Math::PI)*1.5/(nx-1)) vy = NArray.float(ny).indgen! * (2*(Math::PI)*1.0/(ny-1)) x.put( vx ) y.put( vy ) sx = sin( vx ) sy = sin( vy ) z = NArray.float(nx,ny) for j in 0..ny-1 z[true,j] = sx * sy[j] + 0.00001 end var.put(z) file.close print `ncdump -h test.nc` end ## < read the file and plot > def draw_graph file = NetCDF.open("test.nc") vx = file.var("x") vy = file.var("y") vz = file.var("var") x = vx.get y = vy.get z = vz.get file.close #DCL.swlset('ldump',1) DCL.gropn(1) DCL.grfrm DCL.usspnt(x, y) DCL.uspfit DCL.usdaxs DCL.sglset("lsoftf",false) DCL.uegtlb(z, -20) # set the number of levels DCL.uelset("ltone",true) DCL.uetone(z) DCL.udcntz(z) DCL.grcls end ###(main)### write_file draw_graph ###(main)### ruby-netcdf-0.7.2/demo/demo3-ncepclim.rb0000644000175000017500000001042612772251340017654 0ustar uwabamiuwabami# Plot global climatological temperature distribution # from the NCEP reanalysis data. # The data is downloaded if not found and the users wants. ###################################### ### local functions ### def nearest_index(na,val) # returns the element of na nearest to val # na is assumed to be 1d and monotonic if(na[0] > na[-1]) then reversed = true na = na[-1..0] else reversed = false end w = (na.lt(val)).where idx = [ (w.length==0 ? 0 : w.max), na.length-2 ].min if ( na[idx+1]-val < val-na[idx] ) then idx = idx+1 end if reversed then na = na[-1..0] idx = na.length-1-idx end idx end ##################################### ### main part ### require "numru/dcl" require "numru/netcdf" include NumRu filename = "air.mon.ltm.nc" # < download if not found and the users wants > if !(Dir.glob(filename)[0]) then # file not found ==> download by ftp if the user wants host = "ftp.cdc.noaa.gov" path = "/Datasets/ncep.reanalysis.derived/pressure/"+filename print "\n*** question ***\n", " File "+filename+" is not in the current directory.\n", " Would you like to download (ftp) it from "+host+"?\n", " (y, n)> " ans = gets if ans =~ /^y/ then print " What is your email address? (needed for anonymous ftp) > " email = gets.chop! require "net/ftp" print " connecting...\n" ftp = Net::FTP.open(host, "anonymous", email, nil) size = ftp.size(path) print " Size of the file is #{(size/1000)} kb. Would you really like to download?\n (y, n)> " ans = gets if ans =~ /^y/ then print " now downloading...\n" ftp.getbinaryfile(path, filename) else print " exit\n" exit end else print " exit\n" exit end end # < open the file and read axes > file = NetCDF.open(filename) var = file.var("air") # temperature lon = file.var("lon") lat = file.var("lat") level = file.var("level") time = file.var("time") # in hours t = (time.get/720).round + 1 # --> in months axes = [ lon, lat, level, time ] axvals = [ lon.get, lat.get, level.get, t ] axunits = [ lon.att("units").get.gsub("_",""), lat.att("units").get.gsub("_",""), level.att("units").get.gsub("_",""), "months" ] # < graphics > #DCL.sglset('lbuff',false) DCL.swlset('lwait',false) DCL.gropn(1) first = true while true do begin ## / select a 2D slice / if (first) then print <<-EOS ** select a slice ** List desired grid numbers of lonigutede, latitude, level, time (set only two of them) Example: , , 850, 1 -- horizontal slice at 850hPa and January 135, , , 2 -- vertical slice at 135E and Feburary EOS DCL.grfrm else DCL.grfrm print "Input next slice (C-d to quit)\n" end print "> " slice = gets.chop!.split(",") if slice.length!=4 then raise("Slice must be 4 comma-split numerics") end slice.collect!{|e| # "collect!" replaces elements if e =~ /^ *$/ then nil else e.to_f end } iax = [] start=[] ; last=[] slice.each_index{|i| if slice[i] == nil then iax.push(i) start.push(0) ; last.push(-1) # from the beginning to the end else idx = nearest_index( axvals[i], slice[i] ) start.push( idx ) ; last.push( idx ) end } if iax.length != 2 then raise("Specify a 2D slice") else x = axvals[iax[0]] iax[0]==2 ? xr=[x.max, x.min] : xr=[x.min, x.max] xttl = axes[iax[0]].att("long_name").get xunits = axunits[iax[0]] y = axvals[iax[1]] iax[1]==2 ? yr=[y.max, y.min] : yr=[y.min, y.max] yttl = axes[iax[1]].att("long_name").get yunits = axunits[iax[1]] end ## / read the slice and plot / v = var.get("start"=>start, "end"=>last) shp=v.shape; shp.delete(1); v.reshape!(*shp) # delete dims of length==1 #Fig.inclpoint(x, y) DCL.grswnd( xr[0], xr[1], yr[0], yr[1] ) DCL.grsvpt(0.2,0.9,0.2,0.9) DCL.grstrf DCL.ussttl(xttl," ",yttl," ") DCL.usdaxs DCL.uwsgxa(x) DCL.uwsgya(y) DCL.uelset("ltone",true) DCL.uetone(v) DCL.udcntz(v) first = false rescue print "*Error* ", $!,"\n" # show the error message in ($!) end end DCL.grcls ruby-netcdf-0.7.2/demo/demo1-create-alt.rb0000644000175000017500000000160712772251340020102 0ustar uwabamiuwabamirequire "numru/netcdf" include NumRu file = NetCDF.create("test.nc") nx, ny = 10, 5 file.def_dim("x",nx) file.def_dim("y",ny) file.def_dim("t",0) require "date" file.put_att("history","created by #{$0} #{Date.today}") x = file.def_var("x","sfloat",["x"]) y = file.def_var("y","sfloat",["y"]) t = file.def_var("t","sfloat",["t"]) v1 = file.def_var("v1","sfloat",["x","y"]) v1.put_att("long_name","test 1") v1.put_att("units","1") v2 = file.def_var("v2","sfloat",["x","y","t"]) v2.put_att("long_name","test 2") v2.put_att("units","1") file.enddef x.put( NArray.float(nx).indgen! ) y.put( NArray.float(ny).indgen! ) z = NArray.float(nx,ny).indgen!*0.1 v1.put(z) v1.put( NArray.float(nx).add!(20), "start"=>[0,2],"end"=>[-1,2]) v2.put(z, "start"=>[0,0,0],"end"=>[-1,-1,0]) t.put( 0, "index"=>[0]) v2.put(-z, "start"=>[0,0,1],"end"=>[-1,-1,1]) t.put( 1, "index"=>[1]) file.close print `ncdump test.nc`