#!/bin/csh -f

# monthlist3.bisagni script
#
# Modified 1/24/1996 rcg to add access to *.nav, *.nav.Z and *.rmp files
#	in the subdirectory.
# 7/25/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 parameters
#	$1 month
#	$2 image_type
#	$3 year
#	$4 initpath


# 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 to caller.
#
set version="#monthlist3.bisagni V3.01"
set month=$1
#       					echo "month = $month"
set year=$3
#					echo "year = $year"
set image_type=$2
#					echo "image_type = $image_type"
set initpath=$4

#	set month="1"
#	set year="1995"
#	set image_type="k"
#	set initpath="/pathfdr1/xbrowse/avhrr"

echo "$version"
echo "status	yrday_gmt	time"

if (! -e $initpath ) then
	cat <<XERROR
" *Cannot continue with displaying satellite image view"	"$initpath is not directory or does not exist"
XERROR
  exit
endif

cd $initpath
#					 echo "Change directory to: `pwd`"

set dirpath=$initpath/$year/$month/${image_type}
#					echo "dirpath = $dirpath"

set count=`ls -1 ${dirpath}*.nav.Z  |& fgrep -c "No match"` 
#						echo "count = $count"
if ($count == 0) then
	set files=`ls -1 ${dirpath}*.nav.Z`
	set stat="final"

	foreach file ($files)
		set filetail=$file:t
		set yrday=`echo $filetail | awk '{print substr($filetail,4,3)}' `

		set time=`echo $filetail | awk '{print substr($filetail,7,6)}' `

cat <<XSTUFF
"${stat}"	"${yrday}"	"<a href="http://chips1.gso.uri.edu/jg/dsp2gif?${file}">${time}</a>"
XSTUFF
          end
endif

set count=`ls -1 ${dirpath}*.nav  |& fgrep -c "No match"` 
#						echo "count = $count"
if ($count == 0) then
	set files=`ls -1 ${dirpath}*.nav`
	set stat="navigated"

	foreach file ($files)
		set filetail=$file:t
		set yrday=`echo $filetail | awk '{print substr($filetail,4,3)}' `

		set time=`echo $filetail | awk '{print substr($filetail,7,6)}' `

cat <<XSTUFF
"${stat}"	"${yrday}"	"<a href="http://chips1.gso.uri.edu/jg/dsp2gif?${file}">${time}</a>"
XSTUFF
          end
endif

set count=`ls -1 ${dirpath}*.rmp  |& fgrep -c "No match"` 
#						echo "count = $count"
if ($count == 0) then
	set files=`ls -1 ${dirpath}*.rmp`
	set stat="unnavigated"

	foreach file ($files)
		set filetail=$file:t
		set yrday=`echo $filetail | awk '{print substr($filetail,4,3)}' `

		set time=`echo $filetail | awk '{print substr($filetail,7,6)}' `

cat <<XSTUFF
"${stat}"	"${yrday}"	"<a href="http://chips1.gso.uri.edu/jg/dsp2gif?${file}">${time}</a>"
XSTUFF
          end
endif
