#!/bin/csh -f
# dir.tmp - source script for the ../htmlbin/dir script
# dir     - created from dir.tmp by Makefile
# purpose - to display the dictionary-type directory structure
#           for the jgofs data management system based on the data
#           contained in the dictionary files, .remoteobjects
#
#	1/7/1997 rcg -- changed inventory access to inventory-new.html rcg
#	9/14/95 rcg -- edited for GLOBEC GB
#    9/30/94, clh -- narration added 
#   10/12/94, clh -- output log file entry if .log present 
#    1/04/95, clh -- modified to accept a command line parameter replacing
#        if ( "$QUERY_STRING" == "" ) setenv QUERY_STRING /jgofs/ 
#        with an if block based on $1
#    1/05/95, clh -- changed log file to be handled like .remoteobjects, but
#        want event log to stand out, so need a separate section
#
# set currentdir = the subdir that is requested - may be empty if at top level
# if we are at the top level, do nothing
# if we are at first level down, add a link to get to top
# if we are in subdirs 2 levels or below, link allows going up one level
# list the subdirectories, create a hypertext reference to the subdir, 
# name the link the same as the subdir
# to list the objects of this directory, send name of this subdir (if any)
#      and .remoteobjects to readdct2 which creates the 'obj, pi, descript' 
#      type of directory listing
#
echo "Content-type: text/html"
echo ""

if ( "$1" == "" ) then 
   setenv QUERY_STRING /globec/gb/
else
   setenv QUERY_STRING $1
endif

set topdir=/data/globec/objects
set currentdir=$QUERY_STRING
set currentdir=$currentdir:h
set subdir=$currentdir:t

cd $topdir$QUERY_STRING
if ( "$currentdir" == "/globec/gb" ) then
   if ( -f dirhead ) then
     echo "<h1>U.S. GLOBEC Georges Bank Data System</h1>"
#     cat dirhead
   endif
   if ( -f direxplain ) then
     cat direxplain
   endif
endif

###|\<a href="\""http://www1.whoi.edu/cgi-bin/searchjg"\"">Search</a> 
###add back once completed

echo "<h2>| <a href="\""http://globec.whoi.edu/globec-dir/dir-help.html"\"">Help</a> | Search | <a href="\""http://globec.whoi.edu/globec-dir/inventory-new.html"\"">Inventory</a> | <a href="\""http://globec.whoi.edu/"\"">Home Page</a> |</h2>"

echo "<pre>"

###if ( "$currentdir" == "/globec/gb" ) then
###else
  echo ""
  echo "<h2>Data in directory $QUERY_STRING</h2>"
  if ( -f .log) then
    /data/globec/htmlbin/bin/readdct2 $QUERY_STRING < .log  
    echo ""
  endif
  echo ""

  if ( -e .remoteobjects) then
    echo "<em>Data           Investigator    Description</em>"
    echo "<hr>"
  /data/globec/htmlbin/bin/readdct2 $QUERY_STRING < .remoteobjects
  endif
###endif
echo "<hr>"
echo "<h3>U.S. GLOBEC Georges Bank Data Directory Overview</h3>"
echo "Go to the indicated category or year by clicking on its name or number."

if ( "$currentdir" == "/jgofs" ) then
 find ${topdir}/globec/gb/ -type d -print | grep -v dmotests | grep objects/globec/gb | sort | nawk '\
$1 != "." {  n=split($1,arr,"/");\
  for(i=1;i<n;i++)printf "   "\
  printf "<a href=\"http:/jg/newdir?%s/\">%s</a>\n",substr($1,21,length($1)-2),arr[n]}\
'
else
 find ${topdir}/ -type d -print | grep -v dmotests | grep objects/globec/gb | sort | nawk '\
$1 != "." {  n=split($1,arr,"/");\
  for(i=1;i<n;i++)printf "   "\
  printf "<a href=\"http:/jg/newdir?%s/\">%s</a>\n",substr($1,21,length($1)-2),arr[n]}\
'
endif
echo "</pre>"
