#!/bin/csh -f
#
# dsp2gif script
# 6/22/95 RCG

# Converts DSP formatted image file into gif image file.

# Assumes QUERY_STRING is the file to be converted
# mia2gifpath is set to the directory of where the mia2gif program resides
# tmppath is set to the directory where temporary gif files will be stored
# palfile is set to the full path/file name of the pallette data file
# 
echo " from dsdp2gif QUERY_STRING = $QUERY_STRING"
set dspin=$QUERY_STRING

set mia2gifpath=/data/globec/htmlbin/bin
set tmppath=/data/globec/httpd/htdocs/temp-dir
set palfile=/data/globec/htmlbin/bin/petes.pal

set tmp=`date '+%H%M%S'`
if ($REMOTE_HOST == "") then
	setenv REMOTE_HOST "tmp.host"
endif

set gifout=$tmppath/$tmp.$REMOTE_HOST.gif
echo " gifout = $gifout"

set ext=$dspin:e

set zcatout = "no"
if ($ext == "Z") then
	set zcatout=$tmppath/$tmp.$REMOTE_HOST.zcat
	zcat $dspin > $zcatout
	chmod o+w $tmppath/*.$REMOTE_HOST.zcat
	set dspin=$zcatout
endif

/$mia2gifpath/mia2gif in=$dspin out=$gifout pal=\($palfile,24\)
chmod o+w $tmppath/*.$REMOTE_HOST.gif

if (-e $zcatout) rm $zcatout

if (-e $gifout) then

#	echo "Content-type: text/html"
#	echo ""
#	echo "Here is the satellite image requested"
#	echo "\<p\>\<img src=\"$gifout\"\>\</p\>"
#	echo " gifout file = $gifout created" ; ls -l $gifout

	echo "Content-type: image/gif"
	echo ""
	cat $gifout
	rm $gifout

else

	echo " Content-type: text/plain"
	echo ""
	echo " Could not convert the satellite image from the file "
	echo "  $dspin " 
	echo " Please contact the U.S. GLOBEC Georges Bank"
	echo " Data Mangement Office."
	echo " "
	echo " The following information may be useful for debugging the problem."
	echo " QUERY_STRING = $QUERY_STRING"
	echo " mia2gifpath = $mia2gifpath"
	echo " tmppath = $tmppath"
	echo " palfile = $palfile"
	echo " dspin = $dspin"
	echo " ext = $ext"
	echo " zcatout = $zcatout"
	echo " gifout = $gifout"
endif


