|
34 | 34 | from build_fortran_tests import build_tests, build_exists |
35 | 35 | from functional_class_with_drivers import FunctionalTestWithDrivers |
36 | 36 | from path_utils import add_cime_lib_to_path |
37 | | -from utils import copy_file, config_to_dict, parse_test_list |
38 | | -from utils import check_param_file, create_param_file, _DEFAULT_CDL_PATH |
| 37 | +from utils import copy_file, create_nc_from_cdl, config_to_dict, parse_test_list |
39 | 38 |
|
40 | 39 | # load the functional test classes |
41 | 40 | from load_functional_tests import * |
|
47 | 46 | # constants for this script |
48 | 47 | _FILE_DIR = os.path.dirname(__file__) |
49 | 48 | _DEFAULT_CONFIG_FILE = os.path.join(_FILE_DIR, "functional_tests.cfg") |
| 49 | +_DEFAULT_CDL_PATH = os.path.abspath( |
| 50 | + os.path.join( |
| 51 | + _FILE_DIR, |
| 52 | + os.pardir, |
| 53 | + "parameter_files", |
| 54 | + "fates_params_default.cdl", |
| 55 | + ) |
| 56 | +) |
50 | 57 | _CMAKE_BASE_DIR = os.path.join(_FILE_DIR, os.pardir) |
51 | 58 | _TEST_SUB_DIR = "testing" |
52 | 59 |
|
@@ -196,6 +203,25 @@ def check_arg_validity(args): |
196 | 203 | raise RuntimeError(f"config 'file' is a directory: '{args.config_file}'") |
197 | 204 |
|
198 | 205 |
|
| 206 | +def check_param_file(param_file): |
| 207 | + """Checks to see if param_file exists and is of the correct form (.nc or .cdl) |
| 208 | +
|
| 209 | + Args: |
| 210 | + param_file (str): path to parameter file |
| 211 | +
|
| 212 | + Raises: |
| 213 | + argparse.ArgumentError: Parameter file is not of the correct form (.nc or .cdl) |
| 214 | + argparse.ArgumentError: Can't find parameter file |
| 215 | + """ |
| 216 | + file_suffix = os.path.basename(param_file).split(".")[-1] |
| 217 | + if not file_suffix in ["cdl", "nc"]: |
| 218 | + raise argparse.ArgumentError( |
| 219 | + None, "Must supply parameter file with .cdl or .nc ending." |
| 220 | + ) |
| 221 | + if not os.path.isfile(param_file): |
| 222 | + raise FileNotFoundError(param_file) |
| 223 | + |
| 224 | + |
199 | 225 | def check_build_dir(build_dir, test_dict): |
200 | 226 | """Checks to see if all required build directories and executables are present |
201 | 227 |
|
@@ -334,6 +360,37 @@ def make_plotdirs(run_dir, test_dict): |
334 | 360 | os.mkdir(sub_dir) |
335 | 361 |
|
336 | 362 |
|
| 363 | +def create_param_file(param_file, run_dir): |
| 364 | + """Creates and/or move the default or input parameter file to the run directory |
| 365 | + Creates a netcdf file from a cdl file if a cdl file is supplied |
| 366 | +
|
| 367 | + Args: |
| 368 | + param_file (str): path to parmaeter file |
| 369 | + run_dir (str): full path to run directory |
| 370 | +
|
| 371 | + Raises: |
| 372 | + RuntimeError: Supplied parameter file is not netcdf (.cd) or cdl (.cdl) |
| 373 | +
|
| 374 | + Returns: |
| 375 | + str: full path to new parameter file name/location |
| 376 | + """ |
| 377 | + if param_file is None: |
| 378 | + print("Using default parameter file.") |
| 379 | + param_file = _DEFAULT_CDL_PATH |
| 380 | + param_file_update = create_nc_from_cdl(param_file, run_dir) |
| 381 | + else: |
| 382 | + print(f"Using parameter file {param_file}.") |
| 383 | + file_suffix = os.path.basename(param_file).split(".")[-1] |
| 384 | + if file_suffix == "cdl": |
| 385 | + param_file_update = create_nc_from_cdl(param_file, run_dir) |
| 386 | + elif file_suffix == "nc": |
| 387 | + param_file_update = copy_file(param_file, run_dir) |
| 388 | + else: |
| 389 | + raise RuntimeError("Must supply parameter file with .cdl or .nc ending.") |
| 390 | + |
| 391 | + return param_file_update |
| 392 | + |
| 393 | + |
337 | 394 | def run_fortran_exectuables(build_dir, test_dir, test_exe, run_dir, args): |
338 | 395 | """Run the generated Fortran executables |
339 | 396 |
|
|
0 commit comments