I don't have working knowledge of Fortran, nor am I an advanced user of Python(2), so please bear that in mind and please be understanding!
I'm trying to write some data into a binary file with Python2 (opened an empty binary file with "wb"), which has to be opened as an "unformatted" file in Fortran (a .f90 file). The thing is, such a Python-generated binary file can be read (in Fortran) if I have, when opening the file in Fortran,
"form='unformatted'", and "access='stream'".
I am hoping to write a binary file in Python 2 such that I do not need "access='stream'". I am using this binary file in conjunction with a massive nonpublic code in Fortran (which I did not develop), and would like to not touch the source code at all. I only made changes as a test for myself.
If I do not use "access='stream'", then I just get nonsensical values that are output.
I was using the below before (byteswap() for changing endianness) to write the binary file, to no avail.
dxidxup = 1/dxm
dxidxup = np.array(dxidxup,dtype='<f4')
dxidxup_write = dxidxup.byteswap()
dxidxup_write.tofile(new_mesh)
I also tried to use np.ascontiguousarray and np.asfortranarray to write the data to the binary file, but it did not work either.
dxidxup = 1/dxm
dxidxup = np.array(dxidxup)
dxidxup = np.ascontiguousarray(dxidxup,dtype='<f4')
dxidxup_write = dxidxup.byteswap()
dxidxup_write.tofile(new_mesh)
I have tried struct.pack too, as per this link. I am not sure what other avenue to best pursue... I appreciate thoughts/inputs!
I hope that all made sense..