ruby-netcdf-0.7.1.1/0000755000004100000410000000000012556371372014143 5ustar www-datawww-dataruby-netcdf-0.7.1.1/Rakefile0000644000004100000410000000003512556371372015606 0ustar www-datawww-datarequire "bundler/gem_tasks" ruby-netcdf-0.7.1.1/ToDo0000644000004100000410000000002112556371372014724 0ustar www-datawww-data* none currently ruby-netcdf-0.7.1.1/bin/0000755000004100000410000000000012556371372014713 5ustar www-datawww-dataruby-netcdf-0.7.1.1/bin/console0000644000004100000410000000052012556371372016275 0ustar www-datawww-data#!/usr/bin/env ruby require "bundler/setup" require "ruby/netcdf" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start ruby-netcdf-0.7.1.1/bin/setup0000644000004100000410000000016312556371372015776 0ustar www-datawww-data#!/bin/bash set -euo pipefail IFS=$'\n\t' bundle install # Do any other automated setup that you need to do here ruby-netcdf-0.7.1.1/Gemfile0000644000004100000410000000014012556371372015431 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in ruby-netcdf.gemspec gemspec ruby-netcdf-0.7.1.1/doc/0000755000004100000410000000000012556371372014710 5ustar www-datawww-dataruby-netcdf-0.7.1.1/doc/to_html0000755000004100000410000000037012556371372016304 0ustar www-datawww-data#!/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.1.1/doc/Ref_man_jp.rd0000644000004100000410000011441412556371372017304 0ustar www-datawww-data=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 は以下の4つのクラスから構成される。 * ((<クラス NetCDF>)) -- ファイルのクラス 一つのNetCDFクラスのオブジェクトは一つの NetCDF ファイルに対応する * ((<クラス NetCDFDim>)) -- 次元のクラス C 版 NetCDF では、次元は、ファイルのIDと次元IDという2変数の組で表されるが、 Ruby 版では一つの NetCDFDim オブジェクトで代表される * ((<クラス NetCDFVar>)) -- 変数のクラス C 版 NetCDF では、変数は、ファイルのIDと変数IDという2変数の組で表されるが、 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)または長さ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_, 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} などとする。つまり、要素 数が1のハッシュのキーに範囲(Range)、値にステップ(Integer)を指定 する。NArrayと違い、2次元以上の変数を1次元のインデックスで 指定することは出来ない。 ---[]= NetCDFVar#put と同様だが、サブセットを NArray#[]= と同様に指定する. NArrayでサポートされているサブセット指定方法に加えて、ステップ付 きの範囲を指定できる。これは {0..-1,2} などとする。つまり、要素 数が1のハッシュのキーに範囲(Range)、値にステップ(Integer)を指定 する。NArrayと違い、2次元以上の変数を1次元のインデックスで 指定することは出来ない。 ==="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.1.1/doc/Ref_man_jp.html0000644000004100000410000020154012556371372017640 0ustar www-datawww-data Untitled

RubyNetCDF <潟鴻ャ≪

RubyNetCDF version : 0.7.1

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

网荀

RubyNetCDF NetCDF ゃ若 Ruby ゃ潟帥若с若鴻сRuby 若吾с鴻荐茯с ユсRubyNetCDF 医ら Ruby т篏帥紊罨≦医らゃ NArray сゃ潟鴻若鏆荀 NArray 若帥C ゃ潟帥若g<≪守 篆荐膊罘莖羣合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 鐚罩g∈ 荐 NArray 鐚d緇c "char", "byte", "sint", "int", "sfloat", "float" 若違緇cNetCDFVar 鴻 vartype (=ntype) 絖筝ゃ菴障NetCDF鴻 def_var 純紊違絎臂篁鴻羈綽荀 ゃ若с "float" C ц double 潟 с Ruby dс -- 腟粋昭帥 Float 鴻C float с double 絲上с

NetCDFVar 鴻 get <純<ゃ筝 NArray 紊違 茯粋昭"char" 紊違ゃ "byte" NArray 茯粋昭障 NArray "char" с NArray byte ф絖膂≦宴с鴻筝遵

若堺箴紊榊絲上篏ゃ菴<純 с荵遵小若 nil 菴у上鐚絮уゃ緇絎 絮с絖鐚箴紊倶 nil 榊 <純ゃャ≪荐

祉ャ

腟粋昭帥 File 鴻祉ャc弱上

篏睡羈

RubyNetCDFゃ若障罨<茵 Ruby 違吾 ゃ若若綽荀

require 'numru/netcdf'

(NetCDFVar鴻) 若炊<純篏帥 篁ヤ絎茵綽荀

require 'numru/netcdf_miss'

т require 'numru/netcdf' 絎茵с 若鴻域若炊宴 NArrayMiss сゃ潟鴻若違 require 'numru/netcdf' 若吟NArrayMiss 筝荀с

с'numru' ("Numerical Ruby") 若吟若ゃ 若剛賢泣c若с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 ≪吾ャ若ゃ潟若у鐚憜鴻潟若 с鐚緇c罨<吾

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

篏睡箴潟若宴若吾障 demo test 違с

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

ャ≪荀

<純(綣1, 綣2, ...) -- ュ純綣違 綣医= 綵≪хず

罘純茹h

  • 綣1 (鴻障緇): 茯
  • 綣2 (鴻障緇): 茯
  • ...

  • 祉ゃ茯

絲上() C NetCDF ∽

  • NetCDF ver 3 ∽医綣с翫∽違膈罘純 腓冴贋・絲上翫綣у箴絖∽違

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

<純ゃ潟

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

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 篏帥c 鐚潟 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 若狗菴遵篏c鴻鴻若
  • 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) : 潟若<ゃ臀c弱 医紊違ф絎c種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/createfilename綣違筝荳菴.

  • 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

<≪寂賢<若c鴻筝<ゃ

  • 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" 障NArraytypecode(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吾сArraynames絖紊医障遺紊榊

絲上() 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吾сArraynames絖罨≦障遺紊榊

絲上() 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) 篏帥c堺ャ<祉ィ絅

  • 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 篏帥推戎緒с 箴紊榊). 潟c≪潟荐絎篏睡帥ゃ潟違 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 篏帥推戎緒с 箴紊榊). 憜潟c≪活┃絎菴.

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

紊医ゃ(NArraytypecodeц)

  • 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(Numeric1罨≦)NArray) 鴻(Numeric)障激鐚翫ゃ筝罕荐絎
  • option (Hash) : 紊違筝絎激с喝違 ャ違紊医篏絲乗院激ャ若 "start","end","stride"腟障"index"篏睡с"index" 1荀膣鐚鴻種"end","stride"ュャ 吾鴻荀膣違 value筝眼 違start,end,indexсArray翫罕莢ゃу 篏臀絎с"stride"罩cゃ水篁с 綣c菴医ラ

    箴鐚 紊違2罨≦翫:

    {"start"=>[2,5],"end"=>[6,-1],"stride"=>[2,4]} -- 膃1罨≦ 荀膣 2 6 障 1 ゃ (0違ц膣 2 3 с 羈)膃2罨≦荀膣 6 緇(=-1)障 3 ゃ c泣祉

    {"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_putpack絮 scale_factor add_offset 茹i

綣亥ゃ put 茹hс

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 c紊 -- 箴違 na sint scale_factor add_offset sfloat с違菴ゃ sfloat 菴ゃ NetCDFVar.unpack_type= 篏帥c 純絎с

  • na : unpack 医ら (NArray, or NArrayMiss)

  • a NArray or NArrayMiss

scaled_get(option=nil)

simple_getunpack絮 scale_factor add_offset 茹i

綣亥ゃ put 茹hс

[]

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)

get罕若炊

若炊罔羣絮 valid_range, (valid_min and/or valid_max), 障 missing_value 絎茹i篏 若吟若冴ゃィ絅с missin_value 茹i missing_value valid_* 絖翫 missng_value 鴻若睡峨c翫箴紊 榊

筝荐若炊鐚篁刻絎違<純 NArrayMiss 吾с菴с NArray 菴

  • NArrayMiss吾с (若炊絎翫) 障 NArray 吾с (若炊絎翫)

NetcdfError 篁ュ箴紊榊

  • missing_value 若炊合蚊 (筝荐с).

絲上() C NetCDF ∽

  • get 荀. <純 Ruby 帥ф吾.

  • 罨<箴с get get_with_miss 臀. [] 若炊茹i ( 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_missunpack鴻宴若潟違茵.

罨ゅ堺 pack 若帥絲乗院茵(紊 潟潟潟激с恰。)valid_* / missing_value pack 若帥違 unpack若帥 筝眼鐚鐚 unpack 若帥絲乗院 у堺潟潟潟激с潟絲上с

  • 筝荐сс

put_with_miss(value, option=nil)

put罕若炊

value NArray <純 put . value NArrayMiss с self 絮с若炊 絎臂 (get_with_missс)value 筝若炊茹i潟<value筝罨若帥 罨 (missing_value 障 _FillValue 障若炊合 紊綵) 臀筝с<ゃ吾莨若障 value 筝罨若帥 self 合蚊ャc с

  • value : NArrayMiss 障 put ц┗鴻吾с.
  • option (Hash) : put 荀.

  • nil

絲上() C NetCDF ∽

  • put 荀. <純 Ruby 帥ф吾.

  • 罨<箴с put put_with_miss 臀. []= 若炊茹i ( 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_misspack鴻宴若潟違茵.

罨ゅ堺 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

絮уゃ(NArraytypecodeц)

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

絲上() C NetCDF ∽

  • nc_inq_atttype
ruby-netcdf-0.7.1.1/doc/Ref_man.html0000644000004100000410000017600212556371372017153 0ustar www-datawww-data 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.1.1/doc/README_JP.txt0000644000004100000410000001225312556371372017002 0ustar www-datawww-data***** 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.1.1/doc/Ref_man.rd0000644000004100000410000013272512556371372016620 0ustar www-datawww-data=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.1.1/extconf.rb0000644000004100000410000001263212556371372016142 0ustar www-datawww-datarequire "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) 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-*").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.1.1/.rspec0000644000004100000410000000003712556371372015260 0ustar www-datawww-data--format documentation --color ruby-netcdf-0.7.1.1/demo/0000755000004100000410000000000012556371372015067 5ustar www-datawww-dataruby-netcdf-0.7.1.1/demo/README0000644000004100000410000000113312556371372015745 0ustar www-datawww-data * 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.1.1/demo/demo3-ncepclim.rb0000644000004100000410000001042612556371372020216 0ustar www-datawww-data# 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.1.1/demo/demo5-netcdf4.rb0000644000004100000410000000206512556371372017755 0ustar www-datawww-datarequire "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.1.1/demo/demo2-graphic.rb0000644000004100000410000000241512556371372020037 0ustar www-datawww-datarequire "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.1.1/demo/demo1-create-alt.rb0000644000004100000410000000160712556371372020444 0ustar www-datawww-datarequire "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` ruby-netcdf-0.7.1.1/demo/demo1-create.rb0000644000004100000410000000164412556371372017667 0ustar www-datawww-datarequire "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.1.1/demo/demo4-copy.rb0000644000004100000410000000130012556371372017366 0ustar www-datawww-data=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.1.1/LICENSE.txt0000644000004100000410000000513112556371372015766 0ustar www-datawww-dataRuby/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.1.1/.travis.yml0000644000004100000410000000003612556371372016253 0ustar www-datawww-datalanguage: ruby rvm: - 1.9.3 ruby-netcdf-0.7.1.1/lib/0000755000004100000410000000000012556371372014711 5ustar www-datawww-dataruby-netcdf-0.7.1.1/lib/netcdf_miss.rb0000644000004100000410000001377312556371372017547 0ustar www-datawww-datarequire "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.1.1/lib/version.rb0000644000004100000410000000007612556371372016726 0ustar www-datawww-datamodule Ruby module Netcdf VERSION = "0.7.1.1" end end ruby-netcdf-0.7.1.1/lib/netcdf.rb0000644000004100000410000005115712556371372016512 0ustar www-datawww-datarequire 'narray' 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 # classic netcdf ver 3 fmt @@cr_format = 0 when NC_64BIT_OFFSET, /^64BIT_OFFSET$/i @@cr_format = NC_64BIT_OFFSET when NC_NETCDF4, /^NETCDF4$/i @@cr_format = NC_NETCDF4 when ( NC_NETCDF4 | NC_CLASSIC_MODEL), /^NETCDF4_CLASSIC$/i # 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.1.1/ruby-netcdf.gemspec0000644000004100000410000000272712556371372017742 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'version' Gem::Specification.new do |spec| spec.name = "ruby-netcdf" spec.version = Ruby::Netcdf::VERSION spec.authors = ["Takeshi Horinouchi", "Tsuyoshi Koshiro",\ "Shigenori Otsuka", "Seiya Nishizawa", "T Sakakima"] spec.email = ['eriko@gfd-dennou.org'] #if spec.respond_to?(:metadata) # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server." #end 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 = ["GFD Dennou Club"] spec.files = `git ls-files -z`.split("\x0") spec.test_files = spec.files.grep(%r{^(test|demo)/}) #spec.bindir = "exe" #spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.required_ruby_version = Gem::Requirement.new(">= 1.6") spec.add_runtime_dependency(%q, [">= 0"]) spec.add_runtime_dependency(%q, [">= 0"]) spec.extensions << "extconf.rb" end ruby-netcdf-0.7.1.1/metadata.yml0000644000004100000410000000567012556371372016456 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: ruby-netcdf version: !ruby/object:Gem::Version version: 0.7.1.1 platform: ruby authors: - Takeshi Horinouchi - Tsuyoshi Koshiro - Shigenori Otsuka - Seiya Nishizawa - T Sakakima autorequire: bindir: bin cert_chain: [] date: 2015-03-02 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: narray requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: narray_miss requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' description: 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. email: - eriko@gfd-dennou.org executables: [] extensions: - extconf.rb extra_rdoc_files: [] files: - .gitignore - .rspec - .travis.yml - ChangeLog - Gemfile - INSTALL - LICENSE.txt - Rakefile - ToDo - bin/console - bin/setup - demo/README - demo/demo1-create-alt.rb - demo/demo1-create.rb - demo/demo2-graphic.rb - demo/demo3-ncepclim.rb - demo/demo4-copy.rb - demo/demo5-netcdf4.rb - doc/README_JP.txt - doc/Ref_man.html - doc/Ref_man.rd - doc/Ref_man_jp.html - doc/Ref_man_jp.rd - doc/to_html - extconf.rb - lib/netcdf.rb - lib/netcdf_miss.rb - lib/version.rb - netcdfraw.c - ruby-netcdf.gemspec - test/aref_aset.rb - test/char_var.rb - test/clone.rb - test/create_tmp.rb - test/def_var_with_dim.rb - test/factor_offset.rb - test/putatt.cdl - test/putatt.rb - test/test.cdl - test/test.rb - test/type.rb homepage: http://www.gfd-dennou.org/arch/ruby/products/ruby-netcdf/ licenses: - GFD Dennou Club metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '1.6' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.4.6 signing_key: specification_version: 4 summary: Ruby interface to NetCDF test_files: - demo/README - demo/demo1-create-alt.rb - demo/demo1-create.rb - demo/demo2-graphic.rb - demo/demo3-ncepclim.rb - demo/demo4-copy.rb - demo/demo5-netcdf4.rb - test/aref_aset.rb - test/char_var.rb - test/clone.rb - test/create_tmp.rb - test/def_var_with_dim.rb - test/factor_offset.rb - test/putatt.cdl - test/putatt.rb - test/test.cdl - test/test.rb - test/type.rb ruby-netcdf-0.7.1.1/INSTALL0000644000004100000410000000357012556371372015201 0ustar www-datawww-dataInstallation 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.1.1/test/0000755000004100000410000000000012556371372015122 5ustar www-datawww-dataruby-netcdf-0.7.1.1/test/factor_offset.rb0000644000004100000410000000206312556371372020274 0ustar www-datawww-datarequire '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.1.1/test/test.cdl0000644000004100000410000000150612556371372016567 0ustar www-datawww-datanetcdf 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.1.1/test/putatt.cdl0000644000004100000410000000074312556371372017133 0ustar www-datawww-datanetcdf 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.1.1/test/clone.rb0000644000004100000410000000145712556371372016556 0ustar www-datawww-datarequire '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.1.1/test/aref_aset.rb0000644000004100000410000000132512556371372017401 0ustar www-datawww-datarequire '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.1.1/test/putatt.rb0000644000004100000410000000274612556371372017001 0ustar www-datawww-datarequire '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.1.1/test/def_var_with_dim.rb0000644000004100000410000000065612556371372020750 0ustar www-datawww-datarequire '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.1.1/test/test.rb0000644000004100000410000001335012556371372016430 0ustar www-datawww-data##require '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.1.1/test/create_tmp.rb0000644000004100000410000000044212556371372017572 0ustar www-datawww-datarequire '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.1.1/test/type.rb0000644000004100000410000000040212556371372016424 0ustar www-datawww-datarequire '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.1.1/test/char_var.rb0000644000004100000410000000072212556371372017235 0ustar www-datawww-data## 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.1.1/.gitignore0000644000004100000410000000012112556371372016125 0ustar www-datawww-data/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /pkg/ /spec/reports/ /tmp/ ruby-netcdf-0.7.1.1/netcdfraw.c0000644000004100000410000035324312556371372016276 0ustar www-datawww-data#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; } } 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)); #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); 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.1.1/ChangeLog0000644000004100000410000004437212556371372015727 0ustar www-datawww-dataTue 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