|
Re: reading in | delimited files into multiple arrays [message #49019 is a reply to message #49003] |
Fri, 09 June 2006 09:30  |
Jo Klein
Messages: 54 Registered: January 2006
|
Member |
|
|
> How do you read in a | delimited file in to multiple arrays, one for
> each column of the data?
I guess there are many ways to do this - how about splitting each line
using strsplit? Is the number of columns per line fixed? You could for
example first find out the number of lines to process using FILE_LINES,
then provide an array for intermediate storage:
number_of_columns=5
myfile='something.txt'
n=file_lines(myfile)
arr=make_array(5,n,/STRING)
openr,unit,myfile,/get_lun
for i=0,n-1 do BEGIN
readf,unit,line
arr[*,i]=strsplit(line,'|',/extract)
endfor
close,unit
free_lun,unit
Then, you can reform this into individual arrays, eg.:
secondcolumn=reform(arr[1,*])
Haven't tested this, but give it a try.
Cheers,
Jo
|
|
|
Re: reading in | delimited files into multiple arrays [message #49020 is a reply to message #49019] |
Fri, 09 June 2006 09:29  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
johnadams_1980@yahoo.com writes:
> How do you read in a | delimited file in to multiple arrays, one for
> each column of the data?
data = FltArr(numCol, numRow)
OpenR, lun, theFile, /Get_Lun
ReadF, lun, data
Free_Lun, data
col_1 = Reform(data[0,*])
col_2 = Reform(data[1,*])
etc.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|