- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I want to know how to read a binary file created by ifort in g77 compilar.
I compiled the following code with ifort, e.g.
pi = ATAN(1.d0)*4.d0
pi2 = 3.141592653589793d0
OPEN(10,FILE='rfile',FORM='UNFORMATTED')
WRITE(10) pi, pi2
CLOSE(10)
without options, and after creating 'rfile' I try to read 'rfile' with g77 as
OPEN(10,FILE='rfile',FORM='UNFORMATTED')
READ(10) pi, pi2
CLOSE(10)
WRITE(*,*) pi, pi2
but the output result is wrong,
3.14159274 1.12103877E-44
Is some paticular options needed in ifort ?
I want to know how to read a binary file created by ifort in g77 compilar.
I compiled the following code with ifort, e.g.
pi = ATAN(1.d0)*4.d0
pi2 = 3.141592653589793d0
OPEN(10,FILE='rfile',FORM='UNFORMATTED')
WRITE(10) pi, pi2
CLOSE(10)
without options, and after creating 'rfile' I try to read 'rfile' with g77 as
OPEN(10,FILE='rfile',FORM='UNFORMATTED')
READ(10) pi, pi2
CLOSE(10)
WRITE(*,*) pi, pi2
but the output result is wrong,
3.14159274 1.12103877E-44
Is some paticular options needed in ifort ?
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you using the x64 version of g77? If so, the answer is "no". Please use gfortran instead (or use ifort!)
32-bit g77 should be the same as ifort for this program.
32-bit g77 should be the same as ifort for this program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The second number output, 1.12103877E-44, if single precision (4-byte), has the internal representation '00000008'. A record-length marker was read as data, which implies that there is a mismatch between writer and reader programs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This very strongly suggests that it is indeed a 64-bit g77 which always uses 8-byte record lengths. Intel Fortran doesn't do this and neither does gfortran nowadays. (Who still uses g77???)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, steve
I am using 64-bit g77, which is gcc version 3.4.6 20060404 (Red Hat 3.4.6-18),
When I modify the example code as
ifort:
REAL*8 pi, pi2
pi = ATAN(1.d0)*4.d0
pi2 = 3.141592653589793d0
OPEN(10,FILE='rfile',FORM='UNFORMATTED')
WRITE(10) pi, pi2
CLOSE(10)
g77:
REAL*8 pi, pi2
OPEN(10,FILE='rfile',FORM='UNFORMATTED')
READ(10) pi, pi2
CLOSE(10)
WRITE(*,*) pi, pi2
then I have
8.61919951E+97 3.44827273E-313
Does ifort add the extra bit into header of binary file ?
I am using 64-bit g77, which is gcc version 3.4.6 20060404 (Red Hat 3.4.6-18),
When I modify the example code as
ifort:
REAL*8 pi, pi2
pi = ATAN(1.d0)*4.d0
pi2 = 3.141592653589793d0
OPEN(10,FILE='rfile',FORM='UNFORMATTED')
WRITE(10) pi, pi2
CLOSE(10)
g77:
REAL*8 pi, pi2
OPEN(10,FILE='rfile',FORM='UNFORMATTED')
READ(10) pi, pi2
CLOSE(10)
WRITE(*,*) pi, pi2
then I have
8.61919951E+97 3.44827273E-313
Does ifort add the extra bit into header of binary file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
64-bit g77 uses a 64-bit record length all the time. This is not the way most other 64-bit Fortran compilers on Linux/Unix work. There is no option in ifort to write record lengths compatible with 64-bit g77.
ifort has options of writing binary files without any record lengths, but I don't know if g77 can read them.
You are using a five-year-old version of gcc. A more recent one would include gfortran that can read and write unformatted files compatible with ifort.
ifort has options of writing binary files without any record lengths, but I don't know if g77 can read them.
You are using a five-year-old version of gcc. A more recent one would include gfortran that can read and write unformatted files compatible with ifort.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Your suggestion makes sense. I confirmed gfortran can read correctly.
(but using old version of gfortran, option -frecord-marker=4 will be needed.)
BTW I found that using stream access in ifort, e.g.
REAL*8 pi, pi2
OPEN(10,FILE='rfile',FORM='unformatted',access='stream')
WRITE(10,POS=9) pi, pi2
CLOSE(10)
g77 can read it correctly. But I do not know it is general or just this case.
Eigo
Your suggestion makes sense. I confirmed gfortran can read correctly.
(but using old version of gfortran, option -frecord-marker=4 will be needed.)
BTW I found that using stream access in ifort, e.g.
REAL*8 pi, pi2
OPEN(10,FILE='rfile',FORM='unformatted',access='stream')
WRITE(10,POS=9) pi, pi2
CLOSE(10)
g77 can read it correctly. But I do not know it is general or just this case.
Eigo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmm - what you're doing is skipping over what g77 wants for the record length but doesn't it complain when it doesn't find a valid length?
If you don't use POS= you can write just the data. Perhaps g77 has a way of dealing with that, I don't know. Why are you insisting on using g77 when you have gfortran?
If you don't use POS= you can write just the data. Perhaps g77 has a way of dealing with that, I don't know. Why are you insisting on using g77 when you have gfortran?
![](/skins/images/D3C0B914909A6564BBB97F4AD1ED1973/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page