Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems using Fortran Binary Files as inputs #247

Open
ingwag opened this issue Feb 24, 2025 · 0 comments
Open

Problems using Fortran Binary Files as inputs #247

ingwag opened this issue Feb 24, 2025 · 0 comments

Comments

@ingwag
Copy link

ingwag commented Feb 24, 2025

Hi,

I was trying to use aronnax for some eddy simulations and wanted to use fortran binary files similar to how you do it in mitgcm.
However, I can't get it to work.
I am generating the fields in python and then save them as binary files.
When I try to save the files with the numpy .astype('>f8').tofile('fname') the aronnax driver returns with the error:

FortranFormattingError: End of file in the middle of a record

I also tried to write my own write function that adheres to the fortran binary format.

def write_binary(fname,array):
    ''' writes an unformatted binary fortran file one row at a time'''
    with open(fname,'wb') as f:
        for j in range(array.shape[1]):
            row_data = array[:,j].tobytes()
            record_size = len(row_data)
            f.write(struct.pack("i", record_size))
            f.write(row_data)  # Write the actual data
            f.write(struct.pack("i", record_size))

With this aronnax.driver doesn't complain anymore. But now the fortran routines crash.

At line 226 of file src/io.f90 (unit = 10, file = 'input/init_h_file.bin')
Fortran runtime error: I/O past end of record on unformatted file


Error termination. Backtrace:
#0  0x7f10eafabe59 in ???

[aronnax_minimal.zip](https://github.com/user-attachments/files/18942139/aronnax_minimal.zip)

#1  0x7f10eafaca71 in ???
#2  0x7f10eafad6dc in ???
#3  0x7f10eb248149 in ???
#4  0x7f10eb24308b in ???
#5  0x55abc304f6ec in __io_MOD_read_input_fileh
        at src/io.f90:226
#6  0x55abc3062169 in aronnax
        at src/aronnax.f90:241
#7  0x55abc303b29e in main
        at src/aronnax.f90:35

I am assuming something about how I write the fortran files is wrong. But then again this method .astype('>f8').tofile('fname') has worked for me in mitgcm.

I have attached a python script to generate the data (gendata_minimal.py), my aronnax.conf and the script to run the model (run_minimal.py).
aronnax_minimal.zip

Best regards,
Ingo

PS: I am running the latest aronnax master on ubuntu 24.04 with an intel i7-1365U CPU. Drivers and libraries should all be up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant