#!/bin/csh -f

# monthlist3.bisagni script
#
# Modified 6/17/1999.  V3.5 Add in looking for *.std.Z and *.img1.Z.  rcg
# Modified 3/3/1999. Change file types to look for from .nav, .nav.Z
#	and .rmp to *.std and *.img1 rcg
# Modified 2/17/1999. Continue conversion to CMAST computer. rcg 
# Modified 12/1/1999.  Brought over to CMAST system for JB.  Change
#	references to the globec machine at CMAST and to the new
#	directory structure used here.  rcg
# Modified 4/5/1996 Fix awk command so awk will work okay.  rcg
# Modified 4/2/1996 Use oawk instead of awk since awk no longer
# 	handles the syntax correctly.  rcg
# 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 June 17, 1999/V3.5"
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="1999"
#	set image_type="f"
#	set initpath="/data2/glob3/pub

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}*.std  |& fgrep -c "No match"` 
#						echo "count = $count"
if ($count == 0) then
	set files=`ls -1 ${dirpath}*.std`
	set stat="navigated"

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

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

cat <<XSTUFF
"${stat}"	"${yrday}"	"<a href="http://globec.cmast.umassd.edu:8080/jg/dsp2gif?${file}">${time}</a>"
XSTUFF
          end
endif

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

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

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

cat <<XSTUFF
"${stat}"	"${yrday}"	"<a href="http://globec.cmast.umassd.edu:8080/jg/dsp2gif?${file}">${time}</a>"
XSTUFF
          end
endif


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

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

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

cat <<XSTUFF
"${stat}"	"${yrday}"	"<a href="http://globec.cmast.umassd.edu:8080/jg/dsp2gif?${file}">${time}</a>"
XSTUFF
          end
endif


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

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

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

cat <<XSTUFF
"${stat}"	"${yrday}"	"<a href="http://globec.cmast.umassd.edu:8080/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($1,4,3)}' `

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

#cat <<XSTUFF
#"${stat}"	"${yrday}"	"<a href="http://globec.cmast.umassd.edu:8080/jg/dsp2gif?${file}">${time}</a>"
#XSTUFF
#          end
#endif

