Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91188653
grestart
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 8, 19:22
Size
1 KB
Mime Type
text/x-python
Expires
Sun, Nov 10, 19:22 (2 d)
Engine
blob
Format
Raw Data
Handle
22215043
Attached To
rGTOOLS Gtools
grestart
View Options
#!/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
Log In to Comment