#!/usr/bin/env ruby ################################################## =begin =gpprint2txt エネルギースペクトルの 3次元データ eksp(t,k,l) を読み込み, (k, l, eksp) の列のテキストデータを作成するプログラム ==USAGE % gpprint2txt url where the format of the url is path@varname ==EXAMPLES % gpprint2txt data.nc@temp % gpprint2txt data.nc@temp > hogehoge.dat ==HISTORY 2006/02/14 H Taniguchi (created) =end ################################################## require "numru/gphys" require "numru/gphys/gpcommon" include NumRu gturl = ARGV[0] gphys = GPhys::IO.open_gturl(gturl) fileval = gturl.split(/@/) fstname = fileval[0] endname = fileval[1] size = fstname.size if size == 34 topname = fstname.slice(0..7) else topname = fstname.slice(0..8) end l = gphys.coord(0).val k = gphys.coord(1).val t = gphys.coord(2).val new_line_int = 1 first_dim_len = (gphys.shape[0]||1) fmt = " %g" eksp = gphys.data.val #eksp = gphys.cut(true, true, true).data.val a = 0 tnum2 = 0 while(tnum2 <= t.length) do tmp = t[a] * 10 # tmp を 10 倍する tmp = tmp.round # tmp の小数点以下を四捨五入して Integer に変換 tmp = (tmp.to_f / 10) # tmp を Float に変換して 10 で割る tx = "#{tmp}" # tmp を文字オブジェクトに変換 tx = tx.slice!(0..2) outfilename = "#{topname}-#{endname}_t=#{tx}0_file.txt" print outfilename, " file is making ...\n" outfile = open(outfilename, "w") outfile.print("##### t=",t[a], " (k, l, eksp) #####\n") #for a in 0...t.length do for b in 0...k.length do for c in 0...l.length do # print t[a], "\t", k[b], "\t", l[c], "\t", eksp[c,b,a], "\n" # outfile.print(t[a], "\t", k[b], "\t", l[c], "\t", eksp[c,b,a], "\n") outfile.print(k[b], "\t", l[c], "\t", eksp[c,b,a], "\n") end end # print "\n" #end outfile.close a += 10 tnum2 += 1 end