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

Home » Public Forums » archive » Re: Use IDL6.0 to read Fortran 90 written data
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Use IDL6.0 to read Fortran 90 written data [message #55189] Tue, 07 August 2007 20:52
Nianming Zuo is currently offline  Nianming Zuo
Messages: 13
Registered: August 2007
Junior Member
Thank you, Paul, David, Mike, chl and other guys.
I have read the links (and other related links), and it is really
helpful for my puzzels.

And now, I have another problem. (The following are on MS Windows
XP(sp2))

IDL6.0 can not read data saved by gcc3.4. (Mingw32)

in "gccfile.dat", I saved a seriers of data, including int and float
type, using
gf = fopen("gccfile.dat", "w");
fwrite(NLAM, sizeof(int),1, gf);
//repeat this sentence to store several vars,
NLAM,R,D,H,ALAM0,ALAM1,DLAM , with different type.

Now, I want to read datas in "gccfile.dat", and I have tried many
methods.

Way 1:
openr, lun, "gccfile.dat", /GET_LUN
readu,lun,NLAM,R,D,H,ALAM0,ALAM1,DLAM
print, NLAM,R,D,H,ALAM0,ALAM1,DLAM

It prints strange data like 3.36641e+038, and prompts:
% Program caused arithmetic error: Floating underflow
% Program caused arithmetic error: Floating illegal operand

Way 2: (learn from this forum. THANKS :) )

openr, lun, "gccfile.dat", /GET_LUN, /SWAP_ENDIAN
readu,lun,NLAM,R,D,H,ALAM0,ALAM1,DLAM
print, NLAM,R,D,H,ALAM0,ALAM1,DLAM

It still prints the garbage!

I have tested the endian-ness things with (from Paul. Thanks):

openr,lun,'shepp.sgm', /GET_LUN ; "shepp.sgm" is my file.
; -- Check the record size
RecordSize = 10000L * 4L
RecordSize_Test = 0L
READU, lun, RecordSize_Test
IF ( RecordSize_Test NE RecordSize ) THEN $
Swap = 1 $
ELSE $
Swap = 0

; -- Close the file
FREE_LUN, lun

print, "Swap", Swap

; The above Swap turns out 1. So swap is necessary.


Way 3:


openr, lun, "gccfile.dat", /GET_LUN ; Without /SWAP_ENDIAN
readu,lun,NLAM,R,D,H,ALAM0,ALAM1,DLAM
NLAM = SWAP_ENDIAN(NLAM)
print, NLAM,R,D,H,ALAM0,ALAM1,DLAM

Amazingly, NLAM (integer) is wrong, and other vars (float) are right!

I am totally confused by its behavious!


Additionally, I have tried another ways, and did't take effect.
byteorder, NLAM,R,D,H,ALAM0,ALAM1,DLAM, /lswap

One suggested "binread" function, but it doesn't exist in IDL6.0.


Thanks,

Tony

On 8 7 , 8 39 , Paul van Delst <Paul.vanDe...@noaa.gov> wrote:
> Nianming Zuo wrote:
>> Dear all,
>
>> I have sufferred file read/write problems between Fortran 90/95 and
>> IDL 6.0.
>
>> My Fortran compiler:
>> Silverfrost ftn95, Compatable for Fortran 77/90/95
>> http://www.silverfrost.com/12/ftn95/ftn95_feature_details.as p
>
>> IDL 6.0 (Interactive Data Language, RSI)
>
>> Both are in MS Windows XP(sp2) OS system.
>
>> Write data to a file by use of Fortran:
>> dimension dat(m, n)
>> !........ Manipulations..., matrix dat(m, n) is float
>> open(unit=11, file="file.dat", form="unformatted")
>> write(11) dat
>> !..........
>> ! The above are really f77 code, so I guess it is related to Compiler.
>
>> Read the data above by IDL6.0: (Way 1)
>> dat = fltarr(m,n)
>> openr, 1, 'file.dat'
>> readu, 1, b, dat, b
>
>> In "readu, 1, b, dat, b", the "b"s are used to skip the record area in
>> Fortran data format.
>> Unfortunately, it can not get the right result, and prompts "End of
>> the file"
>
>> I have also tried another way in IDL: (Way 2)
>> dat = fltarr(m,n)
>> openr, 1, 'file.dat' /f77_unformatted
>> readu, 1, dat
>
>> But, it prompts,
>> "% READU: Corrupted f77 unformatted file detected. "
>
>> For the above Fortran code, when it is compied by g77, IDL can read it
>> by Way 2.
>
>> So, I doubt that different compilers give different response to the
>> standard Fortran sentences ?
>> Since there is no f90_unformatted or f95_unformatted, f77/f90/f95 will
>> produce the same record for the "open-write" sentence.
>
>> Now, how can I read ftn95 compiled output data by IDL6.0 ? I have
>> searched this forum, but without any desirable results.
>
> Have a lookee at:
>
> http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thr...
>
> (Crikey that's a long link)
>
> cheers,
>
> paulv- -
>
> - -
Re: Use IDL6.0 to read Fortran 90 written data [message #55208 is a reply to message #55189] Tue, 07 August 2007 10:57 Go to previous message
Carsten Lechte is currently offline  Carsten Lechte
Messages: 124
Registered: August 2006
Senior Member
David Fanning wrote:
>> (Crikey that's a long link)
>
> Try tinyurl.com. ;-)

Unless one opposes this obfuscation of information on principle;-)


chl
Re: Use IDL6.0 to read Fortran 90 written data [message #55215 is a reply to message #55208] Tue, 07 August 2007 09:58 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Aug 7, 7:11 am, Paul van Delst <Paul.vanDe...@noaa.gov> wrote:
> David Fanning wrote:
>> Paul van Delst writes:
>
>>> Have a lookee at:
>
>>> http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thr...
>
>>> (Crikey that's a long link)
>
>> Try tinyurl.com. ;-)
>
> Thought about it, but two steps too many...
>
> :o)

There is a TinyUrl bookmarklet which you could put in your favorites
bar. That would make it only one extra click.

Mike
--
www.michaelgalloy.com
Re: Use IDL6.0 to read Fortran 90 written data [message #55224 is a reply to message #55215] Tue, 07 August 2007 06:11 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> Paul van Delst writes:
>
>> Have a lookee at:
>>
>> http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thread/513c48ceb53e6933/57c16d337a1aea99?lnk=gst&q =unformatted+endian&rnum=1&hl=en#57c16d337a1aea99
>>
>>
>> (Crikey that's a long link)
>
> Try tinyurl.com. ;-)

Thought about it, but two steps too many...

:o)
Re: Use IDL6.0 to read Fortran 90 written data [message #55225 is a reply to message #55224] Tue, 07 August 2007 05:46 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> Have a lookee at:
>
> http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thread/513c48ceb53e6933/57c16d337a1aea99?lnk=gst&q =unformatted+endian&rnum=1&hl=en#57c16d337a1aea99
>
>
> (Crikey that's a long link)

Try tinyurl.com. ;-)

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: Use IDL6.0 to read Fortran 90 written data [message #55226 is a reply to message #55225] Tue, 07 August 2007 05:39 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Nianming Zuo wrote:
> Dear all,
>
> I have sufferred file read/write problems between Fortran 90/95 and
> IDL 6.0.
>
> My Fortran compiler:
> Silverfrost ftn95, Compatable for Fortran 77/90/95
> http://www.silverfrost.com/12/ftn95/ftn95_feature_details.as p
>
> IDL 6.0 (Interactive Data Language, RSI)
>
> Both are in MS Windows XP(sp2) OS system.
>
> Write data to a file by use of Fortran:
> dimension dat(m, n)
> !........ Manipulations..., matrix dat(m, n) is float
> open(unit=11, file="file.dat", form="unformatted")
> write(11) dat
> !..........
> ! The above are really f77 code, so I guess it is related to Compiler.
>
>
> Read the data above by IDL6.0: (Way 1)
> dat = fltarr(m,n)
> openr, 1, 'file.dat'
> readu, 1, b, dat, b
>
> In "readu, 1, b, dat, b", the "b"s are used to skip the record area in
> Fortran data format.
> Unfortunately, it can not get the right result, and prompts "End of
> the file"
>
> I have also tried another way in IDL: (Way 2)
> dat = fltarr(m,n)
> openr, 1, 'file.dat' /f77_unformatted
> readu, 1, dat
>
> But, it prompts,
> "% READU: Corrupted f77 unformatted file detected. "
>
> For the above Fortran code, when it is compied by g77, IDL can read it
> by Way 2.
>
> So, I doubt that different compilers give different response to the
> standard Fortran sentences ?
> Since there is no f90_unformatted or f95_unformatted, f77/f90/f95 will
> produce the same record for the "open-write" sentence.
>
>
> Now, how can I read ftn95 compiled output data by IDL6.0 ? I have
> searched this forum, but without any desirable results.

Have a lookee at:

http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thread/513c48ceb53e6933/57c16d337a1aea99?lnk=gst&q =unformatted+endian&rnum=1&hl=en#57c16d337a1aea99


(Crikey that's a long link)

cheers,

paulv
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: efficiency of eigenvalue calculations
Next Topic: Locking sav files

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

Current Time: Sun Oct 12 19:44:55 PDT 2025

Total time taken to generate the page: 0.15992 seconds