#!/bin/bash 
#
# This script now reads variables and years from ASCII files.
#
# Usage: ./runProcess.sh
# No command-line arguments are needed for variables and years anymore.

# Define the paths to your variable and years files
VARIABLES_FILE="variables.txt"
YEARS_FILE="years.txt"

# Read variables from the file
# Use 'tr -d "\n"' to remove newlines, ensuring it's a single line of comma-separated values
if [ -f "${VARIABLES_FILE}" ]; then
    export variable=$(cat "${VARIABLES_FILE}" | tr -d '\n')
else
    echo "Error: Variables file '${VARIABLES_FILE}' not found!"
    exit 1
fi

# Read years from the file
if [ -f "${YEARS_FILE}" ]; then
    export yyyys=$(cat "${YEARS_FILE}" | tr -d '\n')
else
    echo "Error: Years file '${YEARS_FILE}' not found!"
    exit 1
fi
export dir_script=`pwd`
export dir_out=`dirname ${dir_script}`
# Ensure the output directory exists
if [ ! -d "${dir_out}" ] ;then
   mkdir -p "${dir_out}"
else
  echo "Directory exist!"
fi
# Execute your Python script with the variables and years read from files
# Assuming your Python script is named 'download_era5_dailyMean_parallel.py'
python download_era5_dailyMean_parallel.py \
    --variables "${variable}" \
    --output_dir "${dir_out}" \
    --years "${yyyys}" \
    --num_processes 1

# You might want to add error checking for the python script's exit status here
if [ $? -eq 0 ]; then
    echo "Python script completed successfully."
else
    echo "Python script failed. Check its output for errors."
fi

