#!/bin/csh -f
#
# modhtml3.bisagni script
#
# Modified 1/24/1996 rcg Add access to rmp and *.nav and *.nav.Z
# 	files the subdirectory.  
# Mar. 3, 1999.  Change file types to look for from Z, nav and rmp
#	to std and img1.  rcg
# Feb. 17, 1999.  Convert to UMass/Dartmouth system for J. Bisagni rcg
# Dec. 4, 2000.  Convert for new home on rodan computer. Data and scripts
# 	are located in new places.  Also, data are not organized by month
#	anymore.  Need to add code to get at this new organization. rcg

# 7/26/95 RCG
# From G. Flierl, 2/16/95
# Used with defexec method for serving satellite images.  Script
# generates the list of available satellite images, according to
# their dates (after preselecting by type based on passed parameter
# $1) and year ($2).  The user will see each line as a hypertext link.
# When clicked, the cgi that is called will convert the specified image
# to gif format and pass it to caller.
#

set version="#modhtml3.bisagni V3.20"
set image_type=$1
set year=$2

#	set image_type="f"
#	set year="1999"

#					 echo "#debug, "
#					echo "#debug, image_type = $image_type"
#					 echo "#debug, year = $year"
set initpath="/data/satellite/avhrr/globec_std"
set monthlistpath="/home/rgroman/scripts"
if (! -e $initpath ) then
  echo "# *Cannot continue with displaying satellite image view"
  echo "#$initpath is not directory or does not exist"
  exit
endif

cd $initpath
#					 echo "Change directory to: `pwd`"
# Check for directory validity
if (-d $year) then
	set months=`ls -1p $year | grep "/" | sort -n | sed 's/\// /g'`

#	echo "debug, months = $months"

# Find months and list out
	set first=0
	if (${#months} > 0 ) then
		echo "$version"
		echo "month	year	>"
		echo "status[width=11]	yrday_gmt	time"
		foreach month ($months)
#       					echo "month = $month"
			set dirpath=$initpath/$year/$month/${image_type}
			echo "#debug, dirpath=$dirpath"
			set count=`ls -1 ${dirpath}*[.Z,.std,.img1]  |& fgrep -c "No match"` 
			echo "#debug, count=$count"
			if ($count == 0) then
				if ($first == 0 ) then
					set first=1
				endif
				cat <<XSTUFF
${month}	"$year"	(${monthlistpath}/monthlist3.bisagni ${month} $image_type $year $initpath)
XSTUFF
			endif

		end
	endif

endif
