#!/bin/csh -f
# FILENAME:
#	docs
# PURPOSE:
#	Create index.html for web-based documentation.
# USAGE:
#	% docs
# MODIFICATION HISTORY:
#	2006-May Written by C. Kankelborg
#	2006-Jun-03 C. Kankelborg. Added table format with file mod dates
#  2006-Jun-12 C. Kankelborg. Added pdftex & xfig files; combined html & txt
#  2006-Jun-20 C. Kankelborg. Added alignstatus shell script.
#  2006-Jun-23 C. Kankelborg. Added subdirectory links.

# Documentation goes here:
set file = 'index.html'

# blow away file, begin HTML header
echo '<html><body>' > $file
echo '<h1 align="center"><i>MOSES</i> Level 1 Data Analysis</h1>' >> $file
echo '<center>' >> $file
echo 'Automatically generated by <em>docs</em>, '`date`'<br>' >> $file
echo '<b>Always run <em>docs</em> after modifying anything in <em>'`pwd`'</em>' >> $file
echo '</center>' >> $file

# Link to all the html files
echo '<h2>HTML and plain text documentation:</h2>' >> $file
echo '<table cellpadding=5>' >> $file
foreach foo (`ls *.html *.txt`)
	echo '<tr>' >> $file
	echo '<td><a href="'$foo'">'$foo'</a></td>' >> $file
	echo '<td>'`filetest -M: $foo`'</td>' >> $file
	echo '</tr>' >> $file
end
echo '</table>' >> $file

# Link to subdirectories and parent directory
echo '<h2>Subdirectories:</h2>' >> $file
echo '<table cellpadding=5>' >> $file
foreach foo (.. `ls -d */`)
	echo '<tr>' >> $file
	echo '<td><a href="'$foo'">'$foo'</a></td>' >> $file
	echo '<td>'`filetest -M: $foo`'</td>' >> $file
	echo '</tr>' >> $file
end
echo '</table>' >> $file


# Link to plain text files
#echo '<h2>Plain text documentation:</h2>' >> $file
#echo '<table cellpadding=5>' >> $file
#foreach foo (`ls *.txt*`)
#	echo '<tr>' >> $file
#	echo '<td><a href="'$foo'">'$foo'</a></td>' >> $file
#	echo '<td>'`filetest -M: $foo`'</td>' >> $file
#	echo '</tr>' >> $file
#end
#echo '</table>' >> $file

# pdftex, xfig and the like
echo '<h2>pdftex, xfig and the like:</h2>' >> $file
echo '<table cellpadding=5>' >> $file
foreach foo (`ls *.pdf *.tex *.fig *.pstex_t *.pstex`)
	echo '<tr>' >> $file
	echo '<td><a href="'$foo'">'$foo'</a></td>' >> $file
	echo '<td>'`filetest -M: $foo`'</td>' >> $file
	echo '</tr>' >> $file
end
echo '</table>' >> $file


# Link to all IDL procedures
echo '<h2>IDL software:</h2>' >> $file
echo '<table cellpadding=5>' >> $file
foreach foo (`ls *.pro*`)
	echo '<tr>' >> $file
	echo '<td><a href="'$foo'">'$foo'</a></td>' >> $file
	echo '<td>'`filetest -M: $foo`'</td>' >> $file
	echo '</tr>' >> $file
end
echo '</table>' >> $file

# Link to all the log files
echo '<h2>Log files:</h2>' >> $file
echo '<table cellpadding=5>' >> $file
foreach foo (`ls *.log*`)
	echo '<tr>' >> $file
	echo '<td><a href="'$foo'">'$foo'</a></td>' >> $file
	echo '<td>'`filetest -M: $foo`'</td>' >> $file
	echo '</tr>' >> $file
end
echo '</table>' >> $file

# Link to all images
echo '<h2>Images:</h2>' >> $file
echo '<table cellpadding=5>' >> $file
foreach foo (`ls *.jpg *.jp2 *.png *.gif *.tiff *.tif`)
	echo '<tr>' >> $file
	echo '<td><a href="'$foo'">'$foo'</a></td>' >> $file
	echo '<td>'`filetest -M: $foo`'</td>' >> $file
	echo '</tr>' >> $file
end
echo '</table>' >> $file

# Link to documentation shell scripts 
# (requires manual update when new scripts are added)
echo '<h2>Shell scripts:</h2>' >> $file
echo '<table cellpadding=5>' >> $file
foreach foo (docs backup alignstatus logtail)
	echo '<tr>' >> $file
	echo '<td><a href="'$foo'">'$foo'</a></td>' >> $file
	echo '<td>'`filetest -M: $foo`'</td>' >> $file
	echo '</tr>' >> $file
end
echo '</table>' >> $file

# Analysis directory listing
echo '<h2>Complete contents of <em>'`pwd`'</em>:</h2>' >> $file
echo '<pre>' >> $file
ls -lh       >> $file
echo '<pre>' >> $file

# HTML footer
echo '</body></html>' >> $file

# Put it all on the web
backup
