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)
| 61 | |
| 62 | |
| 63 | def 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 |
no test coverage detected