#!/usr/bin/csh -f
#
# cruise-report-list script

# Creates html output from inventory data of available cruise reports.

# June 23, 1999.  V1.41  Revert back to using defrpt_url.  Cannot get
#	object to be read in.  rcg
# June 23, 1999.  V1.4 Use list to get at data rather than defrpt_url.  
#	Data in is changed to an object rather than the data file. RCG
# January 19, 1999.  V1.3 Move start of hlml header to beginning of script
# so any error messages might appear to user.  Change REMOTE_HOST to
# REMOTE_ADDR in defining temporary file name since not all systems
# make the host name available.  Replace temp-dir with /tmp and add
# script name to file name.  rcg
# December 1, 1998.  Replace underscores with blanks before output. rcg
# March 20, 1998.  Use /data5 not /data.  Try using defgb, but nogood.
#	Still need defrpt_url.
# 1996/01/23 RCG

set version="June 23, 1999-V1.41"

echo "Content-type: text/html"
echo ""

#set tmppath=/data5/globec/httpd/htdocs/temp-dir
set tmppath=/tmp

#set datain=/globec/gb/inventory
set datain=/data/rgroman/Inventory/toplevel.dat

#set method="/data5/globec/bin/list -c -n -b -t"
set method=/data5/globec/methods/defrpt_url
#set method=/data5/globec/methods/defgb

setenv PATH_INFO=.flat2
 
#	echo " method = $method"
#	echo " tmppath = $tmppath"
#	echo " datain = $datain"
#	echo " PATH_INFO = $PATH_INFO"

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

set htmlout=$tmppath/cruise-report-list-$tmp.$REMOTE_ADDR.html
#	echo " htmlout = $htmlout"

#	set retrieve_params=status=on-line,project,platform,description
#	set arg1=$datain
#	set arg2=$retrieve_params
#	echo "#debug, method=$method"
#	echo "#debug, arg1=$arg1"
#	echo "#debug, arg2=$arg2"
#	echo "#debug, htmlout=$htmlout"
#	/data5/globec/bin/list -c -n -b -t "/globec/gb/inventory(data_type=cruise_report,status=on-line,project,platform)"
#	$method \"${arg1}\(${arg2}\)\" > $htmlout
	$method $datain data_type=cruise_report status=on-line project platform description >  $htmlout

#	echo "#debug, after first method execution"

chmod o+w $tmppath/*.$REMOTE_ADDR.html


if (-e $htmlout) then

#	echo "#debug, begining of cruise report section"
	echo "<title> Cruise Reports</title>"
	echo "<head>"
	echo "<h2 align=center>Cruise Reports</h2>"
	echo "</head>"
	echo "Click on the link to review on-line cruise reports.  Note that in"
	echo "some cases the figures, tables and other images may not yet be"
	echo "available and you will receive a message that the link " 
	echo "has not been"
	echo "found.  The text is searchable using whatever search (or find)"
	echo "capabilities are available in your browser."
	echo " "
	echo "<body>"
	echo "<p>Many of these reports were converted directly to "
	echo "Web format and would"
	echo "benefit from  tailoring for on-line use. " 

	echo "<hr>"
	echo "<h3 align=center>Cruise reports available on-line</h3>"
	echo "<pre>"
	cat $htmlout | grep -v "Content-type:" | tr -d '\042' | tr "_" " "
	echo "</pre>"
	cp $htmlout /tmp/htmlout.debug_1
	\rm $htmlout
	
	echo "<hr><p><p><h3 align=center>Cruise reports will be available"
	echo "for all cruises</h3>"
	
#	set retrieve_params=data_type=cruise_report,status=printed,project,platform,description,siname
#	set arg1=$datain
#	set arg2=$retrieve_params
#	echo "#debug, method=$method"
#	echo "#debug, arg1=$arg1"
#	echo "#debug, arg2=$arg2"
#	echo "#debug, htmlout=$htmlout"
#	$method \"${arg1}\(${arg2}\)\" > $htmlout
	$method $datain data_type=cruise_report status=printed project platform description siname >  $htmlout
#	echo "#debug, after second method execution"
	echo "<pre>"
	cat $htmlout | grep -v "Content-type:" | tr -d '\042' | tr "_" " "
	echo "</pre>"
	cp $htmlout /tmp/htmlout.debug_2
	\rm $htmlout
else
	echo "<pre>
	echo " Could not output cruise report inventory from the file "
	echo "  $datain <p>" 
	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 " tmppath = $tmppath"
	echo " datain = $datain"
	echo " htmlout = $htmlout"
	echo " method = $method"
	echo "</pre>
endif

echo "<p><hr>Version: $version<p></html>"


