- 积分
- 1901
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-1-6
- 最后登录
- 1970-1-1
|
发表于 2016-8-29 16:02:25
|
显示全部楼层
本帖最后由 xuebiz 于 2016-8-29 16:06 编辑
http://www.ncl.ucar.edu/Applications/read_ascii.shtml
官网例子~~
可能这个例子比较像你的数据,供参考
stn_latlon.dat - a file with 980 rows and 10 columns of floating point data. (example)
http://www.ncl.ucar.edu/Applications/read_ascii.shtml#stn_latlon
stn_latlon.dat - a file with 980 rows and 10 columns of floating point data.
The first two methods show how to read this file if you know the exact number of rows and columns, and the third method shows how to read this file if you don't.
Method 1
; Read data into a 980 x 10 float array.
nrows = 980
ncols = 10
data = asciiread("stn_latlon.dat",(/nrows,ncols/),"float")
printVarSummary(data) ; Print information about file only.
; Two ways to print the data.
print(data) ; Print data, one value per line
write_matrix(data,ncols + "f7.2",0) ; Formatted output
Method 2
This file is actually a file of latitude and longitude values, each dimensioned 70 x 70. The latitude values are written first on the file, followed by the longitude values. Given this information, here's another way to read in this file:
nlat = 70
nlon = 70
latlon2d = asciiread("stn_latlon.dat",(/2,nlat,nlon/),"float") ; 2 x 70 x 70
lat2d = latlon2d(0,:,:) ; 70 x 70
lon2d = latlon2d(1,:,:) ; 70 x 70
Method 3
Use the special contributed functions numAsciiCol and readAsciiTable function to first calculate the number of columns, and then to read the data into an array dimensioned nrows x ncols.
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
filename = "stn_latlon.dat"
; Calculate the number of columns.
ncols = numAsciiCol(filename)
; Given the # of columns, we can use readAsciiTable to read this file.
data = readAsciiTable(filename,ncols,"float",0)
nrows = dimsizes(data(:,0)) ; calculate # of rows
print("'" + filename + "' has " + nrows + " rows and " + ncols + \
" columns of data.")
|
|