MCPcopy Create free account
hub / github.com/AMReX-Astro/Castro / parse_param_file

Function parse_param_file

Util/scripts/write_probdata.py:63–136  ·  view source on GitHub ↗

read all the parameters in the prob_param_files and add valid parameters to the params list. This returns the parameter list.

(params_list, param_file)

Source from the content-addressed store, hash-verified

61
62
63def parse_param_file(params_list, param_file):
64 """read all the parameters in the prob_param_files and add valid
65 parameters to the params list. This returns the parameter list.
66
67 """
68
69 namespace = "problem"
70
71 try:
72 f = open(param_file)
73 except FileNotFoundError:
74 sys.exit(f"write_probdata.py: ERROR: file {param_file} does not exist")
75
76 line = get_next_line(f)
77
78 err = 0
79
80 while line and not err:
81
82 # this splits the line into separate fields. A field is a
83 # single word or a pair in parentheses like "(a, b)"
84 fields = re.findall(r'[\w\"\+\./\-]+|\([\w+\./\-]+\s*,\s*[\w\+\.\-]+\)', line)
85
86 if len(fields) < 3:
87 print("write_probdata.py: ERROR: missing one or more fields in parameter definition.")
88 err = 1
89 continue
90
91 name = fields[0]
92 dtype = fields[1]
93 default = fields[2]
94
95 current_param = rp.Param(name, dtype, default,
96 namespace=namespace)
97
98 # optional field: in namelist
99 try:
100 in_namelist_in = fields[3]
101 if in_namelist_in in ["y", "Y"]:
102 in_namelist = True
103 else:
104 in_namelist = False
105
106 except IndexError:
107 in_namelist = False
108
109
110 # optional field: size
111 try:
112 size = fields[4]
113 except IndexError:
114 size = 1
115
116 current_param.in_namelist = in_namelist
117 current_param.size = size
118
119 # check to see if this parameter is defined in the current
120 # list if we delete the old one and take the new one (we

Callers 1

write_probinFunction · 0.85

Calls 1

get_next_lineFunction · 0.85

Tested by

no test coverage detected