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

Home » Public Forums » archive » Re: BINARY FILES
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: BINARY FILES [message #21975] Fri, 13 October 2000 00:00
mole6e23 is currently offline  mole6e23
Messages: 31
Registered: December 1998
Member
mohamed_nur@my-deja.com wrote:

> I've been dealing with binary files and every case i had to know before
> hand the dimensions of the array to setup an IDL variable of the said
> dimesions and read the unformatted data into.
>
> But is it possible or is there a method (in IDL 5.2/5.3) to read it in
> with no knowledge of the dimensions of the array.


I always use the fstat routine, which gets a bunch of information about
the file, but the only one I ever use is the size field:

;-----
openr,lun,'file.dat',/get_lun
stat = fstat( lun )

array = fltarr( stat.size )

readu,lun,array

free_lun, lun
;----

Alternatively, if you're on UNIX, you can use the /nostdio keyword which
lets you just read willy nilly until the end of the file, and then get the
transfer count from the readu procedure. It's not a good way of doing
things, in my opinion, but it works:

;; Allocate a much bigger array than you need
array = fltarr( 1e5 )
openr,lun,'file.dat',/get_lun,/nostdio
readu,lun,array,transfer_count=count
array = temporary(array)[0:count-1]
free_lun, lun


Hope this helps,
Todd
Re: BINARY FILES [message #21977 is a reply to message #21975] Fri, 13 October 2000 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
mohamed nur (mohamed_nur@my-deja.com) writes:

> I've been dealing with binary files and every case i had to know before
> hand the dimensions of the array to setup an IDL variable of the said
> dimesions and read the unformatted data into.
>
> But is it possible or is there a method (in IDL 5.2/5.3) to read it in
> with no knowledge of the dimensions of the array.

A free Second Edition IDL Programming Techniques book
to the first person who can find the simple word I
embedded in this binary sequence:

0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 1
0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 1 1 0 1 1 0 0 0 0 0
0 0 0 0 0 1 1 0 1 0 0 1 0 0 0 0 0 0 0
0 0 1 1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1
0 0 0 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 0

Cheers,

David

P.S. Let's just say this is a *much* easier problem
than the one you propose. :-)

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: [Q]: ID analog to FORTRAN "sign" function
Next Topic: Re: object wizards

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

Current Time: Sat Oct 11 16:00:47 PDT 2025

Total time taken to generate the page: 0.48144 seconds