Reading fortran [message #45591] |
Tue, 20 September 2005 02:54  |
panblosky
Messages: 17 Registered: May 2005
|
Junior Member |
|
|
Hi all,
does somebody knows how to read this (fortran way)
do 210 j=1,ngr2
write(10) real(rhoc(j)),
2 real(psi1(j)),real(psi2(j)),real(psi3(j))
write(10) aimag(rhoc(j)),
2 aimag(psi1(j)),aimag(psi2(j)),aimag(psi3(j))
210 continue
in IDL? I managed, but it takes forever for big "ngr2". This is what I
do:
rhoc=fltarr(ng3)
psi1=fltarr(ng3) & psi2=fltarr(ng3) & psi3=fltarr(ng3)
For i=0l,ng3-1l do begin
readu,lun,tmp1,tmp2,tmp3,tmp4
rhoc[i]=tmp1
psi1[i]=tmp2
psi2[i]=tmp3
psi3[i]=tmp4
Endfor
but this takes a long time... Anybody knows a fast way?
Thanks!!
|
|
|
Re: Reading fortran [message #64046 is a reply to message #45591] |
Mon, 01 December 2008 07:39  |
Norbert Hahn
Messages: 46 Registered: May 2003
|
Member |
|
|
"R.G. Stockwell" <nothanks@noemail.com> wrote:
>
> "Andres" <panblosky@gmail.com> wrote in message
> news:2ee32df7-524b-4cc9-901f-40ec0fe87288@f40g2000pri.google groups.com...
>> Hi all,
>>
>> perhaps it is an easy one, but I am having problems reading the
>> following in IDL:
>>
>> open(11,file='file_name',form='unformatted')
>> rewind 11
>> do i3=1,np3
>> write(11) ((delta(i1,i2,i3),i1=1,np1),i2=1,np2)
>> end do
>> close(11)
>
> wild guess, but i'd say it looks like you are writing
> a 3D array in binary, and i'll guess it is a floating point number array.
Fortran writes the number of bytes of each logical record implicitly to
the data, so ...
> so in IDL do
>
> datain = fltarr(np1, np2, np3)
>
> openr,1,'filename'
openr,1,'filename', /F77_UNFORMATTED
should be added to make IDL aware of the additional bytes in the records.
Norbert
|
|
|
Re: Reading fortran [message #64058 is a reply to message #45591] |
Fri, 28 November 2008 14:24  |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
"Andres" <panblosky@gmail.com> wrote in message
news:2ee32df7-524b-4cc9-901f-40ec0fe87288@f40g2000pri.google groups.com...
> Hi all,
>
> perhaps it is an easy one, but I am having problems reading the
> following in IDL:
>
> open(11,file='file_name',form='unformatted')
> rewind 11
> do i3=1,np3
> write(11) ((delta(i1,i2,i3),i1=1,np1),i2=1,np2)
> end do
> close(11)
wild guess, but i'd say it looks like you are writing
a 3D array in binary, and i'll guess it is a floating point number array.
so in IDL do
datain = fltarr(np1, np2, np3)
openr,1,'filename'
readu,1,datain
close,1
This won't work, cause you'll have to figure out
byteswapping, and dimension order.
So, make a fake file in fortran so you know what the
data is (numbers like delta[1,1,1] = 111, delta[ 4,8,5] = 485 etc.)
and see what you get. Then simply debug it into existence.
Cheers,
bob
|
|
|
Re: Reading fortran [message #64076 is a reply to message #45591] |
Thu, 27 November 2008 08:39  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Andres writes:
> Yes - I forgot to mention that I was trying to write an IDL code that
> will read that FORTRAN output...
Yes, and we are waiting to see what you came up with so
we can help you. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|
|
Re: Reading fortran [message #64079 is a reply to message #45591] |
Thu, 27 November 2008 08:05  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
Please correct me if I am wrong... it's from old souvenirs...
> perhaps it is an easy one, but I am having problems reading the
> following in IDL:
>
> open(11,file='file_name',form='unformatted')
open the file
> rewind 11
go to the beginning of the file
> do i3=1,np3
> write(11) ((delta(i1,i2,i3),i1=1,np1),i2=1,np2)
> end do
ok, that's the "fun" part. You have 3 loops here.
you could read it as follow:
for i3=1, np3
for i1 = 1, np1
for i2=1, np2
write(i1,i2,i3)
Please double check that I haven't inverter i1 and i3's loops...
Read http://docs.hp.com/cgi-bin/doc3k/B3150190022.12120/15 for more
explanations
Jean
> close(11)
>
> any ideas?
>
> Thanks!!
|
|
|
Re: Reading fortran [message #64080 is a reply to message #45591] |
Thu, 27 November 2008 08:04  |
Peter Clinch
Messages: 98 Registered: April 1996
|
Member |
|
|
Andres wrote:
> perhaps it is an easy one, but I am having problems reading the
> following in IDL:
>
> open(11,file='file_name',form='unformatted')
> rewind 11
> do i3=1,np3
> write(11) ((delta(i1,i2,i3),i1=1,np1),i2=1,np2)
> end do
> close(11)
>
> any ideas?
IDL is a language in itself: it isn't FORTRAN, and it doesn't read FORTRAN.
So you'll need to rewrite the above in IDL. It will be quite similar,
but compilers don't do "similar" :-(
Look at OPENU to read unformatted stuff and FOR to do DO loops.
Pete.
--
Peter Clinch Medical Physics IT Officer
Tel 44 1382 660111 ext. 33637 Univ. of Dundee, Ninewells Hospital
Fax 44 1382 640177 Dundee DD1 9SY Scotland UK
net p.j.clinch@dundee.ac.uk http://www.dundee.ac.uk/~pjclinch/
|
|
|
Re: Reading fortran [message #64081 is a reply to message #45591] |
Thu, 27 November 2008 07:51  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Andres writes:
> perhaps it is an easy one, but I am having problems reading the
> following in IDL:
>
> open(11,file='file_name',form='unformatted')
> rewind 11
> do i3=1,np3
> write(11) ((delta(i1,i2,i3),i1=1,np1),i2=1,np2)
> end do
> close(11)
>
> any ideas?
Uh, that looks like FORTRAN code. Any IDL code to look at?
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|