comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: reading in | delimited files into multiple arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: reading in | delimited files into multiple arrays [message #49019 is a reply to message #49003] Fri, 09 June 2006 09:30 Go to previous messageGo to previous message
Jo Klein is currently offline  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
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Roses Blooming
Next Topic: replace elements in array

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 12:10:55 PDT 2025

Total time taken to generate the page: 1.03647 seconds