按行读取txt文件
;readin the data file
openr,lun,file_name,/get_lun
array = '' & line = ''
while not eof(lun) do begin
readf,lun,line
array = [array,line]
endwhile
free_lun,lun
当一行有多个数据时,需要将其分隔开,可以用"STRSPLIT"函数,这里以一个一行9个数据的文件为例,前两个数据为时间,后7个为不同波段的数据:
n = n_elements(array)
timet = strarr(n)
data = fltarr(7,n)
for i = 0,n-1 do begin
tmp = strsplit(array[i],/extract)
timet[i] = tmp[0]+' '+tmp[1]
data[*,i] = float(tmp[2:*])
endfor
3641

被折叠的 条评论
为什么被折叠?



