#!/bin/bash
# catalog a list of run folders read from command line,
# and create softlinks to the catalog folder
# catalog_jetto_step desc study_id configuration run1 run2 run*
# desc is prepended to any description in jetto.note
# add flag -F before other arguments to catalog both failed and succesful runs
# catalog successful runs only:
#   catlog_jetto_step "generated by scan" TD-000000 SPR-039 runlist*
# catalog both failed and successful runs:
#   catlog_jetto_step -F "generated by scan" TD-000000 SPR-039 runlist*

if [ "$1" = "-F" ]; then
  catfailed=true
  shift
else
  catfailed=false
fi
desc=$1
study=$2
config=$3
shift
shift
shift

until [ -z $1 ]; do
  echo catalouging $1...
  cd $1
  rm jetto.sout
  rm -f .msg

  if [ "$catfailed" = true ]; then
    if [ -f jetto.jsp ]; then
      completejsp
    fi
    if [ -f jetto.jhp ]; then
      completejhp
    fi
    if [ -f jetto.jse ]; then
       completejse
    fi
  fi
  catalog -d"$desc" -S$study -C$config
  rtcd=$?
  cd ..
  ln_cat_step $1
  catid_oneline $1
  shift
  echo '==============================================' 
  echo
done



  

