Hi,
I am having trouble for reading with IDL a binary file i wrote in
Fortran90.
Here is how i wrote it in fortran.
open(11,file='bfile.bin',form='unformatted')
write(11) nrej,n
write(11) data(1:nrej,1:n)
close(11)
I can read it correctly in fortran but in IDL , when i do :
" nrej = 0L
n = 0L
my_file = 'bfile.bin'
a = 0.0d0
openr,unit,myfile,/get_lun
readu,unit, nrej,n
Nphot_tab = dblarr(nrej,n)
Nphot_tab(*,*) = 0.0d0
for i=0L,nrej-1L do begin
for j=0L,n-1L do begin
readu,unit,a
Nphot_tab(i,j) = a
endfor
endfor
close,unit, /file
free_lun,unit
"
it prints : READU: End of file encountered. Unit:.....
Does anybody know what i did wrong? :)
Thank you!
|
|
0
|
|
|
|
Reply
|
thibaultgarel (44)
|
3/25/2010 5:19:25 PM |
|
bing999 writes:
> Does anybody know what i did wrong? :)
Maybe you forgot the F77_UNFORMATTED keyword on
the OPENR statement .
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
|
|
0
|
|
|
|
Reply
|
David
|
3/25/2010 5:42:17 PM
|
|
This is what you were asking, but I think the way you are reading it,
your Nphot_tab will have the elements messed up in it. Both IDL and
Fortran are row major, so when you read the data, the leftmost
dimension should vary the fastest. Also I think you could use just:
nrej = 0L
n = 0L
my_file = 'bfile.bin'
openr,unit,myfile,/get_lun,/f77_unformatted
readu,unit, nrej,n
Nphot_tab = dblarr(nrej,n)
readu,unit,Nphot_tab
free_lun,unit
You should also make sure that the data types match. Is your fortran
array data made of 64-bit reals? Are the fortran nrej and n 32 bit
integers?
|
|
0
|
|
|
|
Reply
|
pp
|
3/25/2010 6:50:24 PM
|
|
On Mar 25, 3:50=A0pm, pp <pp.pente...@gmail.com> wrote:
> This is what you were asking, but I think the way you are reading it,
I meant to say "this is not what you were asking".
|
|
0
|
|
|
|
Reply
|
pp
|
3/25/2010 6:51:31 PM
|
|
|
3 Replies
854 Views
(page loaded in 0.071 seconds)
|