| 1 |
molod |
1.1 |
#!/bin/csh |
| 2 |
|
|
# |
| 3 |
|
|
# Reads an eps file(s) created by matlab, possibly with many |
| 4 |
|
|
# frames, and creates html/gif from it. See "man page" at the |
| 5 |
|
|
# end of this file. |
| 6 |
|
|
# |
| 7 |
|
|
# Required utilities |
| 8 |
|
|
# ------------------ |
| 9 |
|
|
set CONVERT = /usr/bin/convert # ImageMagick convert |
| 10 |
|
|
|
| 11 |
|
|
# No args |
| 12 |
|
|
# -------- |
| 13 |
|
|
if ( $#argv < 1 ) goto usage |
| 14 |
|
|
|
| 15 |
|
|
# Parse command line arguments |
| 16 |
|
|
# ---------------------------- |
| 17 |
|
|
set title = 'EPS HTML Translator' |
| 18 |
|
|
set dirn = " " |
| 19 |
|
|
set notes = " " |
| 20 |
|
|
set verb = 1 # verbose mode |
| 21 |
|
|
set contents = 0 |
| 22 |
|
|
foreach token ( $argv ) |
| 23 |
|
|
if ( "$token" == "-p" ) then |
| 24 |
|
|
set mode = 'Portrait' # obsolete, no effect |
| 25 |
|
|
shift |
| 26 |
|
|
endif |
| 27 |
|
|
if ( "$token" == "-q" ) then |
| 28 |
|
|
set verb = 0 |
| 29 |
|
|
shift |
| 30 |
|
|
endif |
| 31 |
|
|
if ( "$token" == "-c" ) then |
| 32 |
|
|
set contents = 1 |
| 33 |
|
|
shift |
| 34 |
|
|
endif |
| 35 |
|
|
if ( "$token" == "-t" ) then |
| 36 |
|
|
shift |
| 37 |
|
|
set title = ( $1 ) |
| 38 |
|
|
shift |
| 39 |
|
|
endif |
| 40 |
|
|
if ( "$token" == "-d" ) then |
| 41 |
|
|
shift |
| 42 |
|
|
if ( $#argv < 1 ) goto usage |
| 43 |
|
|
set dirn = $1 |
| 44 |
|
|
shift |
| 45 |
|
|
endif |
| 46 |
|
|
if ( "$token" == "-n" ) then |
| 47 |
|
|
shift |
| 48 |
|
|
if ( $#argv < 1 ) goto usage |
| 49 |
|
|
set notes = $1 |
| 50 |
|
|
shift |
| 51 |
|
|
if ( !(-e $notes) ) then |
| 52 |
|
|
echo "epshtml: cannot open notes file $notes" |
| 53 |
|
|
exit 1 |
| 54 |
|
|
endif |
| 55 |
|
|
endif |
| 56 |
|
|
end |
| 57 |
|
|
|
| 58 |
|
|
|
| 59 |
|
|
# Make sure all eps files are there |
| 60 |
|
|
# -------------------------------- |
| 61 |
|
|
if ( $#argv < 1 ) goto usage |
| 62 |
|
|
foreach epsfilen ( $argv ) |
| 63 |
|
|
if ( !(-e $epsfilen) ) then |
| 64 |
|
|
echo "epshtml: cannot find file $epsfilen" |
| 65 |
|
|
exit 1 |
| 66 |
|
|
endif |
| 67 |
|
|
endif |
| 68 |
|
|
|
| 69 |
|
|
if ( $verb ) echo " " |
| 70 |
|
|
if ( $verb ) echo "EPS to HTML starting . . ." |
| 71 |
|
|
|
| 72 |
|
|
|
| 73 |
|
|
# Create or reuse directory for HTML/GIF files, |
| 74 |
|
|
# -------------------------------------------- |
| 75 |
|
|
if ( x$dirn == x ) then |
| 76 |
|
|
set basen = `basename $1` |
| 77 |
|
|
set dirn = $basen:r |
| 78 |
|
|
endif |
| 79 |
|
|
if ( -d $dirn ) then |
| 80 |
|
|
if ( $verb ) echo " o Re-using directory $dirn/ for html/gif files" |
| 81 |
|
|
touch $dirn/index.html |
| 82 |
|
|
if ( $status ) then |
| 83 |
|
|
echo "epshtml: cannot write to directory $dirn" |
| 84 |
|
|
exit 1 |
| 85 |
|
|
endif |
| 86 |
|
|
else |
| 87 |
|
|
if ( $verb ) echo " o Creating directory $dirn/ for html/gif files" |
| 88 |
|
|
mkdir $dirn |
| 89 |
|
|
if ( $status ) then |
| 90 |
|
|
echo "epshtml: cannot create directory $dirn" |
| 91 |
|
|
exit 1 |
| 92 |
|
|
endif |
| 93 |
|
|
endif |
| 94 |
|
|
|
| 95 |
|
|
|
| 96 |
|
|
# Create HTML header |
| 97 |
|
|
# ------------------ |
| 98 |
|
|
set htmlfn = $dirn/index.html |
| 99 |
|
|
if ( -e $htmlfn ) /bin/rm -r $htmlfn |
| 100 |
|
|
echo "<HTML>" > $htmlfn |
| 101 |
|
|
echo "<HEAD><title> $title </title></HEAD>" >> $htmlfn |
| 102 |
|
|
echo "<BODY BGCOLOR=#FFFFFF TEXT=#000000" >> $htmlfn |
| 103 |
|
|
echo "LINK=#0000FF VLINK=#006030>" >> $htmlfn |
| 104 |
|
|
echo "<p><center><h1><font size=6 color=#FF0000>" >> $htmlfn |
| 105 |
|
|
echo $title >> $htmlfn |
| 106 |
|
|
echo "</font> </h1></center>" >> $htmlfn |
| 107 |
|
|
if ( x$notes != x ) then |
| 108 |
|
|
echo "<p>" >> $htmlfn |
| 109 |
|
|
cat $notes >> $htmlfn |
| 110 |
|
|
echo "<p>" >> $htmlfn |
| 111 |
|
|
endif |
| 112 |
|
|
echo "<p><center><i><font size=2 color=#0000ff>" >> $htmlfn |
| 113 |
|
|
echo "Click on the images below to enlarge them" >> $htmlfn |
| 114 |
|
|
echo "</font></i></center>" >> $htmlfn |
| 115 |
|
|
if ( $contents ) echo "<p><hr><p>" >> $htmlfn |
| 116 |
|
|
|
| 117 |
|
|
# Loop over eps files |
| 118 |
|
|
# ------------------ |
| 119 |
|
|
foreach epsfilen ( $argv ) |
| 120 |
|
|
|
| 121 |
|
|
if ( !(-e $epsfilen) ) then |
| 122 |
|
|
echo "epshtml: cannot find file $epsfilen |
| 123 |
|
|
exit 1 |
| 124 |
|
|
endif |
| 125 |
|
|
set basen = $epsfilen:r |
| 126 |
|
|
|
| 127 |
|
|
|
| 128 |
|
|
# land/port mode vary for each file |
| 129 |
|
|
# --------------------------------- |
| 130 |
|
|
set mode = 'Portrait' |
| 131 |
|
|
if ( $status ) goto cleanup |
| 132 |
|
|
if ( "$mode" == "Landscape" ) then |
| 133 |
|
|
set rotate = '-rotate 90' |
| 134 |
|
|
else |
| 135 |
|
|
set rotate = ' ' |
| 136 |
|
|
endif |
| 137 |
|
|
|
| 138 |
|
|
|
| 139 |
|
|
# Make postscript/gif in a pipe |
| 140 |
|
|
# ----------------------------- |
| 141 |
|
|
if ( $verb ) echo " o Creating GIF images from $mode metafile ${epsfilen}" |
| 142 |
|
|
set tbasen = $dirn/$basen.tmp |
| 143 |
|
|
echo "convert from "$epsfilen "to "$tbasen":" |
| 144 |
|
|
$CONVERT +adjoin -density 60x60 $rotate eps:$epsfilen gif:$tbasen >& /dev/null |
| 145 |
|
|
|
| 146 |
|
|
if ( $status ) goto cleanup |
| 147 |
|
|
foreach tmp ( $tbasen* ) |
| 148 |
|
|
set fno = $tmp:e |
| 149 |
|
|
if ( "$fno" != "tmp" ) then |
| 150 |
|
|
@ fno = 100 + $fno |
| 151 |
|
|
set gif = $dirn/${basen}_p$fno.gif |
| 152 |
|
|
else |
| 153 |
|
|
set gif = $dirn/${basen}_p100.gif |
| 154 |
|
|
endif |
| 155 |
|
|
mv $tmp $gif # Rename GIF files |
| 156 |
|
|
if ( $verb ) echo " o Created GIF file $gif " |
| 157 |
|
|
end |
| 158 |
|
|
|
| 159 |
|
|
|
| 160 |
|
|
# Make thumbnail sketches (Note: could create sketches from GIF) |
| 161 |
|
|
# -------------------------------------------------------------- |
| 162 |
|
|
if ( ! $contents ) then |
| 163 |
|
|
if ( $verb ) echo " o Creating thumbnail sketches from $mode metafile ${epsfilen}" |
| 164 |
|
|
set tbasen = $dirn/$basen.tmp |
| 165 |
|
|
$CONVERT +adjoin -density 16x16 $rotate eps:$epsfilen gif:$tbasen >& /dev/null |
| 166 |
|
|
if ( $status ) goto cleanup |
| 167 |
|
|
foreach tmp ( $tbasen* ) |
| 168 |
|
|
set fno = $tmp:e |
| 169 |
|
|
if ( "$fno" != "tmp" ) then |
| 170 |
|
|
@ fno = 100 + $fno |
| 171 |
|
|
set gif = $dirn/${basen}_t$fno.gif |
| 172 |
|
|
else |
| 173 |
|
|
set gif = $dirn/${basen}_t100.gif |
| 174 |
|
|
endif |
| 175 |
|
|
mv $tmp $gif # Rename GIF files |
| 176 |
|
|
if ( $verb ) echo " o Created GIF file $gif " |
| 177 |
|
|
end |
| 178 |
|
|
endif |
| 179 |
|
|
|
| 180 |
|
|
# Add HTML lines for these files |
| 181 |
|
|
# ------------------------------ |
| 182 |
|
|
echo " " >> $htmlfn |
| 183 |
|
|
echo "<p>Images from file <font size=4 color=#ff0000>" >> $htmlfn |
| 184 |
|
|
echo "$epsfilen </font>" >> $htmlfn |
| 185 |
|
|
if ( $contents ) then |
| 186 |
|
|
echo ": " >> $htmlfn |
| 187 |
|
|
else |
| 188 |
|
|
echo "<hr>" >> $htmlfn |
| 189 |
|
|
endif |
| 190 |
|
|
set fno = 1 |
| 191 |
|
|
foreach gifpage ( $dirn/${basen}_p*.gif ) |
| 192 |
|
|
set gifbase = `basename $gifpage` |
| 193 |
|
|
set thumb = `echo $gifbase | sed -e 's/_p/_t/g'` |
| 194 |
|
|
if ( $contents ) then |
| 195 |
|
|
echo " | <a href=$gifbase>$fno</a>" >> $htmlfn |
| 196 |
|
|
@ fno++ |
| 197 |
|
|
else |
| 198 |
|
|
echo "<a href=$gifbase><img src=$thumb></a>" >> $htmlfn |
| 199 |
|
|
endif |
| 200 |
|
|
end |
| 201 |
|
|
if ( $contents ) then |
| 202 |
|
|
echo "| <p>" >> $htmlfn |
| 203 |
|
|
else |
| 204 |
|
|
echo "<hr>" >> $htmlfn |
| 205 |
|
|
endif |
| 206 |
|
|
|
| 207 |
|
|
end |
| 208 |
|
|
|
| 209 |
|
|
|
| 210 |
|
|
# Records when and by whom document was created |
| 211 |
|
|
# --------------------------------------------- |
| 212 |
|
|
set usern = `whoami` |
| 213 |
|
|
echo \$1 == \"$usern\" \{print \$5\} >! $tmp |
| 214 |
|
|
set whom = `awk -F: -f $tmp < /etc/passwd|awk -F, '{print $1}'` |
| 215 |
|
|
if ( $#whom < 1 ) set whom = $usern |
| 216 |
|
|
set when = `date` |
| 217 |
|
|
|
| 218 |
|
|
# Now clean-up mess |
| 219 |
|
|
# ----------------- |
| 220 |
|
|
# /bin/rm -r $tmp $dirn/*.ps |
| 221 |
|
|
if ( $verb ) echo "EPS to HTML exited normally" |
| 222 |
|
|
if ( $verb ) echo " " |
| 223 |
|
|
exit 0 |
| 224 |
|
|
|
| 225 |
|
|
cleanup: |
| 226 |
|
|
# /bin/rm -r $tmp $dirn/*.ps |
| 227 |
|
|
if ( $verb ) echo "EPS to HTML exited abnormally" |
| 228 |
|
|
exit 1 |
| 229 |
|
|
|
| 230 |
|
|
|
| 231 |
|
|
usage: |
| 232 |
|
|
cat << ---//--- |
| 233 |
|
|
|
| 234 |
|
|
NAME |
| 235 |
|
|
epsHTML - EPS HTML Translator |
| 236 |
|
|
|
| 237 |
|
|
SYNOPSIS |
| 238 |
|
|
epshtml [-q] [-c] [-d path] [-n file] [-t title] eps_file(s) |
| 239 |
|
|
|
| 240 |
|
|
DESCRIPTION |
| 241 |
|
|
This utility creates a HTML document with images from eps files. |
| 242 |
|
|
Clickable thumbnail sketches are produced for each of the |
| 243 |
|
|
images, with higher resolution images accessible with a mouse click. |
| 244 |
|
|
This utility, together with your favorite web browser, can be used |
| 245 |
|
|
as a starting point for building customized |
| 246 |
|
|
web pages. |
| 247 |
|
|
|
| 248 |
|
|
For the heavy duty conversion work this utility relies |
| 249 |
|
|
on the ImageMagick 'convert' utility. This |
| 250 |
|
|
packages must be installed on your system. epsHTML is nothing |
| 251 |
|
|
more than a C-Shell script driving the package. |
| 252 |
|
|
|
| 253 |
|
|
OPTIONS |
| 254 |
|
|
-d path directory for output HTML/GIF files, default |
| 255 |
|
|
is to use the base name of the first eps file, |
| 256 |
|
|
i.e., if the file name is 'myfile.eps', the |
| 257 |
|
|
directory will be 'myfile' |
| 258 |
|
|
-n file specify ASCII file with notes to be appended to |
| 259 |
|
|
output HTML |
| 260 |
|
|
-q quiet mode (default is verbose) |
| 261 |
|
|
-c include a text "table of contents" instead of thumbnail |
| 262 |
|
|
sketches (this is faster) |
| 263 |
|
|
-t title title for output HTML document, the default is |
| 264 |
|
|
'epsHTML - eps HTML Translator' |
| 265 |
|
|
|
| 266 |
|
|
EXAMPLE |
| 267 |
|
|
epshtml myfile.eps |
| 268 |
|
|
netscape myfile/index.html |
| 269 |
|
|
|
| 270 |
|
|
---//--- |
| 271 |
|
|
exit 1 |