#!/bin/bash

MAX_JOBS=13
current_jobs=0

md_list=(
  "0101" "0106" "0111" "0116" "0121" "0126" "0131"
  "0205" "0210" "0215" "0220" "0225"
  "0302" "0307" "0312" "0317" "0322" "0327"
  "0401" "0406" "0411" "0416" "0421" "0426"
  "0501" "0506" "0511" "0516" "0521" "0526" "0531"
  "0605" "0610" "0615" "0620" "0625" "0630"
  "0705" "0710" "0715" "0720" "0725" "0730"
  "0804" "0809" "0814" "0819" "0824" "0829"
  "0903" "0908" "0913" "0918" "0923" "0928"
  "1003" "1008" "1013" "1018" "1023" "1028"
  "1102" "1107" "1112" "1117" "1122" "1127"
  "1202" "1207" "1212" "1217" "1222" "1227"
)

variables=("RH" "axsmtg" "ASWDNS")

for var in "${variables[@]}"; do
  for md in "${md_list[@]}"; do
    echo "Launching: python ./anomaly.py $md $var"
    python ./anomaly_cwrf.py "$md" "$var" &

    ((current_jobs++))
    if ((current_jobs >= MAX_JOBS)); then
      wait -n  # Wait for at least one job to finish
      ((current_jobs--))
    fi
  done
done

wait  # Wait for any remaining jobs

