I have a file write in big-endian format. I wrote a library to access this file. Now I try to use this library to access this file inside a python script. For this I wrote some routines and compile then using f2py. The problem is that in gfortran (a compiler that I use) the options "-fconvert=big-endian" has an effect only when used in the main program, not inside a library. So I can't access correctly this file in python.
Bellow I put a little example to reproduce this issue:
The file "fileTest.bin" was created by this program:
program ttt
implicit none
real(kind=4) :: m(2,2)
m=10.0
open(unit=100,file='fileTeste.bin', form='unformatted')
write(100)m
close(100)
end program
to compile:
gfortran -o ttt.x -fconvert=big-endian ttt.f90
and execute :
./ttt.x
I wrote a test module to read this big-endian file inside python:
module test
implicit none
contains
subroutine openFile(fileName)
character(len=*), intent(in) :: fileName
real(kind=4), allocatable :: array(:,:)
print*,"open File:", trim(fileName)
open(unit=100,file=trim(fileName),form='unformatted')
allocate(array(2,2))
read(100)array
print*,array
end subroutine openFile
end module test
compile using f2py:
f2py -c -m test --f90flags='-fconvert=big-endian' test.f90
load test module inside python:
from test import test as t
a=t.open(teste.bin)
that result in:
open File:fileTeste.bin
1.15705214E-41 1.15705214E-41 1.15705214E-41 1.15705214E-41
So, how can I read a big-endian file using f2py?
thanks !