nesi / APSIM-HPC

Deploy APSIM (Agricultural Production Systems sIMulator - https://www.apsim.info/) on high performance computing clusters.
https://nesi.github.io/APSIM-HPC/
MIT License
0 stars 0 forks source link

Exclude "ExampleConfig.txt" from ${CONFIG_FILES} #20

Closed DininduSenanayake closed 2 months ago

DininduSenanayake commented 2 months ago

Current version of Slurm script ( and the Snake rule) assigns all of the .txt files to ${CONFIG_FILES} as per CONFIG_FILES=($(ls $CONFIG_DIR/*.txt)). This is not desirable as ExampleConfig.txt file is on the same working directory which has to be excluded from the variable. Otherwise, it will create a ghost .apsimx file and NULL array task

DininduSenanayake commented 2 months ago

Few ways to tackle this

  1. Use extended globbbing
shopt -s extglob
CONFIG_FILES=($(ls $CONFIG_DIR/!(*ExampleConfig).txt))
echo "${CONFIG_FILES[@]}"
  1. Use find and grep
    CONFIG_FILES=($(find "$CONFIG_DIR" -name "*.txt" | grep -v "ExampleConfig.txt"))
    echo "${CONFIG_FILES[@]}"
  2. Use a Loop
CONFIG_FILES=()
for file in "$CONFIG_DIR"/*.txt; do
    if [ "$(basename "$file")" != "ExampleConfig.txt" ]; then
        CONFIG_FILES+=("$file")
    fi
done

echo "${CONFIG_FILES[@]}"

DininduSenanayake commented 2 months ago

Abandon this approach in favour of moving ExampleConfig to a different dir

DininduSenanayake commented 2 months ago

This was addressed in https://github.com/DininduSenanayake/APSIM-eri-mahuika/pull/32