I might be able to help you with that:
Here is a python script I use to keep only the
last timestep:
from parsers.parserFortran import cleanQuotes
from runSELAFIN import alterSELAFIN
slf = SELAFIN(spefile)
names = slf.VARNAMES
frames = slf.tags['times']
tmax = max(frames)
for i,var in enumerate(names):
i += 1
#print i,var,tmax
vars = cleanQuotes(var.replace('_',' '))
#~~> times = (tfrom,tstep,tstop)
slf1 = alterSELAFIN( spefile, times = (tmax,0,tmax), vars = vars, root=None )
#~~> Reset time to 0
slf1.alterTIMES(pT=-tmax)
# write *.slf file
name, ext = os.path.splitext(spefile)
new_filename = '{}_{}{}'.format(name,i,ext)
slf1.putContent( new_filename )
del slf1
In alterSELAFIN "times = (tmax,0,tmax)", the arguments are (start_step, step, last_step) so you can adjust accordingly...
You should also add a loop for all selafin file in a directory matching a pattern like it is done here:
def PurgeOld(dir):
'''
Deletes files in given directory that contain *old*
'''
import os,re
pattern = '[_]old\d{1,}\.(slf|spe|glob)$'
try:
for f in os.listdir(dir):
if re.search(pattern, f):
os.remove(os.path.join(dir, f))
except:
pass
return
Regards,
Costas