Below is the clean, NOAA-style way to run domain forecast arrays in PBS, using one array dimension = domains (CONUS, AK, HI, PR, etc.). This is the correct operational pattern.

🧠 Concept: Domain → Array Index

Each PBS array task = one domain
Your Python (or plotting) code stays domain-agnostic.

✅ Example: CPC GFS Domain Forecast Arrays
Domains
Index  Domain
0      CONUS
1      AK
2      HI
3      PR
4      GU

✅ PBS Script (domain array)
gfs_domain.pbs
#!/bin/bash
#PBS -N gfs_domain_fcst
#PBS -A CPC-DEV
#PBS -q dev
#PBS -l select=1:ncpus=4:mem=8GB
#PBS -l walltime=00:10:00
#PBS -J 0-4
#PBS -r y
#PBS -j oe

cd $PBS_O_WORKDIR

# ---- Domain table ----
DOMAINS=(CONUS AK HI PR GU)

DOMAIN=${DOMAINS[$PBS_ARRAY_INDEX]}

echo "Running domain: $DOMAIN"

python plot_domain.py \
  --cycle 00 \
  --date 20260109 \
  --domain $DOMAIN

✅ Python: domain-aware plotting
plot_domain.py
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--cycle", required=True)
parser.add_argument("--date", required=True)
parser.add_argument("--domain", required=True)
args = parser.parse_args()

DOMAIN_BBOX = {
    "CONUS": (-130, -65, 24, 50),
    "AK": (-170, -130, 50, 72),
    "HI": (-162, -154, 18, 23),
    "PR": (-68, -64, 17, 19),
    "GU": (144, 146, 13, 15),
}

lonmin, lonmax, latmin, latmax = DOMAIN_BBOX[args.domain]

print(f"Plotting {args.domain}: {lonmin},{lonmax},{latmin},{latmax}")

🧪 Debug (always add early)
echo "INDEX=$PBS_ARRAY_INDEX DOMAIN=$DOMAIN HOST=$(hostname)"

🧩 Two-Dimensional Arrays (Domains × Forecast Hours)

PBS does not support true 2D arrays, but this is the standard workaround.

Example

5 domains

20 forecast hours

Total tasks = 5 × 20 = 100

#PBS -J 0-99

DOMAINS=(CONUS AK HI PR GU)
FHS=(006 012 018 024 030 036 042 048 054 060 \
     066 072 078 084 090 096 102 108 114 120)

ND=${#DOMAINS[@]}
NF=${#FHS[@]}

DOM_IDX=$((PBS_ARRAY_INDEX / NF))
FH_IDX=$((PBS_ARRAY_INDEX % NF))

DOMAIN=${DOMAINS[$DOM_IDX]}
FH=${FHS[$FH_IDX]}

Mapping
Index 0  → CONUS 006
Index 1  → CONUS 012
...
Index 19 → CONUS 120
Index 20 → AK    006

🧠 Why this is the NOAA-approved pattern

✔ Clean separation of concerns
✔ Maximum scheduler efficiency
✔ Easy restart per domain
✔ Scales to 100s of plots
✔ Avoids nested loops in PBS

🏆 Best Practices
Item	Recommendation
Domain list	Bash array
Domain logic	Python
Restart	Array index
Logs	-o log.$PBS_ARRAY_INDEX
Validation	Fail early
🧪 Log per domain
#PBS -o logs/domain.$PBS_ARRAY_INDEX.out
#PBS -e logs/domain.$PBS_ARRAY_INDEX.err

🚀 Want more?

I can:

Add domain-specific colormaps

Add map projections per domain

Add automatic data subsetting

Convert this into a single CLI tool

Just tell me which model (GFS / GEFS / CFS).
