【正文】
。 ENDIF ENDFOR Close the file. WRITE_GIF, outfname, /CLOSE ENDIFENDIDL代碼共享IDL讀取文本格式矩陣數(shù)據(jù)20110330 19:48:17|分類: 代碼類 |標(biāo)簽: |字號(hào)大中小訂閱 。+。 :Description:。 Read digital number sotred in a text file, and the。 separater of the data in each line must be a 39。Space39。 or 39。Tab39。.。 :Params:。 infilename : Input filename of the text file.。 :Uses:。 data = read_txt_data_file(39。c:\39。)。 :Author: dabin。 :Email: dabinj@。 :Date: 20091216。FUNCTION read_txt_data_file, infilename Get the number of lines nlines = FILE_LINES(infilename) OPENR, lun1, infilename, /GET_LUN Used to store a line tmp_str = 39。39。 Get columns of the input file READF, lun1, tmp_str tmp = STRSPLIT(tmp_str, COUNT = col_count) POINT_LUN, lun1, 0 Allocate memory data = FLTARR(col_count, nlines) row_count = 0L WHILE ~EOF(lun1) DO BEGIN READF, lun1, tmp_str IF ~STRCMP(tmp_str, 39。39。) THEN BEGIN tmp_str_split = STRSPLIT(tmp_str, /EXTRACT) data_line = FLOAT(tmp_str_split) data[*, row_count] = data_line row_count = row_count + 1 ENDIF ENDWHILE FREE_LUN, lun1 RETURN, data[*, 0 : (row_count 1)]END