Using a linux system, I have to compile a program that -in order to work properly- needs to read some input binary files. However, some of the input binary files that need to be read were generated using a big_endian system, whereas other input binary files were generated using a little_endian system.
My question is, if I use -byteswapio for compiling my program, will the resulting excutable file be able to figure it out which of the input files are little_endian and do the swipping while not touching the big_endian input files?
“-byteswapio” will convert all unformatted sequential accesses and all direct access so probably wont work for you. Instead, I would use the PGI “convert” extension to the Fortran OPEN statement. The CONVERT specifier allows you to set the “endianess” of each file you open.
From the PGI Fortran Reference Guide
PGI Fortran Extensions
PGI has extended the OPEN statement as follows:
order is a character expression specifying the byte order of the file. One of ‘BIG_ENDIAN’, ‘LITTLE_ENDIAN’, or ‘NATIVE’ is allowed.
The CONVERT specifier allows byte-swapping I/O to be performed on specific logical units. The value ‘BIG_ENDIAN’ is used to convert big-endian format data files produced by most RISC workstations and highend servers to the little-endian format used on Intel Architecture systems on-the-fly during file reads/writes. This value assumes that the record layouts of unformatted sequential access and direct access files are the same on the systems. For the values ‘LITTLE_ENDIAN’ and 'NATIVE’, byte-swapping is not performed during
file reads/writes since the little-endian format is used by the x86 architecture.
Hope this helps,