forked from MarkKJones/deut_simc
-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_defaults.py
50 lines (47 loc) · 1.35 KB
/
get_defaults.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
#
# create namelist datafile
#
def make_type(x, type):
if type == 'int':
return int(x)
if type == 'double':
return float(x)
if type == 'doublearray':
return float(x)
# end
d = open('nml_defaults.data').readlines()
o = open('namelist.data','w')
found_set = False
first = True
for l in d:
blank = (len(l.split()) == 0)
if l.find('*') >= 0:
if not first :
o.write(' / \n')
first = False
found_set = True
name = l.split()[1]
print 'namelist : ', name
lo = ' &' + name
o.write(lo + '\n')
elif found_set and ( not blank):
data = l.split(',')
type = l.split('regparm')[1].split('(')[0]
if len(data) == 3:
var_name = data[-2:-1][0]
var_val = data[-1:][0].split(')')[0]
# lc = '! type: '+ type
lo = ' ' + var_name + ' = '+ var_val
# o.write(lc + '\n')
o.write(lo + '\n')
elif len(data) == 4:
var_name = data[-3:-2][0]
var_val = (data[-2:-1][0], data[-1:][0].split(')')[0])
# lc = '! type: '+ type
lo = ' ' + var_name + ' = '+ var_val[0] + ', ' + var_val[1]
# o.write(lc + '\n')
o.write(lo + '\n')
print 'variable : ', var_name, var_val, type
# done
o.write(' / \n')
o.close()