7 source ${0%${script}}ulib.sh
 
    9 set_variable:  DEBUG        ARCHIVE_DEBUG       2
 
   10 set_variable   VERSION      ""
 
   13     usage "$script  <input file>  <path>  <detector identifier>  <minimal run>  <maximal run>  <type>  <version>"\
 
   14           "\nUtility script to store file in archive."
 
   18     7)  set_variable   INPUT_FILE   $argv[1];
 
   19         set_variable   DIR          $argv[2];
 
   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."
 
   28 if [[ ! -d $DIR ]]; then
 
   29     fatal "Invalid path $argv[2]"
 
   32 if [[ ! -f $INPUT_FILE ]]; then
 
   33     fatal "File $INPUT_FILE does not exist."
 
   36 if (( $ID     == 0 )); then
 
   37     fatal "Invalid detector identifier $argv[3]"
 
   40 if (( $MINRUN == 0 )); then
 
   41     fatal "Invalid minimal run $argv[4]"
 
   44 if (( $MAXRUN == 0 )); then
 
   45     fatal "Invalid minimal run $argv[5]"
 
   48 if (( $MINRUN > $MAXRUN )); then
 
   49     fatal "Invalid minimal / maximal run $argv[4] / $argv[5]"
 
   52 if [[ $VERSION == *[^[:alnum:_-]]* ]]; then
 
   53     fatal "Invalid version $argv[7] (special characters not allowed)"
 
   64 if [[ -d $DIR/$ID/$TYPE ]]; then
 
   66     typeset -T BUFFER ARRAY /
 
   68     (ls -1 $DIR/$ID/$TYPE/_*/*/*/*) 2> /dev/null | while read BUFFER; do
 
   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]}
 
   77         let           A_COUNTER="${A_FILENAME:r}"
 
   79         if (( $MINRUN <= $A_MAXRUN && $MAXRUN >= $A_MINRUN )); then
 
   80             if (( $A_COUNTER > $COUNTER )); then
 
   81                 let COUNTER="$A_COUNTER"
 
   87 let COUNTER="$COUNTER + 1"
 
   89 set_variable  OUTPUT_FILE  $DIR/$ID/$TYPE/_${VERSION}/$MINRUN/$MAXRUN/${COUNTER}.${INPUT_FILE:e}
 
   91 mkdir -p ${OUTPUT_FILE:h}
 
   93 if (( $? != 0 )); then
 
   94     fatal "Path ${OUTPUT_FILE:h} not created."
 
   97 cp -p  $INPUT_FILE  $OUTPUT_FILE
 
   99 if (( $? == 0 )); then
 
  100     notice "Stored $INPUT_FILE to archive:$OUTPUT_FILE"
 
  102     fatal  "File $INPUT_FILE not stored in archive."