- 积分
- 332
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-1-18
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
想把一个nc格式数据转存到txt文本文件中,修改ncl网站write_asc_4.ncl,出错提醒:fatal:process_list: can only handle list less than 128 elements.
查不出原因。贴出来,请高手指点。
;----------------------------------------------------------------------
; write_asc_4.ncl
;
; Concepts illustrated:
; - Generating dummy data
; - Writing a formatted 3D array of data to an ASCII file using write_table
; - Appending data to an existing ASCII file
; - Formatting integers using "sprinti"
;----------------------------------------------------------------------
begin
;---Generate a dummy 3D array
in = addfile("/home/xyr/ncl_data/LTNG_2011.nc","r")
nx = 37 ; # of blocks
ny = 118 ; # of rows
nt = 135 ; # of columns
data = in->LNT
; Use this to create "nice" numbers for debug purposes. This makes it easier to
; see how the data file is being written.
;
; data = reshape(conform_dims((/200,ny*nt/),ispan(1,ny*nt,1),1),(/nx,ny,nt/)) + \
; conform_dims((/nx,ny,nt/),ispan(1,nx,1),0)/1000.
;---Remove file just in case
filename = "file4.txt"
system("rm -f " + filename)
;---Write a header to the file
; header = "This ASCII file contains " + nx + " blocks of " + ny + " x " + nt + " arrays"
; write_table(filename, "w", [/header/], "%s") ; Use "w" to create file
;---Create row format string. It will have "%7.3f" repeated nt times
; fmt_str = "%s " + str_concat(conform_dims(nt,"%8.3f",-1))
fmt_str = "%s" + str_concat(conform_dims(nt,"%8.3f",-1))
;
; Loop through each column of each block and write the
; column of data to a List object. We can then use
; write_table to append a whole block of formatted data
; to an ASCII file.
;
row_labels = sprinti("%3i",ispan(1,ny,1))
dtmp = True ; Variable to hold temporary attributes
do i=0,nx-1
;---Write out the block number
slist = [/"Block " + (i+1) + " of " + nx/]
write_table(filename, "a", slist, "%s") ; Use "a" to append to existing file
;---Create a new List object for this block of data
dlist = NewList("lifo")
;---Loop in reverse order so items are written in correct order
do j=nt-1,0,1
ListPush(dlist,(/data(i,:,j)/))
end do
;---Push array of row headers onto list object
str = unique_string("test")
dtmp@$str$ = row_labels
ListPush(dlist,dtmp@$str$)
;---Append this List of data to file.
write_table(filename, "a", dlist, fmt_str)
end do
end
|
|