The most important part is that you understand how the bin file works. It stores each field of md
in binary format (using the marshall
function of each subclass, which calls src/m/solve/WriteData.m
). The order of the fields does not matter. Each field starts with:
- field name (e.g.,
md.initialization.vx
)
- length of the field
- the field itself
You should take a look at scripts/BinRead.py
to understand how the file is written. For example, if you want to add a new field to the bin file, you could do this:
from struct import error, pack
fid = open("inputfile.bin", "ab")
# 1: Write field name
name="md.NewField"
fid.write(pack('i', len(name)))
fid.write(pack('{}s'.format(len(name)), name.encode()))
# 2: Write length of record
fid.write(pack('q', 4 + 4)) #1 integer + code
fid.write(pack('i', 2)) #2 means Integer for ISSM
# 3: Write data (here 20, but could be anything)
fid.write(pack('i', int(20)))
#done!
fid.close()
You can check that it is there by running:
$ISSM_DIR/scripts/BinRead.py -f inputfile.bin
I hope this helps you get started! Maybe a natural next step would be to change a field, like md.timestepping.final_time
, you will need to find where “md.timestepping.final_time” is (with seek
), and then replace its value (the “Code” for “Double” is 3, I think you used 2 for an integer:
# 2: Write length of record
fid.write(pack('q', 8 + 4)) #1 double + code
fid.write(pack('i', 3)) #3 means Double for ISSM
# 3: Write data
fid.write(pack(‘d', NEWFINALTIMEVALUE))
Cheers
Mathieu