4if [ -z $JPP_DIR ]; then
 
    5    echo "Variable JPP_DIR undefined."
 
    9source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
 
   11set_variable:  DEBUG         DYNAMICS_DEBUG       2
 
   12set_variable:  WORKDIR       DYNAMICS_WORKDIR     ./
 
   13set_variable:  PERIOD        DYNAMICS_PERIOD      100    # range of runs per output file
 
   14set_variable:  MARGIN        DYNAMICS_MARGIN      5      # overlap of runs at edges between output files
 
   15set_variable   RANGE         1-99999999
 
   18    usage "$script <archive> <detector identifier|detector file> <version> [run-run]"\
 
   19          "\nAuxiliary script to process dynamical positions and orientations data."\
 
   20          "\nThe static and dynamic data are stored in the archive with the given version."
 
   24     4) set_variable  RANGE           $argv[4];&
 
   25     3) set_variable  VERSION         $argv[3];
 
   26        set_variable  DETECTOR        $argv[2];
 
   27        set_variable  ARCHIVE         $argv[1];;
 
   28     *) fatal "Wrong number of arguments."
 
   35if [[ -f $DETECTOR ]]; then
 
   36    eval `JPrintDetector -a $DETECTOR -O IDENTIFIER`
 
   38    set_variable  DETECTOR_ID   `getDetector -D $DETECTOR -O int`
 
   39    set_variable  DETECTOR      detector.datx
 
   42if [[ ! -f $DETECTOR ]]; then
 
   43    fatal "Missing file $DETECTOR"\
 
   44          "\nYou may want to execute archive-get-calibration.sh beforehand."
 
   47JAcoustics.sh $DETECTOR_ID
 
   51archive-put-calibration.sh  $ARCHIVE  $VERSION  ./
 
   55RUNS=(`JRuns -D $DETECTOR_ID -F RUN -@ "RUN >= ${RANGE%%-*}" -@ "RUN <= ${RANGE##*-}" | sort -g`)
 
   57for (( L = 1; $L <= ${#RUNS}; L += $PERIOD )); do
 
   59    let "R  = $L + $PERIOD - 1"
 
   61    if (( $R > ${#RUNS} )); then
 
   65    let "LS = $L - $MARGIN"
 
   66    let "RS = $R + $MARGIN"
 
   68    if (( $LS < 1 )); then
 
   71    if (( $RS > ${#RUNS} )); then
 
   75    echo "\n\nProcessing runs $RUNS[$L]-$RUNS[$R]\n"
 
   78    set_variable  TYPE          positions
 
   79    set_variable  OUTPUT_FILE   katoomba_${(l:8::0::0:)DETECTOR_ID}_${(l:8::0::0:)RUNS[$L]}.root
 
   83    for (( i = $LS; $i <= $RS; i += 1 )); do
 
   85        set_variable  INPUT_FILE    KM3NeT_${(l:8::0::0:)DETECTOR_ID}_${(l:8::0::0:)RUNS[$i]}_event.root
 
   87        if [[ ! -f $INPUT_FILE ]]; then
 
   88            JAcousticsEventBuilder.sh  $DETECTOR  $RUNS[$i]
 
   91        if [[   -f $INPUT_FILE ]]; then
 
   92            INPUT_FILES+=($INPUT_FILE)
 
   96    if [[ ! -f $OUTPUT_FILE ]]; then
 
   98        if (( ${#INPUT_FILES} != 0 )); then
 
  100            set_variable  ACOUSTICS_STRIP
 
  102            JKatoomba.sh  $DETECTOR  $INPUT_FILES[*]  $OUTPUT_FILE
 
  104            putFile.sh  $OUTPUT_FILE  $ARCHIVE  $DETECTOR_ID  $RUNS[$L]  $RUNS[$R]  $TYPE  $VERSION
 
  107            error "No input files for $OUTPUT_FILE"
 
  112    set_variable  TYPE          orientations
 
  113    set_variable  OUTPUT_FILE   ballarat_${(l:8::0::0:)DETECTOR_ID}_${(l:8::0::0:)RUNS[$L]}.root
 
  115    if [[ ! -f $OUTPUT_FILE ]]; then
 
  117        JBallarat.sh  $DETECTOR  $RUNS[$LS,$RS]  $OUTPUT_FILE
 
  119        putFile.sh  $OUTPUT_FILE  $ARCHIVE  $DETECTOR_ID  $RUNS[$L]  $RUNS[$R]  $TYPE  $VERSION