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

Home » Public Forums » archive » 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
BINARY FILES [message #21979] Fri, 13 October 2000 00:00 Go to next message
mohamed_nur is currently offline  mohamed_nur
Messages: 3
Registered: October 2000
Junior Member
hello all,
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.

thanks for the assistance


mohamed nur


Sent via Deja.com http://www.deja.com/
Before you buy.
Re: BINARY FILES [message #22046 is a reply to message #21979] Mon, 16 October 2000 00:00 Go to previous messageGo to next message
Aaron Birenboim is currently offline  Aaron Birenboim
Messages: 24
Registered: October 2000
Junior Member
Todd Clements <mole6e23@hotmail.com> wrote:
: 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

After that, you can resize the array to the desired dimensions.
I do that frequently.

I have even used a correlation algorithm to determine
widths of image data that is not necessarily aligned!
Hopefully, your problem is not that tricky.
--
Aaron Birenboim
Albuquerque, NM
aaron@ptree.abq.nm.us
http://www.swcp.com/~aaron
Re: BINARY FILES [message #22047 is a reply to message #21979] Mon, 16 October 2000 00:00 Go to previous messageGo to next message
Aaron Birenboim is currently offline  Aaron Birenboim
Messages: 24
Registered: October 2000
Junior Member
Paul van Delst <pvandelst@ncep.noaa.gov> wrote:
: mohamed_nur@my-deja.com wrote:

: I have used both Todd Clements' suggestion, then graduated to Liam's
: tools. I now work (almost) exclusively in netCDF so I avoid:

How about HDF?
Is it falling out of favor in some communities?

--
Aaron Birenboim
Albuquerque, NM
aaron@ptree.abq.nm.us
http://www.swcp.com/~aaron
Re: BINARY FILES [message #22060 is a reply to message #21979] Sun, 15 October 2000 00:00 Go to previous messageGo to next message
Nick Bower is currently offline  Nick Bower
Messages: 43
Registered: June 1999
Member
>
> The following may be of interest:
> http://cimss.ssec.wisc.edu/~gumley/binarytools.html
>

I use Liam's tools exclusively, as netCDF was overkill for my purposes.
They rock. Which reminds me, I've been meaning to do a python port of
theses tools too.

nick
Re: BINARY FILES [message #22064 is a reply to message #21979] Fri, 13 October 2000 00:00 Go to previous messageGo to next message
mole6e23 is currently offline  mole6e23
Messages: 31
Registered: December 1998
Member
> At last count (at least on my newsreader) we have two replies (Todd
> Clements' second post doesn't count :o) and five.... well I don't know
> what to call them. That a SNR of 0.4. Oof.

Hmm...not sure if this message will increase that or decrease that. ;>

> I have used both Todd Clements' suggestion, then graduated to Liam's
> tools. I now work (almost) exclusively in netCDF so I avoid:

Of course, I didn't know that Liam's tools existed, so I reinvented the
wheel and made my own tools. Then, Of course^2, the advantage to
reinventing the wheel is that you can use the correct material and number
of spokes you want for the wheel instead of what someone else wants. The
routines I've written for our lab are one-liners that do 99% of everything
we need. We don't care much about portability, or generalized reading and
writing. We write out our own data and read in our own data. For
everything else, we use the command line. ;>

And the other advantage (I admit to not being familiar with CDF, so I
can't say whether this is supported) is that by writing my own routines, I
can take advantage of the file compression capabilities recently built
into IDL. Most of the data we write consists of x,y data or x,y and 2-d
image data. The 2-d image data files get rather large even in binary, but
they are highly compressible, so we save 80% of our disk space, which is
nice.

But then again, I'm the type that even sometimes when the wheel exists, I
invent it all over again because I want to know to make my own wheel. (Not
to mention I like to ride on one wheel - it's a fun activity - but perhaps
there is a connection here...)

Todd
Re: BINARY FILES [message #22065 is a reply to message #21979] Fri, 13 October 2000 00:00 Go to previous messageGo to next message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
mohamed_nur@my-deja.com wrote:
>
> hello all,
> 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.
>
> thanks for the assistance

At last count (at least on my newsreader) we have two replies (Todd
Clements' second post doesn't count :o) and five.... well I don't know
what to call them. That a SNR of 0.4. Oof.

I have used both Todd Clements' suggestion, then graduated to Liam's
tools. I now work (almost) exclusively in netCDF so I avoid:

a) the problem with needing to know the file format/dimensions/etc,
b) the problems one encounters moving data files from big->little-endian
machines and
c) having to use IDL for everything (netCDF has an API in multiple
languages and the list is growing).

If you have the ability to create the files and aren't worried about
portability, I would suggest Liam's binary tools. If portability is a
problem, then (for a bit more effort) I'd say go with netCDF.

If you're stuck with someone else's files, then you're in the schtook.
It was only recently I discovered that Fortran sequential binary files
aren't as portable as I thought - endian-ness notwithstanding (Those
damn record delimiters!)

paulv
--
Paul van Delst Ph: (301) 763-8000 x7274
CIMSS @ NOAA/NCEP Fax: (301) 763-8545
Rm.202, 5200 Auth Rd. Email: pvandelst@ncep.noaa.gov
Camp Springs MD 20746
Re: BINARY FILES [message #22066 is a reply to message #21979] Fri, 13 October 2000 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
J.D. Smith (jdsmith@astro.cornell.edu) writes:

> Hmm... all ascii letters at any offset:
>
> 0:hH
> 1:Ja
> 2:XF
> 3:
> 4:Qa
> 5:ddvid
> 6:El
> 7:
>
> Offset 5 looks promising. Do we get extra points for detecting typoes?
> Does the german Ja or spanish El count?

Oh, JD, I knew *you* would get it! And I was going
to send you a book anyway, just because I always
learn something every time you post. :-)

Cheers,

David

P.S. Humm. I was *sure* I typed an A there. :-(
--
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
Re: BINARY FILES [message #22067 is a reply to message #21979] Fri, 13 October 2000 00:00 Go to previous messageGo to next message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
David Fanning wrote:
>
> 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
>


Hmm... all ascii letters at any offset:

0:hH
1:Ja
2:XF
3:
4:Qa
5:ddvid
6:El
7:

Offset 5 looks promising. Do we get extra points for detecting typoes?
Does the german Ja or spanish El count?

JD


--
J.D. Smith | WORK: (607) 255-6263
Cornell Dept. of Astronomy | (607) 255-5842
304 Space Sciences Bldg. | FAX: (607) 255-5875
Ithaca, NY 14853 |
Re: BINARY FILES [message #22069 is a reply to message #21979] Fri, 13 October 2000 00:00 Go to previous messageGo to next message
mole6e23 is currently offline  mole6e23
Messages: 31
Registered: December 1998
Member
Silly me -

Of course, you need to divide by the size of each element when using the
fstat function to get the array size:

array = fltarr( stat.size / 4 ) ;; 4 bytes to a float

Todd

> 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
Re: BINARY FILES [message #22070 is a reply to message #21979] Fri, 13 October 2000 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Martin Schultz (martin.schultz@dkrz.de) writes:

> Hmmmm, David: please count the digits next time -- these truely don't
> make sense.

No, I threw in a few extra digits to make the problem more
"real world-like". It simulates the problem of thinking you
have an integer value when you really have a byte value. :-)

Cheers,

David

P.S. The book is still available!

--
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
Re: BINARY FILES [message #22071 is a reply to message #21979] Fri, 13 October 2000 00:00 Go to previous messageGo to next message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior 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.

The following may be of interest:
http://cimss.ssec.wisc.edu/~gumley/binarytools.html

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
Re: BINARY FILES [message #22073 is a reply to message #21979] Fri, 13 October 2000 00:00 Go to previous messageGo to next message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
David Fanning wrote:
>
> 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

Hmmmm, David: please count the digits next time -- these truely don't
mnake sense.
Yet, I tried - first padding the string with a few more zero's.

First step:
copy the text into a string (mouse)
IDL> a='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 ...'

Then:
a=strcompress(a,/remove_all)3
print,strlen(a)
; 114 (which divided by 8 is 14.25)
a=a+'000000'
b=bytarr(8,15)
reads,a,b,format='(120a1)'
value=lonarr(15)
for i=0,14 do
value =long(b[0,i])+2*(b[1,i]+2*(b[2,i]+2*(b[3,i]+2*(b[4,i]+2*(b[5 ,i]+2*(b[6,i]+2*b[7,i]))))))
print,string(byte(value))

; (doesn't make sense, though ...)


Cheers,
Martin

--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
Re: binary files [message #75423 is a reply to message #21979] Wed, 09 March 2011 18:03 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Mar 9, 8:43 pm, BigDaveII <davidharri...@yahoo.com> wrote:
> I am new to learning IDL, I have looked at all the Web Seminars, even
> order books Gumley, Bowman, & Fanning and have been reading them .  I
> am just having trouble with the basic. I am trying to set my directory
> for where my data is located. I tried running a simple program to read
> a binary file but can not get it to work.  Can anyone please give me
> some advice on how to solve this problem.

Unless NDVI is some standard that people here might recognize, this is
not enough information. What data does the file contain? Organized in
what way?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: selecting radnom number from 2D array
Next Topic: LOADCT is not working

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

Current Time: Wed Oct 08 15:49:32 PDT 2025

Total time taken to generate the page: 0.00752 seconds