#!/bin/bash

# 2009.02.25 dph - v2.0.0
#    add error checking on chandra-get
#    and uncompress, create links if successful, using setup_obsdir
#     (and update to chandra-get  v0.2.0,  -> chandra-get2
#

# 2008.08.01 - v1.0.2
#  switch to bash, since no pushd in sh on solaris.

# 2007.10.17
# v 1.0.1   added dtf1 for hrc-s

# 2007.08.08 dph
# v 1.0.0

# usage:  download_obsid n[ n2[ n3 [...]]]


for i in $*
  do
  echo ""
  echo Attempting retrieval of standard file set for obsid:  $i

  chandra-get --download $i

  if [ $? == 1 ] 
      then
      echo WARNING: Retrieval failed for $i
  else
      echo Retrieved.

# in case it's an hrc-s obs, try to get the dtf1:
# (there shouldn't be any problem if it doesn't exist)

      chandra-get --download=dtf1 $i

      echo Unpack and create links...

      setup_obsdir obs_$i

  fi

done

