|
5 | 5 | import os |
6 | 6 | from make_bcs_questionary import * |
7 | 7 | from make_bcs_shared import * |
8 | | -import re |
9 | 8 | from datetime import datetime |
10 | 9 | import subprocess |
11 | 10 |
|
12 | | -def _resolve_versions(bcs_version: str): |
13 | | - """ |
14 | | - Returns (mom6_bathy_version, topo_version) as 'v1' or 'v2' |
15 | | - Rule: v14+ -> v2; else -> v1. Non-numeric (NL3, ICA, GM4...) -> v1. |
16 | | - """ |
17 | | - v = (bcs_version or "").strip() |
18 | | - m = re.match(r'[vV]?(\d+)', v) |
19 | | - vnum = int(m.group(1)) if m else None |
20 | | - use_v2 = vnum is not None and vnum >= 14 |
21 | | - return ("v2" if use_v2 else "v1", "v2" if use_v2 else "v1") |
22 | | - |
23 | | -def _build_mom6_link_lines(inputdir: str, preferred_version: str) -> str: |
24 | | - """ |
25 | | - Build csh lines to symlink MOM6 datasets. |
26 | | - Prefer `preferred_version` (v1 or v2) per size; if missing, fall back to the other version. |
27 | | - Emits an echo note on fallback; warns if a size is missing in both. |
28 | | - """ |
29 | | - sizes = ["72x36", "540x458", "1440x1080"] |
30 | | - other = "v1" if preferred_version == "v2" else "v2" |
31 | | - |
32 | | - lines = ['if ( ! -d data/MOM6 ) mkdir -p data/MOM6'] |
33 | | - for size in sizes: |
34 | | - src_pref = os.path.join(inputdir, "ocean", "MOM6", preferred_version, size) |
35 | | - src_other = os.path.join(inputdir, "ocean", "MOM6", other, size) |
36 | | - |
37 | | - if os.path.isdir(src_pref): |
38 | | - src = src_pref |
39 | | - note = "" |
40 | | - elif os.path.isdir(src_other): |
41 | | - src = src_other |
42 | | - note = f'echo "NOTE: MOM6 {preferred_version}/{size} not found; using {other}/{size}"' |
43 | | - else: |
44 | | - lines.append(f'echo "WARNING: MOM6 {size} missing in both v1 and v2; skipping"') |
45 | | - continue |
46 | | - |
47 | | - lines.append(f'if ( -e data/MOM6/{size} ) /bin/rm -f data/MOM6/{size}') |
48 | | - if note: |
49 | | - lines.append(note) |
50 | | - lines.append(f'ln -s {src} data/MOM6/{size}') |
51 | | - return "\n".join(lines) |
52 | | - |
53 | 11 | cube_template = """ |
54 | 12 |
|
55 | 13 | ln -s {MAKE_BCS_INPUT_DIR}/ocean/MOM5/360x200 data/MOM5/360x200 |
56 | 14 | ln -s {MAKE_BCS_INPUT_DIR}/ocean/MOM5/720x410 data/MOM5/720x410 |
57 | 15 | ln -s {MAKE_BCS_INPUT_DIR}/ocean/MOM5/1440x1080 data/MOM5/1440x1080 |
58 | | -{MOM6_LINK_LINES} |
| 16 | +if ( {TRIPOL_OCEAN} == True ) then |
| 17 | + set mom6v = {mom6_bathy_version} |
| 18 | + set mom6root = {MAKE_BCS_INPUT_DIR}/ocean/MOM6/$mom6v |
| 19 | + set req = {imo}x{jmo} |
| 20 | +
|
| 21 | + if ( ! -d $mom6root/$req ) then |
| 22 | + echo "ERROR: MOM6/$mom6v/$req missing under {MAKE_BCS_INPUT_DIR}/ocean/MOM6" |
| 23 | + echo " Selected via questionnaire '{lbcsv}' -> MOM6_BATHY_VERSION=$mom6v" |
| 24 | + exit 10 |
| 25 | + endif |
| 26 | +
|
| 27 | + if ( ! -d data/MOM6 ) mkdir -p data/MOM6 |
| 28 | + if ( -e data/MOM6/$req ) /bin/rm -f data/MOM6/$req |
| 29 | + ln -s $mom6root/$req data/MOM6/$req |
| 30 | +endif |
59 | 31 |
|
60 | 32 |
|
61 | 33 | if( -e CF{NC}x6C{SGNAME}_{DATENAME}{IMO}x{POLENAME}{JMO}.stdout ) /bin/rm -f CF{NC}x6C{SGNAME}_{DATENAME}{IMO}x{POLENAME}{JMO}.stdout |
@@ -180,8 +152,30 @@ def make_bcs_cube(config): |
180 | 152 | if not os.path.exists(log_dir): |
181 | 153 | os.makedirs(log_dir) |
182 | 154 |
|
183 | | - MOM6_BATHY_VERSION, TOPO_VERSION = _resolve_versions(config['lbcsv']) |
184 | | - MOM6_LINK_LINES = _build_mom6_link_lines(config['inputdir'], MOM6_BATHY_VERSION) |
| 155 | + TOPO_VERSION = topo_version_for_bcs(config['lbcsv']) |
| 156 | + MOM6_BATHY_VERSION = mom6_bathy_version_for_bcs(config['lbcsv']) |
| 157 | + |
| 158 | + # ---------- INPUT CHECKS (abort before sbatch) ---------- |
| 159 | + # 1) TOPO must exist for this grid |
| 160 | + topo_dir = f"CF{NC}x6C{SGNAME}" # CF0090x6C or CF0540x6C-SG001 |
| 161 | + topo_src = os.path.join(config['inputdir'], "atmosphere", "TOPO", TOPO_VERSION, topo_dir) |
| 162 | + if not os.path.isdir(topo_src): |
| 163 | + print(f"ABORT: Missing TOPO: {topo_src} " |
| 164 | + f"(LBCSV={config['lbcsv']} TOPO_VERSION={TOPO_VERSION})") |
| 165 | + return |
| 166 | + |
| 167 | + # 2) MOM6 bathymetry: strict, check ONLY the size used by this run |
| 168 | + if config["TRIPOL_OCEAN"]: |
| 169 | + req = f"{config['imo']}x{config['jmo']}" # 540x458 or 1440x1080 |
| 170 | + mom6_src = os.path.join(config['inputdir'], "ocean", "MOM6", MOM6_BATHY_VERSION, req) |
| 171 | + if not os.path.isdir(mom6_src): |
| 172 | + print(f"ABORT: Missing MOM6 bathymetry: {mom6_src} " |
| 173 | + f"(LBCSV={config['lbcsv']} MOM6={MOM6_BATHY_VERSION})") |
| 174 | + return |
| 175 | + |
| 176 | + print(f"[make_bcs_cube] LBCSV={config['lbcsv']} TOPO={TOPO_VERSION} " |
| 177 | + f"MOM6={MOM6_BATHY_VERSION} REQ={'{imo}x{jmo}'.format(**config)} GRID={GRIDNAME}") |
| 178 | + # ------------------------------------------------------------------- |
185 | 179 |
|
186 | 180 | script_template = get_script_head() + cube_template + get_script_mv(config['grid_type']) |
187 | 181 |
|
@@ -223,7 +217,6 @@ def make_bcs_cube(config): |
223 | 217 | SGPARAM = SGPARAM, \ |
224 | 218 | TOPO_VERSION = TOPO_VERSION, |
225 | 219 | mom6_bathy_version = MOM6_BATHY_VERSION, |
226 | | - MOM6_LINK_LINES = MOM6_LINK_LINES, |
227 | 220 | IS_STRETCHED = IS_STRETCHED, \ |
228 | 221 | NCPUS = config['NCPUS']) |
229 | 222 |
|
|
0 commit comments