I have code written in Fortran and I would like to convert it to Python. I understand the flow of the code but when I wrote the code in Python, the outputs of the codes did not match.
So, after debugging I found out that the difference is coming from the first part of the code and I don't understand it. I think the way in which the two codes open and read the file are different because I don't think there is any problem with the seek() command. My file is a binary file and it is too large to attach it here.
Here are the first 10 outputs I am getting from Python: [1]: https://i.stack.imgur.com/KGXlI.png
Here is the first 10 outputs from Fortran: [2]: https://i.stack.imgur.com/wvlui.png
The first part of the two codes are pasted below:
open(1,file='ca48_exp_010.mvmelst',ACCESS='STREAM')
call fseek(1,8,0) ! offset 8 bytes from beginning
nsection=0
continueReading= .true.;
do while(continueReading)
read(1) sectionHeader
print *, sectionHeader
Python version:
with open('ca48_exp_010.mvmelst',mode='rb') as f:
f.seek(8,0)
nsection = 0
continueReading = True
while continueReading:
sectionHeader = f.read(4) # read 4 bytes at a time
if not sectionHeader:
continueReading = False
sectionHeader = int.from_bytes(sectionHeader, byteorder="big")
print(sectionHeader)