BINARY FILES [message #21979] |
Fri, 13 October 2000 00:00  |
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   |
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 #22064 is a reply to message #21979] |
Fri, 13 October 2000 00:00   |
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 #22069 is a reply to message #21979] |
Fri, 13 October 2000 00:00   |
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 #22073 is a reply to message #21979] |
Fri, 13 October 2000 00:00   |
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  |
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?
|
|
|