Hi All,
I write first time here. I have a problem with reading out binary
files written in Linux/FORTRAN. I tryed several things but without
positive result. I would like to hear your opinion and any idea to
solve it is very-very wellcome :)
The binary file contain 100000 spectra (2 column X 7323 lambda-point).
In FORTRAN it is written like
niw=7323
close (61)
open (61,file='spectra2.bin', status='unknown', form='unformatted')
write
(61) (wl(i), fprop(i), i=1,niw)
I made spectra10.bin file with first 10 spectra to try reading out. I
will copy-paste several starting and ending rows of first two spectra
here to know what numbers we should expect.
firts:
91. 2.0477294E-23
94. 5.73141842E-23
96. 1.12217811E-22
...
360000000. 2.11874862E-22
second:
91. 2.3658085E-12
94. 4.20825007E-12
96. 6.12436013E-12
...
360000000. 1.0040658E-21
########################################
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?
########################################
The second try was
data = 'c:\users\spectra10.bin'
Openr, lun, data, /Get_Lun;, /F77_UNFORMATTED
data = Fltarr(2,7323,10)
skip = READ_BINARY(lun, DATA_DIMS = 0, DATA_START = 0, DATA_TYPE = 4)
ReadU, lun, data
Close, lun
Free_Lun, lun
print, data[0,0,0], ' ',data[1,0,0]
print, data[0,7322,0], ' ', data[1,7322,0]
print
print, data[0,0,1], ' ',data[1,0,1]
print, data[0,7322,1], ' ', data[1,7322,1]
with the same result
91.0000 2.04773e-023
3.60000e+008 2.11875e-022
8.20937e-041 8.20937e-041
2.40000e+008 5.08605e-021
I had to quit from this option since if I put data =
Fltarr(2,7323,100000) then I have this error message "Unable to
allocate memory: to make array". But ok, I can overcome this by
splitting binary files into peaces.
######################################################
this work perfectly but I need 83 days for reading out all 100000
spectra :)
nlam = 7323
nmod = 100
;define arrays
lam = fltarr(nmod,nlam) & flux = fltarr(nmod,nlam)
;for each model
step=4l
for imod = 0, nmod-1 do begin
for ilam = 0, nlam-1 do begin
lam[imod,ilam] = READ_BINARY(unit, DATA_DIMS = 0, DATA_START =
step, DATA_TYPE = 4)
flux[imod,ilam] = READ_BINARY(unit, DATA_DIMS = 0, DATA_START = step
+4, DATA_TYPE = 4)
step=step+8
endfor
endfor
####################################################
What is you opinion? How to read spectra out properly? Any ideas?
Similar experiences? Copmpressed, spectra10.bin file is only about 1/2
MB large so if it is easier to one to try I can send it.
Well...thanks in advance
oliver
|