Page MenuHomec4science

grestart
No OneTemporary

File Metadata

Created
Fri, Nov 8, 19:22

grestart

#!/usr/bin/env python
'''
restart a gadget simulation
'''
import sys
import os
import string
try:
from optparse import OptionParser
except ImportError:
from optik import OptionParser
def parse_options():
usage = "usage: %prog [options] file"
parser = OptionParser(usage=usage)
parser.add_option("-p",
action="store",
dest="params",
type="string",
default = 'params',
help="gadget parameter file",
metavar=" FILE")
parser.add_option("-r",
action="store",
dest="runfile",
type="string",
default = 'run',
help="run file",
metavar=" FILE")
(options, args) = parser.parse_args()
if len(args) == 0:
print "you must specify a filename"
sys.exit(0)
file = args[0]
return file,options
######################
# MAIN
######################
# get options
file,options = parse_options()
params = options.params
runfile = options.runfile
# open params file
f = open(params,'r')
lines = f.readlines()
f.close()
# rewrite params file
f = open('params.restart','w')
for line in lines:
wds = string.split(line)
if len(wds) != 0:
if wds[0] == "InitCondFile":
txt = os.path.join(os.path.dirname(wds[1]),file)
txt = string.join(["InitCondFile",'\t\t ',txt,'\n'])
f.write(txt)
else:
f.write(line)
else:
f.write(line)
f.close()
# open run file
f = open(runfile,'r')
line = f.readline()
f.close()
line = string.split(line)
line[-1] = 'params.restart'
line.append('2')
#line.append('&')
line = string.join(line)
os.system(line)

Event Timeline