#!/opt/tcl/bin/sytcl
#!/usr/local/tcl74/bin/dbtcl
#
set tclroot /opt/share/tcl
# set tclroot /usr/local/tcl74
#
loadlibindex $tclroot/lib/ucodb/ucodb.tlib
#
set dbpipe1 [sybOpen keck guest rsvp UCO-ASTRO]
#
global sybmsg
#
set memtbl keck.dbo.Memes
set mcotbl keck.dbo.Mcontexts
#
set uniq [getclock]
set outfile $argv
set ofp [open $outfile w]
#
set boiler1 "<HTML> <HEAD> <TITLE>Meme Contexts</title> </HEAD> <BODY> \n\
<H1>Meme (FITS and ACS/DCS/ICS Keywords, etc.) Context Report</h1> \n\
<h2>provided by The Scientific Programming Group</H2> \n\
<H3>UCO / Lick Observatory</H3> <HR> \n"
#
set boiler2 "<p> \n\
<hr> \n\
<p> \n\
<ADDRESS> \n\
A Public Service of UCO/Lick Observatory <br> \n\
Courtesy of the Scientific Programming Group <br> \n\
Using Sybase Server, Tcl, HTML<br> \n\
<a href=\"mailto:webmaster@ucolick.org\">webmaster@ucolick.org</a> \n\
</address> \n\
</BODY> \n\
</HTML>"
#
puts $ofp "$boiler1"
#
set sqlcmd "select distinct context from $memtbl"
set sqt $memtbl
doSQL 1
#
while {1} {
	set ct [sybNext 1]
	if {$ct == ""} {break}
	lappend cts $ct
}
#
set cts [lsort $cts]
set ctt "<dl>\n"
foreach ct $cts {

	set sqlcmd "select descrip, author, stamp from $mcotbl where mcontext = '$ct'"
	set sqt $mcotbl
	doSQL 1
	set line [sybNext 1]
	if {$line != ""} {
		lassign $line desc auth stam
		if {$auth == ""} {set auth "Unknown Author"}
		if {$stam == ""} {set stam "Unknown Date"}
#		append ctt "<dt><b>$ct</b> -- by $auth as of $stam\n"
		append ctt "<dt><b>$ct</b>"
		append ctt "<dd>[string trim $desc]\n"
	} else {
		append ctu "<li><b>$ct</b> -- No Info Available yet"
	}

}
append ctt "</dl>\n"
puts $ofp "If you are unfamiliar with the Lick keyword contexts,"
puts $ofp "this list of context names may be helpful:"
puts $ofp "$ctt"
if {![lempty ctu]} {
	puts $ofp "<ul>\n$ctu\n</ul>"
}
#
puts $ofp "$boiler2"
#
close $ofp
#
