4 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
 
    6 set_variable:  WORKDIR        ARCHIVE_WORKDIR        ${TMPDIR:-/tmp}/
 
    7 set_variable:  VERSION        ARCHIVE_VERSION        \*
 
    8 set_array      RUNS           1  99999999
 
   12     usage "$script <archive> <detector> <directory>"\
 
   13           "\nAuxiliary script to check auxiliary data in archive for a given detector."\
 
   14           "\nThe directory corresponds to the location of the input tables (see https://git.km3net.de/calibration/input_tables) "\
 
   15           "\nand the archive to auxiliary data (see https://git.km3net.de/auxiliary_data/jpp)."
 
   18 if (( $# != 3 )); then
 
   19     fatal "Wrong number of arguments."
 
   22 set_variable  ARCHIVE         $argv[1]
 
   23 set_variable  DETECTOR        $argv[2]
 
   24 set_variable  DIR             $argv[3]
 
   29 set_variable  DETECTOR      `getDetector -D $DETECTOR -O string`
 
   30 let          "DETECTOR_ID = `getDetector -D $DETECTOR -O int`"
 
   33 # map name in input_data/data/ to name in auxiliary_data/jpp/
 
   37 BUFFER[tripods]=tripod
 
   38 BUFFER[baseAcousticBeacon]=transmitter
 
   39 BUFFER[hydrophones]=hydrophone
 
   40 BUFFER[waveforms]=waveform
 
   43 # processing functions
 
   47     grep -E -v "^#" $1  |  tail -n+2  |  tr ',' ' '  
 
   50 function typeout_tripod()
 
   55 function typeout_hydrophone()
 
   57     typeout  $1  |  awk -v DEGTORAD=0.017453293 '{ $5 *= DEGTORAD; if ($2 != -1) { print $1, $2,     ($3 * -cos($5) + $4 * -sin($5)), ($3 * +sin($5) + $4 * -cos($5)), $6 }}'
 
   60 function typeout_transmitter()
 
   62     typeout  $1  |  awk -v DEGTORAD=0.017453293 '{ $6 *= DEGTORAD; if ($3 != -1) { print $1, $2, $3, ($4 * -cos($6) + $5 * -sin($6)), ($4 * +sin($6) + $5 * -cos($6)), $7 }}'
 
   65 function typeout_waveform()
 
   71 # format aliases with given precision
 
   73 alias format_tripod='awk "{ printf \"%2d %+12.${PRECISION}f %+12.${PRECISION}f %+9.${PRECISION}f\n\", \$1, \$2, \$3, \$4 }"'
 
   74 alias format_transmitter='awk "{ printf \"%2d %3d %2d %7.${PRECISION}f %7.${PRECISION}f %7.${PRECISION}f\n\", \$1, \$2, \$3, \$4, \$5, \$6 }"'
 
   75 alias format_hydrophone='awk "{ printf \"%2d %3d %7.${PRECISION}f %7.${PRECISION}f %7.${PRECISION}f\n\", \$1, \$2, \$3, \$4, \$5 }"'
 
   76 alias format_waveform='awk "{ printf \"%3d  %d\n\", \$1, \$2 }"'
 
   83     set_variable   PRECISION      2
 
   85     eval grep -E  -v \"^#\"  $1  \|  $3  >  $WORKDIR/.A.txt
 
   86     eval grep -E  -v \"^#\"  $2  \|  $3  >  $WORKDIR/.B.txt
 
   88     diff   $WORKDIR/.A.txt  $WORKDIR/.B.txt; export RESULT=$?
 
   89     rm -f  $WORKDIR/.A.txt  $WORKDIR/.B.txt
 
   93 for KEY VALUE in ${(kv)BUFFER}; do
 
   95     set_variable  INPUT_FILE  $DIR/data/$DETECTOR/${DETECTOR}_${KEY}.csv
 
   97     if [[ -f $INPUT_FILE ]]; then
 
   99         set_variable   PRECISION      4
 
  101         eval  typeout_$VALUE   $INPUT_FILE  \|  format_$VALUE  >  $WORKDIR/${VALUE}.txt 
 
  103         rm -f  $WORKDIR/${VALUE}_A.txt
 
  105         getFile.sh  $ARCHIVE  $DETECTOR_ID  $RUNS[1]  $VALUE  master  $WORKDIR/${VALUE}_A >& /dev/null
 
  107         echo -n "Comparing ${INPUT_FILE:t} with archived file..."
 
  109         compare  $WORKDIR/${VALUE}_A.txt  $WORKDIR/${VALUE}.txt  format_$VALUE
 
  111         if (( $RESULT == 0 )); then
 
  112             echo "$GREEN OK $RESET"
 
  114             echo "$RED Alternative input file $WORKDIR/${VALUE}.txt. $RESET"