#!/bin/bash

# 1. Submit the Array and capture the ID
# The --parsable flag is the secret sauce here

#1. Prepare observation to submit obsrvation 
# Assume NMME SST and Precip were already processed

cat allSetParams.sh allObsFcstCodes.sh > prepareObs.sh

bash ./prepareObs.sh  

bash ./allPreparePlots.sh  

# Submit the first job and capture the ID
OBS_ID=$(qsub submitPrecip.sh)
echo "obsPrecip is submitted with ID: $OBS_ID"

# Submit the second job, dependent on the first finishing successfully
ARRAY_ID=$(qsub -W depend=afterok:$OBS_ID submitFcst.sh)
echo "Done R"
echo "Array submitted with ID: $ARRAY_ID"

# Submit the third job, dependent on the second finishing successfully
plot_ID=$(qsub -W depend=afterok:$ARRAY_ID submitPlots.sh)

echo "Plot submitted with ID: $plot_ID. It will start when the collector finishes."

