#!/usr/local/bin/perl

#This script traverses the directory specified in $listpath and looks
#for all ortep files.  Then, for each ortep, it it uses ghostscript
#to make a GIF file from the PostScript file, and a GIF thumbnail.
#An HTML file is also written for a page featuring the thumbnail images
#inlined, with pointers to the full sized GIFs.

#The HTML generated should look like this:
#	<P><A HREF=$bigname>
#	<IMG ALIGN=center WIDTH=144 HEIGHT=144 SRC=$thumbname>
#	$psfile
#	</A></P>

$prehtml="<P><A HREF=";
$midhtml=">\n<IMG ALIGN=center WIDTH=144 HEIGHT=144 SRC=";
$posthtml="</A></P>";
$number="00";

#find all the ortep files
$listpath="/usr/people/texsan/";
@files=ind $listpath. -name 'ortep*.ps' -print;

#this is the html that will contain links to all the images
open(HTML,">texsan_ps.html");

#step through all the ortep files, write the html, a thumbnail gif, and a 
#full size gif
foreach $psfile (@files) {
  ++$number;				
  $bigname="xraygif$number.gif";		
  $thumbname="xraygif_thumb$number.gif";
  $bigcommands="-q -sDEVICE=gif8 -sOutputFile=$bigname";
  $thumbcommands="-q -sDEVICE=gif8 -r20 -sOutputFile=$thumbname";
  open(CMD,"|gs $bigcommands $psfile");
  print CMD "quit";
  close(CMD);
  open(CMD,"|gs $thumbcommands $psfile");
  print CMD "quit";
  close(CMD);
  print HTML "$prehtml $bigname $midhtml $thumbname >\n $psfile\n$posthtml\n";
  }
close(HTML);
                          