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

Home » Public Forums » archive » Re: Reading files with unknown amount of 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 files with unknown amount of data [message #1463 is a reply to message #1358] Thu, 30 September 1993 16:38 Go to previous messageGo to previous message
sterne is currently offline  sterne
Messages: 15
Registered: March 1992
Junior Member
>>>> > "Robert" == Robert Davis <rdavis@aerospace.aero.org> writes:

Robert> I am trying to read a data file containing an unknown amount of
Robert> data into arrays in IDL. I know the format of the data in the
Robert> file, but not the number of pieces of data in the file.
Robert> Currently, I read the file twice; once to determine the amount
Robert> of data in the file and then a second time to actually read the
Robert> data into an array (now that I know the size of array needed).
Robert> Is there a better way to do this (without having to read the
Robert> file twice)?

Here are a couple more variations on the theme:

1. Check the size of the file on the system. In unix, if your file
is a simple formatted file, you can use the IDL command spawn:

spawn,'wc -l'+filename, result

and result will contain the number of lines in the file.

For a binary with fixed record length, you could read the size of
the file in bytes and work out the number of records from that.


2. Building on Joseph Zawodny's suggestion of using the EOF function:
sometimes you want to keep all the data around and manipulate stuff
after you have read it all in. You can use a variation like this:

a = fltarr(n,50) ; or whatever is appropriate.
; Initial guess of 50 records in the file.
openr,1,filename

count = 0

while not eof(1) do begin

if count eq (size(a))(2) then a = [[a],[a]] ; double size
; of 2nd index
readf,1,a(*,count)

count = count + 1

endwhile

close,1

a = a(*,0:ncount-1) ; trim to correct size



I've used both methods in the past, but, assuming I have control over
the software generating the numbers, I now much prefer to change the
software to make it write the number and format of the records at the
top of the file.

Hope this helps,
Phil
--
------------------------------------------------------------ ---------
Philip Sterne | sterne@dublin.llnl.gov
Lawrence Livermore National Laboratory | Phone (510) 422-2510
Livermore, CA 94550 | Fax (510) 422-7300
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Calling External programm
Next Topic: Re: Reading files with unknown amount of dat

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

Current Time: Fri Oct 10 18:35:15 PDT 2025

Total time taken to generate the page: 1.20047 seconds