Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28765 Discussions

how to read a binary file written in SGI

cyq858
Beginner
702 Views
I need to read a binary file in LINUX IA64 which was written by a fortran compilerin SGI, anybody knows how to reada binary file in linux ia64transferred from SGI? THANKS.
0 Kudos
6 Replies
TimP
Honored Contributor III
702 Views
With SGI, there are several possibilities. Their Fortran supports either a C compatible sequential form, or Fortran sequential or direct access. I believe all of the binary file formatsare big-endian,same asother Unix platforms, even though the hardware is not.
0 Kudos
cyq858
Beginner
702 Views

thanks, but I am still confused. eg. I write a real*8 variable in a binary file using fortran in SGI, how can I read it correctly using fortran in linux ia64? thanks.in In SGI,

u=1.2d-5

open(1,FILE=filename,FORM='UNFORAMTTED',ACTION='WRITE')

write(1) u

And then in Linux IA64,

open(1,FILE=filename,FORM='BINARY',ACTIONON='READ')

read(1) u

.but I can not get the value correctly, what is the problem?

0 Kudos
Intel_C_Intel
Employee
702 Views
If SGI machines are indeed big endian (I don't know), then
compile your code on the ia64 box with '-convert big_endian'.
This will tell the compiler to read/write the files as
big_endian instead of the the default little_endian.

Craig
0 Kudos
TimP
Honored Contributor III
702 Views
'BINARY' is a non-standard Fortran format which is more compatible with C. If you want to use that on the Intel side, you should use the equivalent on the SGI side (not standard Fortran unformatted). It may be called 'binary' there too; my memory isn't that good. You still have to reverse the byte order within each data item. There are options in Intel Fortran to open the file as a big-endian file, which should do the job.
0 Kudos
Steven_L_Intel1
Employee
702 Views
I think Craig has the right idea. You can now use CONVERT='BIG_ENDIAN' in OPEN as well. This will properly interpret the record lengths and do the byte swap of integer and real data. The caveat is that you have to list the variables directly in the I/O list - you can't use a record or derived type.
0 Kudos
cyq858
Beginner
702 Views

Yes, after I add CONVERT='BIG_ENDIAN', it works. thank you, guys, this is the first time I ask questions in this forum, and I really appreciate your help.

0 Kudos
Reply