Fortran Big-Endian/Little-Endian Error
The big-endian/little-endian error occurs when Fortran reads and writes binary files. The error is difficult to detect in the early compilation phase and causes abnormal data read in the subsequent program running test. As a result, core dump occurs during program running or the calculation result is incorrect. Therefore, you are advised to sort out the binary file read/write process in the program before the porting to check whether big-endian/little-endian error caused by platform differences exists.
For example:
When porting code from the IBM (PowerPC) platform (big-endian) to the Kunpeng platform (little-endian), pay attention to the conversion of big-endian and little-endian. The conversion method is as follows:
- Method 1: Add the -fconvert=big-endian compilation option to GFortran to use the big-endian byte order.
- Method 2: Add convert='big_endian' to the OPEN statement.
OPEN(11,file=TRIM(bin_name),status='old',access='direct',form="Unformatted",&recl=181*360*124*4,convert='big_endian',IOSTAT=io_err)
Parent topic: Common Problems (Architecture Differences)