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

Home » Public Forums » archive » Re: Reading in text data
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 text data [message #21099 is a reply to message #21098] Tue, 08 August 2000 00:00 Go to previous messageGo to previous message
Andy Loughe is currently offline  Andy Loughe
Messages: 174
Registered: November 1995
Senior Member
reardonb@my-deja.com wrote:
>
> Hi. I am reading in text data (columns and rows of numbers) and I would
> like to know if there is a more elegant way of doing it. Currently, the
> user must specify how many columns there are. In my case the number of
> columns is manually inserted into the first line of the file like this:
>
> 3
> 0 1 2
> 1 2 3
> 2 3 4
> 3 4 5
> 4 5 6
> 5 6 7
> 6 7 8
> 7 8 9
> 8 9 10
> 9 10 11

There are lots of ways to attack this problem depending upon
whether you need to operate on the data one-row-at-a-time, or
if you need all the data stored into an array. Some potentially
useful ideas are illustrated in this simple procedure...

infile = 'column.dat' ;** ASCII input filename.
spawn, 'wc -l < ' + infile, num_recs ;** Number of rows in ASCII file
num_recs = long(num_recs(0)) ;** Convert to num_recs to LONG
data = strarr(num_recs) ;** Declare output array
openr, iu, infile, /get_lun ;** Open file
readf, iu, data ;** Real ALL the data as a string
free_lun, iu ;** Close the file

;** Use help, to check size of arrays. Notice record #1.
for i = 0, num_recs-1 do help, long(str_sep(data(i),' ',/rem))

;** Or use print, to check on value of array elements.
for i = 0, num_recs-1 do print, long(str_sep(data(i),' ',/rem))

end

--
Andrew Loughe =====================================================
NOAA/OAR/FSL/AD R/FS5 | email: loughe@fsl.noaa.gov
325 Broadway | wwweb: www-ad.fsl.noaa.gov/users/loughe
Boulder, CO 80305-3328 | phone: 303-497-6211 fax: 303-497-6301
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Reverse FFT ?
Next Topic: VMS FORTRAN/GKS Graphics to PV-WAVE conversion

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

Current Time: Fri Oct 10 18:46:07 PDT 2025

Total time taken to generate the page: 0.88021 seconds