- 积分
- 746
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2017-9-7
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
最近用ncl提取一个nc文件的一段时间和一个范围内的变量数据输出到一个csv文件中,用Excel打开后时间一直是1.09E+06这种乱码,调了单元格格式之后也不对,代码如下,麻烦各位大神帮我看看,跪谢!!!
begin
;fils=systemfunc("ls *.nc")
;f=addfile("F:/pre_all.nc","r")
f=addfile("F:/ncep/pr_wtr.eatm.2016.nc","r")
time = cd_calendar(f->time, -3)
mm = time/10000%100
data = short2flt(f->pr_wtr)
imm = ind(mm.ge.6.and.mm.le.8)
;stime = time(imm)
spre = data(imm,{30:37.5},{90:97.5})
;spre&time = stime
;delete([/time,data,mm,imm/])
;cont = where(spre.ge.20., 1, 0)
;copy_VarCoords(spre, cont)
;dim = dimsizes(cont)
;
; Read the 1D coordinate arrays, conform them to 4D,
; then convert to 1D so we can write them to CSV
; file along with data.
;
dims = dimsizes(spre)
time1d = ndtooned(conform_dims(dims,spre&time,0))
lat1d = ndtooned(conform_dims(dims,spre&lat, 1))
lon1d = ndtooned(conform_dims(dims,spre&lon, 2))
;---Construct header line
field_names = (/ spre&time@long_name + " [" + spre&time@units + "]", \
spre&lat@long_name + " [" + spre&lat@units + "]", \
spre&lon@long_name + " [" + spre&lon@units + "]", \
spre@long_name + " [" + spre@units + "]"/)
header = [/str_join(field_names,",")/]
;---Write header to CSV file.
csv_filename = "pr_wtr.eatm.2016.csv"
system("rm -rf " + csv_filename)
write_table(csv_filename, "w", header, "%s")
;---Convert 4D arrays to 1D for writing to CSV file
spre1d = ndtooned(spre)
;---Write data to file
alist = [/time1d,lat1d,lon1d,spre1d/]
format = "%g,%g,%g,%g"
write_table(csv_filename, "a", alist, format)
end
|
|