-
Notifications
You must be signed in to change notification settings - Fork 2
/
gate.param.py
executable file
·80 lines (65 loc) · 2.28 KB
/
gate.param.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
import argparse
'''
run afterwards with
find -name 'autogen*' -exec gate_run_submit_cluster_nomove.sh {} 1 \;
'''
parser = argparse.ArgumentParser(description='launch multiple params.')
parser.add_argument('--mac')
parser.add_argument('--param')
args = parser.parse_args()
def readmac(fn):
f = open(fn)
text = f.read()
f.close()
return text
def readparam(filename,headersize=0):
sourcefile = open(filename,'r')
newarr=[]
for line in sourcefile.readlines()[headersize:]:
try:
newarr.append([float(x) for x in line.strip('\n').replace('--','0').replace(',','.').split()])
except ValueError:
newarr.append([x for x in line.strip('\n').replace('--','0').replace(',','.').split()])
sourcefile.close()
return newarr
paramfile = readparam(args.param)
macfile = readmac(args.mac)
assert args.mac.startswith('param-')
assert args.mac.endswith('.mac')
for val in range(len(paramfile[0]))[1:]:
parstr = ''
parfstr = ''
for par in range(len(paramfile)):
parstr = parstr + '/control/alias ' + paramfile[par][0] + ' ' + paramfile[par][val] + '\n'
parfstr = parfstr + '-' + paramfile[par][0] + '-' + paramfile[par][val]
outname = 'autogen-'+args.mac.replace('.mac','').replace('param-','')+parfstr+'.mac'
#print outname
#print parstr+macfile
with open(outname,'w') as newmacfile:
newmacfile.write(parstr)
newmacfile.write(macfile)
#def popenAndCall(onExit, popenArgs):
#"""
#Runs the given args in a subprocess.Popen, and then calls the function
#onExit when the subprocess completes.
#onExit is a callable object, and popenArgs is a list/tuple of args that
#would give to subprocess.Popen.
#"""
#def runInThread(onExit, popenArgs):
#proc = subprocess.Popen(popenArgs,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
#proc.wait()
#onExit()
#return
#thread = threading.Thread(target=runInThread, args=(onExit, popenArgs))
#thread.start()
## returns immediately after the thread starts
#return thread
#def done():
#print "Finished subprocess!"
#threadlist=[]
#for para in param[0][1:]:
#command = "Gate -a '["+param[0][0]+","+str(para)+"]' "+macfile
#threadlist.append(popenAndCall(done,command))
#for thread in threadlist:
#thread.join()