- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm seeing different bit patterns when I write a REAL variable to file as component of a TYPE as opposed to when it's just a REAL in stream output while using the -convert big_endian option. Given the following small program, which opens a file in 'stream' access mode and the proceeds to write two REAL's: [bash]$ cat stream-write.f90[/bash][fortran] PROGRAM foo IMPLICIT NONE TYPE bar real :: x END TYPE bar INTEGER, PARAMETER :: file_id = 20 INTEGER :: ierror REAL :: y TYPE(bar) :: z OPEN(file_id, file="bsob.bin", iostat=ierror, action='write', & form='unformatted', access='stream', status='replace') y = 2.0 z%x = y WRITE(file_id) y WRITE(file_id) z FLUSH(file_id) CLOSE(file_id) END PROGRAM foo [/fortran] and compiling with [bash] $ ifort --version ifort (IFORT) 14.0.2 20140120 Copyright (C) 1985-2014 Intel Corporation. All rights reserved. $ ifort -convert big_endian -o stream-write stream-write.f90 $ ./stream-write $ hexdump bsob.bin 0000000 0040 0000 0000 4000 0000008 [/bash] One can see that the two written quantities are of different endianness. I tested the same program with gfortran 4.7.2 and got consistent bit patterns, i.e.: [bash] $ gfortran -fconvert=big-endian -o stream-write stream-write.f90 $ ./stream-write $ hexdump bsob.bin 0000000 0040 0000 0040 0000 0000008 [/bash] Is this intended? I realize the standard specifies pretty little when it comes to unformatted output. Also programs to read the data compiled by the same compiler could probably read it if TYPE/non-TYPE arguments match the previous WRITEs. But the observed doesn't exactly match my expections. The system involved is a Xeon E5-2665 with Linux 3.11 running in x86_64 mode. Thomas
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for making the first paragraph hard to read it got a prepended from copy&paste, it should have been:
I'm seeing different bit patterns when I write a REAL variable to file as component of a TYPE as opposed to when it's just a REAL in stream output while using the -convert big_endian option.
Given the following small program, which opens a file in 'stream' access mode and the proceeds to write two REAL's:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, this is intended.. You're using the -convert big_endian option, which, when we (as DEC) initially implemented it in the 1980s, did not convert components of structures when you write the whole structure. We still don't. I had thought this was well-documented, but I can't find it at present. gfortran, when it copied our feature, chose to implement this aspect differently.
Nowadays, we really should at least have an option to do this when you're not using the STRUCTURE/UNION extension. I have an open feature request for this (DPD200232660) and will add your request to it.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page