nccreate_time_1dim.rb

「nccreate_time_1dim.rb」の編集履歴(バックアップ)一覧はこちら

nccreate_time_1dim.rb」(2012/06/22 (金) 13:37:14) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

require "numru/netcdf" include NumRu file = NetCDF.create("test3.nc") # 新規作成 nx = 4 file.def_dim("x",nx) # 次元の定義 file.def_dim("t",0) # t~UNLIMITED require "date" file.put_att("history","created by #{$0} #{Date.today}") # グローバル属性の設定 x = file.def_var("lon","sfloat",["x"]) # 変数の定義 t = file.def_var("t","sfloat",["t"]) x.put_att("long_name","longitude") # 属性の設定 x.put_att("units","deg") t.put_att("long_name","time") t.put_att("units","s") velx = file.def_var("VelX","sfloat",["x","t"]) velx.put_att("long_name","longitudinal velocity") velx.put_att("units","m/s") file.enddef # defineモード終わり x.put( NArray.float(nx).indgen!*120 ) # 値を入れる dt = 10.0 # time interval nt = 3 # total time step n=0 for n in 0..(nt-1) time = n * dt print "n=#{n}, time=#{time}\n" z = NArray.float(nx).indgen! * n * dt velx.put(z, "start"=>[0,n],"end"=>[-1,n]) # startからendまで値を入れる t.put( time, "index"=>[n]) # indexの場所に値を入れる end file.close print `ncdump test3.nc` # できたファイルを見る **出力結果 $ ruby nccreate_time_1dim.rb n=0, time=0.0 n=1, time=10.0 n=2, time=20.0 netcdf test3 { dimensions: x = 4 ; t = UNLIMITED ; // (3 currently) variables: float lon(x) ; lon:long_name = "longitude" ; lon:units = "deg" ; float t(t) ; t:long_name = "time" ; t:units = "s" ; float VelX(t, x) ; VelX:long_name = "longitudinal velocity" ; VelX:units = "m/s" ; // global attributes: :history = "created by nccreate_time_1dim.rb 2012-06-22" ; data: lon = 0, 120, 240, 360 ; t = 0, 10, 20 ; VelX = 0, 0, 0, 0, 0, 10, 20, 30, 0, 20, 40, 60 ; }

表示オプション

横に並べて表示:
変化行の前後のみ表示: