Hello Olivier,
Alternately, you can try to use the SELAFIN reader/writer that is part of my PPUTILS project. Reading and writing is done as follows:
from ppmodules.selafin_io_pp import *
# read *.slf file
slf = ppSELAFIN('file_to_be_read.slf')
slf.readHeader()
slf.readTimes()
# store into arrays
times = slf.getTimes()
vnames = slf.getVarNames()
vunits = slf.getVarUnits()
float_type,float_size = slf.getPrecision()
NELEM, NPOIN, NDP, IKLE, IPOBO, x, y = slf.getMesh()
# read the variables for the time step 0
slf.readVariables(0)
results = slf.getVarValues()
# write *.slf file
slf2 = ppSELAFIN('file_to_be_written.slf')
slf2.setPrecision(float_type,float_size)
slf2.setTitle('created with pputils')
slf2.setVarNames(vnames)
slf2.setVarUnits(vunits)
slf2.setIPARAM([1, 0, 0, 0, 0, 0, 0, 0, 0, 1])
slf2.setMesh(NELEM, NPOIN, NDP, IKLE, IPOBO, x, y)
slf2.writeHeader()
slf2.writeVariables(0, results)
For many time steps, you'll have to loop accordingly. Lot's of my scripts use the syntax above.
If you want to add another variable, and write it as a SELAFIN file, you would have to:
1. Append variable name list (and add the variable name),
2. Append variable unit list (and add the variable unit),
3. Add a column in the result array (for the time step in question), and
4. Write the result as above using method writeVariables().
I hope it helps,
Pat