#! /bin/sh
# This is the LHEA perl script: /data/irby/heasoft-6.10/heasoft-6.10/ftools/i386-apple-darwin9.8.0/bin/skvbatch.pl
# The purpose of this special block is to make this script work with
# the user's local perl, regardless of where that perl is installed.
# The variable LHEAPERL is set by the initialization script to
# point to the local perl installation.
#-------------------------------------------------------------------------------
eval '
if [ "x$LHEAPERL" = x ]; then
  echo "Please run standard LHEA initialization before attempting to run /data/irby/heasoft-6.10/heasoft-6.10/ftools/i386-apple-darwin9.8.0/bin/skvbatch.pl."
  exit 3
elif [ "$LHEAPERL" = noperl ]; then
  echo "During LHEA initialization, no acceptable version of Perl was found."
  echo "Cannot execute script /data/irby/heasoft-6.10/heasoft-6.10/ftools/i386-apple-darwin9.8.0/bin/skvbatch.pl."
  exit 3
elif [ `$LHEAPERL -v < /dev/null 2> /dev/null | grep -ic "perl"` -eq 0 ]; then
  echo "LHEAPERL variable does not point to a usable perl."
  exit 3
else
  # Force Perl into 32-bit mode (to match the binaries) if necessary:
  if [ "x$HD_BUILD_ARCH_32_BIT" = xyes ]; then
    if [ `$LHEAPERL -V 2> /dev/null | grep -ic "USE_64_BIT"` -ne 0 ]; then
      VERSIONER_PERL_PREFER_32_BIT=yes
      export VERSIONER_PERL_PREFER_32_BIT
    fi
  fi
  exec $LHEAPERL -x $0 ${1+"$@"}
fi
'
if(0);
# Do not delete anything above this comment from an installed LHEA script!
#-------------------------------------------------------------------------------
#!/usr1/local/bin/perl
##########################################
# Skvbatch.pl is a front end to (x)webquery.pl 
# to return FITS files from SkyView from 
# the command line.
#
# Calling sequence and parameter information
# can be found on the SkyView web site:
#     http://skyview.gsfc.nasa.gov/batchpage.html
#
##########################################

# Loop over the argument list and look to see
# if file has been defined 
$i=0;
foreach (@ARGV) {
   last if (/^file=/i);
   $i++;
}

# if a filename has been specified, make it the filename
# and splice it out of the argument list
$filename = splice(@ARGV,$i,1);

# Read in the argument list and put the
# values in quotes
$new = 'xwebquery.pl url="/cgi-bin/pskcall" host="skys.gsfc.nasa.gov" ' . '\'' . join('\' \'',@ARGV) . '\'';

# Exexcute web query
@arr = `$new`;

# Put all the blocks togehter
$data = join('',@arr);

# Read past the HTTP header to get to the real data
# this is a kludge such that this works with the NCSA and APACHE
# web servers
if (index($data,"\n\r\n") == -1) {
    $locat = index($data, "\n\n") + 2;
} else {
    $locat = index($data, "\n\r\n") + 3;
}

if ($locat == 1) {$locat = 0;}
			       
# Either write to a file or standard output
if (length($filename)) {
   # get the filename from the argument
   ($key,$truename) = split('=',$filename);

   # Open the file
   open(WWWOUT,">$truename");

   # Print out only from SIMPLE on
   print(WWWOUT substr($data, $locat));
} else {
   # Print to standard outuput
   print substr($data, $locat);
}

# And that's all there is


