#! /bin/csh -f
#
if ( $#argv == 6) then
  set inpcoo1 = $argv[1]
  set inpcoo2 = $argv[2]
  set regsiz = $argv[3]
  set outnam = $argv[4]
  set sl = $argv[5]
  set su = $argv[6]
else
  echo "Enter J2000 RA in format HHhMMmSSs or decimal degrees:"
  set inpcoo1 = $<
  echo "Enter J2000 Dec in format DDdMMmSSs or decimal degrees:"
  set inpcoo2 = $<
  echo "Enter region size (in degrees) for FITS images:"
  set regsiz = $<
  echo "Enter base name for output SDSS FITS images:"
  set outnam = $<
  echo -n "Lower sigma limit for RGB stretch (recommended -1): "
  set sl = $<
  echo -n "Upper sigma limit for RGB stretch (recommended 5): "
  set su = $<
endif
#
# Create header
mHdr '"'"$inpcoo1 $inpcoo2 Equ J2000"'"' $regsiz $outnam\.hdr
echo mHdr -d '"'"$inpcoo1 $inpcoo2 Equ J2000"'"' $regsiz $outnam\.hdr
cat $outnam\.hdr
#
# Create g
echo "Processing...g"
mExec -d 1 -c -f $outnam\.hdr -o$outnam\-SDSSg SDSS g $outnam\-SDSSg
#
# Create r
echo "Processing...r"
mExec -d 1 -c -f $outnam\.hdr -o$outnam\-SDSSr SDSS r $outnam\-SDSSr
#
# Create i
echo "Processing...i"
mExec -d 1 -c -f $outnam\.hdr -o$outnam\-SDSSi SDSS i $outnam\-SDSSi
#
# Create z
echo "Processing...z"
mExec -d 1 -c -f $outnam\.hdr -o$outnam\-SDSSz SDSS z $outnam\-SDSSz
echo "Making RGB image from g,r,i ..."
#
# Create RGB jpg
mJPEG -red $outnam\-SDSSi/mosaic.fits $sl\s $su\s -green $outnam\-SDSSr/mosaic.fits $sl\s $su\s -blue $outnam\-SDSSg/mosaic.fits $sl\s $su\s -out SDSS-gri.jpg
echo "Done!"

