-
Notifications
You must be signed in to change notification settings - Fork 3
/
cyverse_greenness-indices.sh
76 lines (67 loc) · 2.14 KB
/
cyverse_greenness-indices.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
WORKING_FOLDER=$(pwd)
# List of folders to exclude from the results
EXCLUDED_FOLDERS=("/logs/")
# Get the file JSON list
if [[ "${1}" == "" ]]; then
echo "The JSON file containing the file list was not specified for greenness indices"
exit 1
fi
FILE_LIST_JSON="${1}"
# No command line options are supported at this time
OPTIONS=""
# Look for YAML files to use as metadata
while IFS= read -r -d '' ONE_FILE; do
case "${ONE_FILE: -4}" in
".yml")
OPTIONS="${OPTIONS} --metadata ${ONE_FILE}"
;;
esac
case "${ONE_FILE: -5}" in
".yaml")
OPTIONS="${OPTIONS} --metadata ${ONE_FILE}"
;;
esac
done < <(find "${WORKING_FOLDER}" -maxdepth 1 -type f -print0)
# Copy the json file to the correct place
cp "${FILE_LIST_JSON}" "/scif/apps/src/greenness-indices_files.json"
echo "Calculating greenness indices using files listed in '${FILE_LIST_JSON}'"
echo " using options: ${OPTIONS}"
echo "{" >"/scif/apps/src/jx-args.json"
{
echo "\"GREENNESS_INDICES_OPTIONS\": \"${OPTIONS}\""
echo "}"
} >>"/scif/apps/src/jx-args.json"
echo "JSON Args file:"
cat "/scif/apps/src/jx-args.json"
scif run greenness-indices
# Copy the CSV files to the working folder as output
FOUND_FILES=()
while IFS= read -r -d '' ONE_FILE; do
case "${ONE_FILE: -4}" in
".csv")
# Look for the excluded folders
EXCLUDE_THIS_FILE="false"
for i in "${EXCLUDED_FOLDERS[@]}"; do
if [[ "${ONE_FILE}" == *"${i}"* ]]; then
EXCLUDE_THIS_FILE="true"
break
fi
done
if [ "${EXCLUDE_THIS_FILE}" == "false" ]; then
FOUND_FILES+=("${ONE_FILE}")
fi
;;
esac
done < <(find "${WORKING_FOLDER}" -type f -print0)
DESTINATION_FOLDER="${WORKING_FOLDER}/greenness"
for i in "${FOUND_FILES[@]}"; do
FILE_NAME=$(basename "${i}")
FILE_PATH=$(dirname "${i}")
LAST_FOLDER_NAME=$(basename "${FILE_PATH}")
# Only copy files where the destination is not the same as the origin
if [[ "${i}" != "${DESTINATION_FOLDER}/${LAST_FOLDER_NAME}/${FILE_NAME}" ]]; then
mkdir -p "${DESTINATION_FOLDER}/${LAST_FOLDER_NAME}"
cp -f "${i}" "${DESTINATION_FOLDER}/${LAST_FOLDER_NAME}/${FILE_NAME}"
fi
done