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 #5341 is a reply to message #5205] Tue, 07 November 1995 00:00 Go to previous messageGo to previous message
Thomas W. Fredian is currently offline  Thomas W. Fredian
Messages: 1
Registered: November 1995
Junior Member
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.
--
/*************************************/
Thomas W. Fredian
Plasma Fusion Center
Massachusetts Institute of Technology
email: twf@pfc.mit.edu
/*************************************/
[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:23:33 PDT 2025

Total time taken to generate the page: 0.00445 seconds