diff --git a/turing/calculations/g09/g09slurm b/turing/calculations/g09/g09slurm index abcb5eb..af81bb1 100755 --- a/turing/calculations/g09/g09slurm +++ b/turing/calculations/g09/g09slurm @@ -6,6 +6,7 @@ # # Usage: g09slurm INPUT_FILE.com [OUTPUT_FILE.out] [START_TIME] +set -e usage () { echo "Usage: g09slurm INPUT_FILE.com [OUTPUT_FILE.out] [START_TIME]" @@ -53,6 +54,63 @@ if [ -z "$ncpus" ]; then fi +# Detect & support custom directories + +collect_scratch_objects () { + # Usage: cat $FILE | collect_scratch_objects LINK0_KEYWORD + # Parses line like this: + # %RWF=/dalton/s0/ + # %RWF=/dalton/s0/,4GB,/scratch/,3GB,/temp/s0/my_job,-1 + # and prints the scratch dirs/files there + # + # The first argument is the keyword to look for, and it must + # be must be in lowercase + local KWD="$1" + awk 'tolower($0) ~ /^ *% *'$KWD' *=/ { + A = $0 + # Erase keyword + sub(/^[^=]*= */, "", A) + # Erase comment, if any + sub(/ *\!.*$/, "", A) + Args_count = split(A, Args, ",") + # print out the directory/file parts + for (i = 1; i <= Args_count; ++i) + print(Args[i]) + }' +} + +create_scratch_dirs () { + # Usage: create_scratch_dir "$scratch_dir_lines" LINK0_KEYWORD + local SCR_DIRS="$1" + local KWD="$2" + if [ -n "$SCR_DIRS" ]; then + echo "Found scratch dirs for $KWD:" + local IFS=$'\n' + for D in $SCR_DIRS; do + echo " $D" + case "$D" in + */) + mkdir -p -v "$D" + ;; + *) + mkdir -p -v "$(dirname "$D")" + ;; + esac + done + fi +} + + +rwf_scratch_dirs=$(cat "$input_file" | collect_scratch_objects rwf) +create_scratch_dirs "$rwf_scratch_dirs" "RWF files" + +int_scratch_dirs=$(cat "$input_file" | collect_scratch_objects int) +create_scratch_dirs "$int_scratch_dirs" "INT files" + +d2e_scratch_dirs=$(cat "$input_file" | collect_scratch_objects d2e) +create_scratch_dirs "$d2e_scratch_dirs" "D2E files" + + # Allow delayed start if [ -z "$begin_date" ]; then