Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
putFile.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2#
3# \author mdejong
4#
5script=${0##*/}
6
7source ${0%${script}}ulib.sh
8
9set_variable: DEBUG ARCHIVE_DEBUG 2
10set_variable VERSION ""
11
12if do_usage $*; then
13 usage "$script <input file> <path> <detector identifier> <minimal run> <maximal run> <type> <version>"\
14 "\nUtility script to store file in archive."
15fi
16
17case $# in
18 7) set_variable INPUT_FILE $argv[1];
19 set_variable DIR $argv[2];
20 let ID=" $argv[3]";
21 let MINRUN=" $argv[4]";
22 let MAXRUN=" $argv[5]";
23 set_variable TYPE $argv[6];
24 set_variable VERSION $argv[7];;
25 *) fatal "Wrong number of arguments."
26esac
27
28if [[ ! -d $DIR ]]; then
29 fatal "Invalid path $argv[2]"
30fi
31
32if [[ ! -f $INPUT_FILE ]]; then
33 fatal "File $INPUT_FILE does not exist."
34fi
35
36if (( $ID == 0 )); then
37 fatal "Invalid detector identifier $argv[3]"
38fi
39
40if (( $MINRUN == 0 )); then
41 fatal "Invalid minimal run $argv[4]"
42fi
43
44if (( $MAXRUN == 0 )); then
45 fatal "Invalid minimal run $argv[5]"
46fi
47
48if (( $MINRUN > $MAXRUN )); then
49 fatal "Invalid minimal / maximal run $argv[4] / $argv[5]"
50fi
51
52if [[ $VERSION == *[^[:alnum:_-]]* ]]; then
53 fatal "Invalid version $argv[7] (special characters not allowed)"
54fi
55
56setopt extendedglob
57
58typeset -Z8 ID
59typeset -Z8 MINRUN
60typeset -Z8 MAXRUN
61
62let COUNTER="0"
63
64if [[ -d $DIR/$ID/$TYPE ]]; then
65
66 typeset -T BUFFER ARRAY /
67
68 (ls -1 $DIR/$ID/$TYPE/_*/*/*/*) 2> /dev/null | while read BUFFER; do
69
70 set_variable A_ID ${ARRAY[-6]}
71 set_variable A_TYPE ${ARRAY[-5]}
72 set_variable A_VERSION ${ARRAY[-4]#_}
73 let A_MINRUN=" ${ARRAY[-3]}"
74 let A_MAXRUN=" ${ARRAY[-2]}"
75 set_variable A_FILENAME ${ARRAY[-1]}
76
77 let A_COUNTER="${A_FILENAME:r}"
78
79 if (( $MINRUN <= $A_MAXRUN && $MAXRUN >= $A_MINRUN )); then
80 if (( $A_COUNTER > $COUNTER )); then
81 let COUNTER="$A_COUNTER"
82 fi
83 fi
84 done
85fi
86
87let COUNTER="$COUNTER + 1"
88
89set_variable OUTPUT_FILE $DIR/$ID/$TYPE/_${VERSION}/$MINRUN/$MAXRUN/${COUNTER}.${INPUT_FILE:e}
90
91mkdir -p ${OUTPUT_FILE:h}
92
93if (( $? != 0 )); then
94 fatal "Path ${OUTPUT_FILE:h} not created."
95fi
96
97cp -p $INPUT_FILE $OUTPUT_FILE
98
99if (( $? == 0 )); then
100 notice "Stored $INPUT_FILE to archive:$OUTPUT_FILE"
101else
102 fatal "File $INPUT_FILE not stored in archive."
103fi
104