#!/bin/csh -f

# /bin/csh -xv

# doupate-level2 Update the U.S. GLOBEC Georges Bank Inventory level 2 files
# Adding descriptions for each status line.

# Edited October 29, 1999.  Add httpd header before error output message.  rcg
# Edited March 17 1998 Change /data to /data5 & httpd.alt reference. rcg
# February 20, 1997 rcg
#
# Passed parameters include
#	1 = project
#	2 = data type
#	3-end = status types and description, in pairs

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

#echo "<title>Update to U.S. GLOBEC Georges Bank Inventory, doupdate-level2, "
#echo "write out status descriptions</title>"
#echo "<h2 align=center>Update to U.S. GLOBEC Georges Bank Inventory, "
#echo "<br>doupdate-level2, write out status descriptions</h2>"

setenv HD /data5/globec
set script_loc=/data/rgroman/Inventory/scripts

set datadir = /data/rgroman/Inventory
#set datadir = /data/rgroman/Inventory/debug
#echo "<p> *** Note: you are in DEBUG mode, datadir = $datadir <p>"

#echo " <p>**DEBUG - doupdate-level2"
set POSTDATA=(`/data/rgroman/Inventory/scripts/poststring`)
#echo "<p>**debug POSTDATA = $POSTDATA"

@ numb_words = ${#POSTDATA}
#echo "<p>**debug numb_words = $numb_words"

set inventorytop=$datadir/toplevel.dat

#set scriptcgi="invtest"
set scriptcgi="inv"

cd $script_loc

setenv TMP `date '+%Y.%m.%d'`
#echo "<p> **debug TMP = $TMP <p>"

set current_project=$POSTDATA[1]
#echo "<p>**DEBUG current_project = $current_project"

#For each status type, add data line in level 2 file.

if ( $numb_words <= 2 ) then
	echo "Content-type: text/html"
	echo ""
	echo "<p>You have not specified any data types to add or modify."
	echo "Ending inventory update procedure."
	exit 0
endif

set datarecord="$POSTDATA"
#echo "<P> **DEBUG before call to addinventory-level2"
$script_loc/addinventory-level2 $datarecord
#echo "<P> **DEBUG after call to addinventory-level2"

#echo " <p>Status record(s) updated for $POSTDATA[2].  Will continue if"
#echo " there are more data types to update."

set curopt="`cat inventoryopt1 | tr ' ' '\012' `"
set numb_words=${#curopt}
if ( $numb_words > 2) then
	if(-e inventoryopt1) \rm inventoryopt1
	set datarecord="$curopt[1] $curopt[3-]"
	echo $datarecord > inventoryopt1
	$script_loc/doupdate_status
else
	$script_loc/inventory_updated $POSTDATA[1]
endif
