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

Home » Public Forums » archive » Q: About reading files into an array without knowing the size.
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: Q: About reading files into an array without knowing the size. [message #5336 is a reply to message #5205] Tue, 07 November 1995 00:00 Go to previous messageGo to previous message
meron is currently offline  meron
Messages: 51
Registered: July 1995
Member
In article <309FD207.167E@pfc.mit.edu>, "Thomas W. Fredian" <twf@pfc.mit.edu> writes:
> David van Kuijk wrote:
>>
>> Hi
>>
>> One of the nice things of IDL is that it is possible to read whole
>> ASCII-files of data (e.g. floats) into an array in one swoop, without
>> having to go through a while loop which reads all of these numbers one by
>> one. E.g.:
>>
>> OPENR,1, "filename"
>> floatss=FLTARR(10000)
>> READF, 1, floatss
>>
> ...
>
> I just tried to write a simple procedure with an on_ioerror to trap the
> end of file error and it seems to work fairly well:
>
> function readarray,unit
> f = fstat(unit)
> maxvals=f.size
> answer=fltarr(maxvals) ; Allocate an array guaranteed to be big enough
> on_ioerror,finish ; Trap end of file error
> readf,unit,answer ; Read in what values are there
> finish:
> f = fstat(unit)
> return,answer(0:f.transfer_count-1) ; return the truncated array
> end
>
> I tested this with IDL Version 4.0.1(vms alpha) and it seems to work.
> --

Years ago I wrote a routine called read_ascii which reads data from an
ASCII file. The routine finds on the go the number of rows and
columns, as long as the number of entries on each line is the same.
It is possible to have lines of text imbedded in the file, the routine
will ignore them. Finally, it is called as a function so it returns
the data as an array.

Since the routine calls on other routines from my library, it is
advisable to copy the whole library and sort things out later. The
library, in tar form is accessible on cars.uchicago.edu in the pub/idl
directory. The file name is cars_library.tar . You can log in as
anonymous and get it.

Mati Meron | "When you argue with a fool,
meron@cars3.uchicago.edu | chances are he is doing just the same"
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: 3D velocity field representation
Next Topic: How can I add parameter to curvefit?

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

Current Time: Wed Oct 08 17:17:17 PDT 2025

Total time taken to generate the page: 0.00441 seconds