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

Home » Public Forums » archive » Reading binary files made by Python
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: reading binary files [message #54512 is a reply to message #49280] Tue, 19 June 2007 06:00 Go to previous message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
On Tue, 19 Jun 2007 00:49:17 -0700, Vince Oliver
<vince@complex.elte.hu> wrote:

> Firest try was using Assoc function. It was somehow natural choice
> since the number of spectra is large. So:
>
> data = 'c:\users\spectra10.bin'
> spectra = Assoc(lun, Fltarr(2,7323))
> aSpectra = spectra[0]
> print, aSpectra[0,0],aSpectra[1,0]
> print, aSpectra[0,7322],aSpectra[1,7322]
> print
> aSpectra = spectra[1]
> print, aSpectra[0,0],aSpectra[1,0]
> print, aSpectra[0,7322],aSpectra[1,7322]
>
> The outout is
>
> 8.20937e-041 91.0000
> 1.07971e-021 3.60000e+008
>
> 2.11875e-022 8.20937e-041
> 2.57653e-020 2.40000e+008
>
>
> It was clear that I should put an offset keyword in Assoc like spectra
> = Assoc(lun, Fltarr(2,7323),4). The output in this case is:
>
> 91.0000 2.04773e-023
> 3.60000e+008 2.11875e-022
>
> 8.20937e-041 8.20937e-041
> 2.40000e+008 5.08605e-021
>
>
> So the 1st spectrum is properly read out but the second not. It seems
> that there is an offset between each spectra. How to read out spectra
> properly in this case?
>
> ########################################

From IDL's help:

"Unformatted data files generated by FORTRAN programs under UNIX
contain an extra long word before and after each logical record in the
file. ASSOC does not interpret these extra bytes but considers them to
be part of the data. This is true even if the F77_UNFORMATTED keyword
is specified..."

I have no experience with this, but what happens if you use (e.g. for
3rd spectrum):

specnr=2
nlen=7323
n=2*nlen+1
specoff=n*specnr*4
spectra = Assoc(lun, Fltarr(n),specoff)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: extracting specific substrings from a text-file
Next Topic: Re: Error: X does not support locale C.

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

Current Time: Fri Oct 10 10:22:11 PDT 2025

Total time taken to generate the page: 1.04754 seconds