#!/usr/bin/env bash
#SBATCH --job-name=coastal_sfincs
#SBATCH --partition=c5n-18xlarge
#SBATCH -N 1
#SBATCH --ntasks=1
#SBATCH --exclusive
#SBATCH --output=slurm-%j.out

# Unzip pre-built Texas model to a job-local temp directory
MODEL_DIR="/tmp/texas_model_${SLURM_JOB_ID}"
unzip -o "$(dirname "$0")/texas.zip" -d "${MODEL_DIR}"

CONFIG_FILE="/tmp/coastal_config_${SLURM_JOB_ID}.yaml"

cat > "${CONFIG_FILE}" <<EOF
model: sfincs

simulation:
  start_date: 2020-05-11
  duration_hours: 168
  coastal_domain: atlgulf
  meteo_source: nwm_retro

boundary:
  source: tpxo

model_config:
  prebuilt_dir: ${MODEL_DIR}
  discharge_locations_file: ${MODEL_DIR}/sfincs_nwm.src
  merge_discharge: true
  forcing_to_mesh_offset_m: 0.171 # TPXO/MSL -> NAVD88 mesh (VDatum at domain centroid)
  vdatum_mesh_to_msl_m: 0.171     # NAVD88 mesh -> MSL observations
  include_precip: true
  include_wind: true
  include_pressure: true
EOF

# For production only this line is needed
/ngen-test/coastal-calibration/coastal-calibration run "${CONFIG_FILE}"

# For running the dev version we use pixi.
# For production comment out these three lines.
# For making uv work well on NSF mounted locations
# we need to set these envs
# export UV_CACHE_DIR=/var/tmp/uv-cache
# export UV_LINK_MODE=copy
# pixi r -e dev coastal-calibration run "${CONFIG_FILE}"

rm -f "${CONFIG_FILE}"
rm -rf "${MODEL_DIR}"
