home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / tex / dvips / !TeX / TeXInputs / Local / psfig < prev    next >
Encoding:
Text File  |  1994-10-23  |  34.4 KB  |  896 lines

  1. % Psfig/TeX
  2. \def\PsfigVersion{1.9}
  3. % dvips version
  4. %
  5. % All psfig/tex software, documentation, and related files
  6. % in this distribution of psfig/tex are 
  7. % Copyright 1987, 1988, 1991 Trevor J. Darrell
  8. %
  9. % Permission is granted for use and non-profit distribution of psfig/tex 
  10. % providing that this notice is clearly maintained. The right to
  11. % distribute any portion of psfig/tex for profit or as part of any commercial
  12. % product is specifically reserved for the author(s) of that portion.
  13. %
  14. % *** Feel free to make local modifications of psfig as you wish,
  15. % *** but DO NOT post any changed or modified versions of ``psfig''
  16. % *** directly to the net. Send them to me and I'll try to incorporate
  17. % *** them into future versions. If you want to take the psfig code 
  18. % *** and make a new program (subject to the copyright above), distribute it, 
  19. % *** (and maintain it) that's fine, just don't call it psfig.
  20. %
  21. % Bugs and improvements to trevor@media.mit.edu.
  22. %
  23. % Thanks to Greg Hager (GDH) and Ned Batchelder for their contributions
  24. % to the original version of this project.
  25. %
  26. % Modified by J. Daniel Smith on 9 October 1990 to accept the
  27. % %%BoundingBox: comment with or without a space after the colon.  Stole
  28. % file reading code from Tom Rokicki's EPSF.TEX file (see below).
  29. %
  30. % More modifications by J. Daniel Smith on 29 March 1991 to allow the
  31. % the included PostScript figure to be rotated.  The amount of
  32. % rotation is specified by the "angle=" parameter of the \psfig command.
  33. %
  34. % Modified by Robert Russell on June 25, 1991 to allow users to specify
  35. % .ps filenames which don't yet exist, provided they explicitly provide
  36. % boundingbox information via the \psfig command. Note: This will only work
  37. % if the "file=" parameter follows all four "bb???=" parameters in the
  38. % command. This is due to the order in which psfig interprets these params.
  39. %
  40. %  3 Jul 1991   JDS     check if file already read in once
  41. %  4 Sep 1991   JDS     fixed incorrect computation of rotated
  42. %                       bounding box
  43. % 25 Sep 1991   GVR     expanded synopsis of \psfig
  44. % 14 Oct 1991   JDS     \fbox code from LaTeX so \psdraft works with TeX
  45. %                       changed \typeout to \ps@typeout
  46. % 17 Oct 1991   JDS     added \psscalefirst and \psrotatefirst
  47. %
  48.  
  49. % From: gvr@cs.brown.edu (George V. Reilly)
  50. %
  51. % \psdraft      draws an outline box, but doesn't include the figure
  52. %               in the DVI file.  Useful for previewing.
  53. %
  54. % \psfull       includes the figure in the DVI file (default).
  55. %
  56. % \psscalefirst width= or height= specifies the size of the figure
  57. %               before rotation.
  58. % \psrotatefirst (default) width= or height= specifies the size of the
  59. %                figure after rotation.  Asymetric figures will
  60. %                appear to shrink.
  61. %
  62. % \psfigurepath#1       sets the path to search for the figure
  63. %
  64. % \psfig
  65. % usage: \psfig{file=, figure=, height=, width=,
  66. %                       bbllx=, bblly=, bburx=, bbury=,
  67. %                       rheight=, rwidth=, clip=, angle=, silent=}
  68. %
  69. %       "file" is the filename.  If no path name is specified and the
  70. %               file is not found in the current directory,
  71. %               it will be looked for in directory \psfigurepath.
  72. %       "figure" is a synonym for "file".
  73. %       By default, the width and height of the figure are taken from
  74. %               the BoundingBox of the figure.
  75. %       If "width" is specified, the figure is scaled so that it has
  76. %               the specified width.  Its height changes proportionately.
  77. %       If "height" is specified, the figure is scaled so that it has
  78. %               the specified height.  Its width changes proportionately.
  79. %       If both "width" and "height" are specified, the figure is scaled
  80. %               anamorphically.
  81. %       "bbllx", "bblly", "bburx", and "bbury" control the PostScript
  82. %               BoundingBox.  If these four values are specified
  83. %               *before* the "file" option, the PSFIG will not try to
  84. %               open the PostScript file.
  85. %       "rheight" and "rwidth" are the reserved height and width
  86. %               of the figure, i.e., how big TeX actually thinks
  87. %               the figure is.  They default to "width" and "height".
  88. %       The "clip" option ensures that no portion of the figure will
  89. %               appear outside its BoundingBox.  "clip=" is a switch and
  90. %               takes no value, but the `=' must be present.
  91. %       The "angle" option specifies the angle of rotation (degrees, ccw).
  92. %       The "silent" option makes \psfig work silently.
  93. %
  94.  
  95. % check to see if macros already loaded in (maybe some other file says
  96. % "\input psfig") ...
  97. \ifx\undefined\psfig\else\endinput\fi
  98.  
  99. %
  100. % from a suggestion by eijkhout@csrd.uiuc.edu to allow
  101. % loading as a style file. Changed to avoid problems
  102. % with amstex per suggestion by jbence@math.ucla.edu
  103.  
  104. \let\LaTeXAtSign=\@
  105. \let\@=\relax
  106. \edef\psfigRestoreAt{\catcode`\@=\number\catcode`@\relax}
  107. %\edef\psfigRestoreAt{\catcode`@=\number\catcode`@\relax}
  108. \catcode`\@=11\relax
  109. \newwrite\@unused
  110. \def\ps@typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
  111. \ps@typeout{psfig/tex \PsfigVersion}
  112.  
  113. %% Here's how you define your figure path.  Should be set up with null
  114. %% default and a user useable definition.
  115.  
  116. \def\figurepath{./}
  117. \def\psfigurepath#1{\edef\figurepath{#1}}
  118.  
  119. %
  120. % @psdo control structure -- similar to Latex @for.
  121. % I redefined these with different names so that psfig can
  122. % be used with TeX as well as LaTeX, and so that it will not 
  123. % be vunerable to future changes in LaTeX's internal
  124. % control structure,
  125. %
  126. \def\@nnil{\@nil}
  127. \def\@empty{}
  128. \def\@psdonoop#1\@@#2#3{}
  129. \def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  130.     \expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
  131. \def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
  132.        #5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
  133. \def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  134.        \let\@nextwhile=\@psdonoop \else
  135.       #4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
  136. \def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  137.     \@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
  138. \def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  139.        \let\@nextwhile=\@psdonoop \else
  140.       #4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
  141. % \fbox is defined in latex.tex; so if \fbox is undefined, assume that
  142. % we are not in LaTeX.
  143. % Perhaps this could be done better???
  144. \ifx\undefined\fbox
  145. % \fbox code from modified slightly from LaTeX
  146. \newdimen\fboxrule
  147. \newdimen\fboxsep
  148. \newdimen\ps@tempdima
  149. \newbox\ps@tempboxa
  150. \fboxsep = 3pt
  151. \fboxrule = .4pt
  152. \long\def\fbox#1{\leavevmode\setbox\ps@tempboxa\hbox{#1}\ps@tempdima\fboxrule
  153.     \advance\ps@tempdima \fboxsep \advance\ps@tempdima \dp\ps@tempboxa
  154.    \hbox{\lower \ps@tempdima\hbox
  155.   {\vbox{\hrule height \fboxrule
  156.           \hbox{\vrule width \fboxrule \hskip\fboxsep
  157.           \vbox{\vskip\fboxsep \box\ps@tempboxa\vskip\fboxsep}\hskip 
  158.                  \fboxsep\vrule width \fboxrule}
  159.                  \hrule height \fboxrule}}}}
  160. \fi
  161. %
  162. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  163. % file reading stuff from epsf.tex
  164. %   EPSF.TEX macro file:
  165. %   Written by Tomas Rokicki of Radical Eye Software, 29 Mar 1989.
  166. %   Revised by Don Knuth, 3 Jan 1990.
  167. %   Revised by Tomas Rokicki to accept bounding boxes with no
  168. %      space after the colon, 18 Jul 1990.
  169. %   Portions modified/removed for use in PSFIG package by
  170. %      J. Daniel Smith, 9 October 1990.
  171. %
  172. \newread\ps@stream
  173. \newif\ifnot@eof       % continue looking for the bounding box?
  174. \newif\if@noisy        % report what you're making?
  175. \newif\if@atend        % %%BoundingBox: has (at end) specification
  176. \newif\if@psfile       % does this look like a PostScript file?
  177. %
  178. % PostScript files should start with `%!'
  179. %
  180. {\catcode`\%=12\global\gdef\epsf@start{%!}}
  181. \def\epsf@PS{PS}
  182. %
  183. \def\epsf@getbb#1{%
  184. %
  185. %   The first thing we need to do is to open the
  186. %   PostScript file, if possible.
  187. %
  188. \openin\ps@stream=#1
  189. \ifeof\ps@stream\ps@typeout{Error, File #1 not found}\else
  190. %
  191. %   Okay, we got it. Now we'll scan lines until we find one that doesn't
  192. %   start with %. We're looking for the bounding box comment.
  193. %
  194.    {\not@eoftrue \chardef\other=12
  195.     \def\do##1{\catcode`##1=\other}\dospecials \catcode`\ =10
  196.     \loop
  197.        \if@psfile
  198.           \read\ps@stream to \epsf@fileline
  199.        \else{
  200.           \obeyspaces
  201.           \read\ps@stream to \epsf@tmp\global\let\epsf@fileline\epsf@tmp}
  202.        \fi
  203.        \ifeof\ps@stream\not@eoffalse\else
  204. %
  205. %   Check the first line for `%!'.  Issue a warning message if its not
  206. %   there, since the file might not be a PostScript file.
  207. %
  208.        \if@psfile\else
  209.        \expandafter\epsf@test\epsf@fileline:. \\%
  210.        \fi
  211. %
  212. %   We check to see if the first character is a % sign;
  213. %   if so, we look further and stop only if the line begins with
  214. %   `%%BoundingBox:' and the `(atend)' specification was not found.
  215. %   That is, the only way to stop is when the end of file is reached,
  216. %   or a `%%BoundingBox: llx lly urx ury' line is found.
  217. %
  218.           \expandafter\epsf@aux\epsf@fileline:. \\%
  219.        \fi
  220.    \ifnot@eof\repeat
  221.    }\closein\ps@stream\fi}%
  222. %
  223. % This tests if the file we are reading looks like a PostScript file.
  224. %
  225. \long\def\epsf@test#1#2#3:#4\\{\def\epsf@testit{#1#2}
  226.                         \ifx\epsf@testit\epsf@start\else
  227. \ps@typeout{Warning! File does not start with `\epsf@start'.  It may not be a PostScript file.}
  228.                         \fi
  229.                         \@psfiletrue} % don't test after 1st line
  230. %
  231. %   We still need to define the tricky \epsf@aux macro. This requires
  232. %   a couple of magic constants for comparison purposes.
  233. %
  234. {\catcode`\%=12\global\let\epsf@percent=%\global\def\epsf@bblit{%BoundingBox}}
  235. %
  236. %
  237. %   So we're ready to check for `%BoundingBox:' and to grab the
  238. %   values if they are found.  We continue searching if `(at end)'
  239. %   was found after the `%BoundingBox:'.
  240. %
  241. \long\def\epsf@aux#1#2:#3\\{\ifx#1\epsf@percent
  242.    \def\epsf@testit{#2}\ifx\epsf@testit\epsf@bblit
  243.         \@atendfalse
  244.         \epsf@atend #3 . \\%
  245.         \if@atend       
  246.            \if@verbose{
  247.                 \ps@typeout{psfig: found `(atend)'; continuing search}
  248.            }\fi
  249.         \else
  250.         \epsf@grab #3 . . . \\%
  251.         \not@eoffalse
  252.         \global\no@bbfalse
  253.         \fi
  254.    \fi\fi}%
  255. %
  256. %   Here we grab the values and stuff them in the appropriate definitions.
  257. %
  258. \def\epsf@grab #1 #2 #3 #4 #5\\{%
  259.    \global\def\epsf@llx{#1}\ifx\epsf@llx\empty
  260.       \epsf@grab #2 #3 #4 #5 .\\\else
  261.    \global\def\epsf@lly{#2}%
  262.    \global\def\epsf@urx{#3}\global\def\epsf@ury{#4}\fi}%
  263. %
  264. % Determine if the stuff following the %%BoundingBox is `(atend)'
  265. % J. Daniel Smith.  Copied from \epsf@grab above.
  266. %
  267. \def\epsf@atendlit{(atend)} 
  268. \def\epsf@atend #1 #2 #3\\{%
  269.    \def\epsf@tmp{#1}\ifx\epsf@tmp\empty
  270.       \epsf@atend #2 #3 .\\\else
  271.    \ifx\epsf@tmp\epsf@atendlit\@atendtrue\fi\fi}
  272.  
  273.  
  274. % End of file reading stuff from epsf.tex
  275. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  276.  
  277. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  278. % trigonometry stuff from "trig.tex"
  279. \chardef\psletter = 11 % won't conflict with \begin{letter} now...
  280. \chardef\other = 12
  281.  
  282. \newif \ifdebug %%% turn me on to see TeX hard at work ...
  283. \newif\ifc@mpute %%% don't need to compute some values
  284. \c@mputetrue % but assume that we do
  285.  
  286. \let\then = \relax
  287. \def\r@dian{pt }
  288. \let\r@dians = \r@dian
  289. \let\dimensionless@nit = \r@dian
  290. \let\dimensionless@nits = \dimensionless@nit
  291. \def\internal@nit{sp }
  292. \let\internal@nits = \internal@nit
  293. \newif\ifstillc@nverging
  294. \def \Mess@ge #1{\ifdebug \then \message {#1} \fi}
  295.  
  296. { %%% Things that need abnormal catcodes %%%
  297.         \catcode `\@ = \psletter
  298.         \gdef \nodimen {\expandafter \n@dimen \the \dimen}
  299.         \gdef \term #1 #2 #3%
  300.                {\edef \t@ {\the #1}%%% freeze parameter 1 (count, by value)
  301.                 \edef \t@@ {\expandafter \n@dimen \the #2\r@dian}%
  302.                                    %%% freeze parameter 2 (dimen, by value)
  303.                 \t@rm {\t@} {\t@@} {#3}%
  304.                }
  305.         \gdef \t@rm #1 #2 #3%
  306.                {{%
  307.                 \count 0 = 0
  308.                 \dimen 0 = 1 \dimensionless@nit
  309.                 \dimen 2 = #2\relax
  310.                 \Mess@ge {Calculating term #1 of \nodimen 2}%
  311.                 \loop
  312.                 \ifnum  \count 0 < #1
  313.                 \then   \advance \count 0 by 1
  314.                         \Mess@ge {Iteration \the \count 0 \space}%
  315.                         \Multiply \dimen 0 by {\dimen 2}%
  316.                         \Mess@ge {After multiplication, term = \nodimen 0}%
  317.                         \Divide \dimen 0 by {\count 0}%
  318.                         \Mess@ge {After division, term = \nodimen 0}%
  319.                 \repeat
  320.                 \Mess@ge {Final value for term #1 of 
  321.                                 \nodimen 2 \space is \nodimen 0}%
  322.                 \xdef \Term {#3 = \nodimen 0 \r@dians}%
  323.                 \aftergroup \Term
  324.                }}
  325.         \catcode `\p = \other
  326.         \catcode `\t = \other
  327.         \gdef \n@dimen #1pt{#1} %%% throw away the ``pt''
  328. }
  329.  
  330. \def \Divide #1by #2{\divide #1 by #2} %%% just a synonym
  331.  
  332. \def \Multiply #1by #2%%% allows division of a dimen by a dimen
  333.        {{%%% should really freeze parameter 2 (dimen, passed by value)
  334.         \count 0 = #1\relax
  335.         \count 2 = #2\relax
  336.         \count 4 = 65536
  337.         \Mess@ge {Before scaling, count 0 = \the \count 0 \space and
  338.                         count 2 = \the \count 2}%
  339.         \ifnum  \count 0 > 32767 %%% do our best to avoid overflow
  340.         \then   \divide \count 0 by 4
  341.                 \divide \count 4 by 4
  342.         \else   \ifnum  \count 0 < -32767
  343.                 \then   \divide \count 0 by 4
  344.                         \divide \count 4 by 4
  345.                 \else
  346.                 \fi
  347.         \fi
  348.         \ifnum  \count 2 > 32767 %%% while retaining reasonable accuracy
  349.         \then   \divide \count 2 by 4
  350.                 \divide \count 4 by 4
  351.         \else   \ifnum  \count 2 < -32767
  352.                 \then   \divide \count 2 by 4
  353.                         \divide \count 4 by 4
  354.                 \else
  355.                 \fi
  356.         \fi
  357.         \multiply \count 0 by \count 2
  358.         \divide \count 0 by \count 4
  359.         \xdef \product {#1 = \the \count 0 \internal@nits}%
  360.         \aftergroup \product
  361.        }}
  362.  
  363. \def\r@duce{\ifdim\dimen0 > 90\r@dian \then   % sin(x+90) = sin(180-x)
  364.                 \multiply\dimen0 by -1
  365.                 \advance\dimen0 by 180\r@dian
  366.                 \r@duce
  367.             \else \ifdim\dimen0 < -90\r@dian \then  % sin(-x) = sin(360+x)
  368.                 \advance\dimen0 by 360\r@dian
  369.                 \r@duce
  370.                 \fi
  371.             \fi}
  372.  
  373. \def\Sine#1%
  374.        {{%
  375.         \dimen 0 = #1 \r@dian
  376.         \r@duce
  377.         \ifdim\dimen0 = -90\r@dian \then
  378.            \dimen4 = -1\r@dian
  379.            \c@mputefalse
  380.         \fi
  381.         \ifdim\dimen0 = 90\r@dian \then
  382.            \dimen4 = 1\r@dian
  383.            \c@mputefalse
  384.         \fi
  385.         \ifdim\dimen0 = 0\r@dian \then
  386.            \dimen4 = 0\r@dian
  387.            \c@mputefalse
  388.         \fi
  389. %
  390.         \ifc@mpute \then
  391.                 % convert degrees to radians
  392.                 \divide\dimen0 by 180
  393.                 \dimen0=3.141592654\dimen0
  394. %
  395.                 \dimen 2 = 3.1415926535897963\r@dian %%% a well-known constant
  396.                 \divide\dimen 2 by 2 %%% we only deal with -pi/2 : pi/2
  397.                 \Mess@ge {Sin: calculating Sin of \nodimen 0}%
  398.                 \count 0 = 1 %%% see power-series expansion for sine
  399.                 \dimen 2 = 1 \r@dian %%% ditto
  400.                 \dimen 4 = 0 \r@dian %%% ditto
  401.                 \loop
  402.                         \ifnum  \dimen 2 = 0 %%% then we've done
  403.                         \then   \stillc@nvergingfalse 
  404.                         \else   \stillc@nvergingtrue
  405.                         \fi
  406.                         \ifstillc@nverging %%% then calculate next term
  407.                         \then   \term {\count 0} {\dimen 0} {\dimen 2}%
  408.                                 \advance \count 0 by 2
  409.                                 \count 2 = \count 0
  410.                                 \divide \count 2 by 2
  411.                                 \ifodd  \count 2 %%% signs alternate
  412.                                 \then   \advance \dimen 4 by \dimen 2
  413.                                 \else   \advance \dimen 4 by -\dimen 2
  414.                                 \fi
  415.                 \repeat
  416.         \fi             
  417.                         \xdef \sine {\nodimen 4}%
  418.        }}
  419.  
  420. % Now the Cosine can be calculated easily by calling \Sine
  421. \def\Cosine#1{\ifx\sine\UnDefined\edef\Savesine{\relax}\else
  422.                              \edef\Savesine{\sine}\fi
  423.         {\dimen0=#1\r@dian\advance\dimen0 by 90\r@dian
  424.          \Sine{\nodimen 0}
  425.          \xdef\cosine{\sine}
  426.          \xdef\sine{\Savesine}}}              
  427. % end of trig stuff
  428. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  429.  
  430. \def\psdraft{
  431.         \def\@psdraft{0}
  432.         %\ps@typeout{draft level now is \@psdraft \space . }
  433. }
  434. \def\psfull{
  435.         \def\@psdraft{100}
  436.         %\ps@typeout{draft level now is \@psdraft \space . }
  437. }
  438.  
  439. \psfull
  440.  
  441. \newif\if@scalefirst
  442. \def\psscalefirst{\@scalefirsttrue}
  443. \def\psrotatefirst{\@scalefirstfalse}
  444. \psrotatefirst
  445.  
  446. \newif\if@draftbox
  447. \def\psnodraftbox{
  448.         \@draftboxfalse
  449. }
  450. \def\psdraftbox{
  451.         \@draftboxtrue
  452. }
  453. \@draftboxtrue
  454.  
  455. \newif\if@prologfile
  456. \newif\if@postlogfile
  457. \def\pssilent{
  458.         \@noisyfalse
  459. }
  460. \def\psnoisy{
  461.         \@noisytrue
  462. }
  463. \psnoisy
  464. %%% These are for the option list.
  465. %%% A specification of the form a = b maps to calling \@p@@sa{b}
  466. \newif\if@bbllx
  467. \newif\if@bblly
  468. \newif\if@bburx
  469. \newif\if@bbury
  470. \newif\if@height
  471. \newif\if@width
  472. \newif\if@rheight
  473. \newif\if@rwidth
  474. \newif\if@angle
  475. \newif\if@clip
  476. \newif\if@verbose
  477. \def\@p@@sclip#1{\@cliptrue}
  478.  
  479.  
  480. \newif\if@decmpr
  481.  
  482. %%% GDH 7/26/87 -- changed so that it first looks in the local directory,
  483. %%% then in a specified global directory for the ps file.
  484. %%% RPR 6/25/91 -- changed so that it defaults to user-supplied name if
  485. %%% boundingbox info is specified, assuming graphic will be created by
  486. %%% print time.
  487. %%% TJD 10/19/91 -- added bbfile vs. file distinction, and @decmpr flag
  488.  
  489. \def\@p@@sfigure#1{\def\@p@sfile{null}\def\@p@sbbfile{null}
  490.                 \openin1=#1.bb
  491.                 \ifeof1\closein1
  492.                         \openin1=\figurepath#1.bb
  493.                         \ifeof1\closein1
  494.                                 \openin1=#1
  495.                                 \ifeof1\closein1%
  496.                                        \openin1=\figurepath#1
  497.                                         \ifeof1
  498.                                            \ps@typeout{Error, File #1 not found}
  499.                                                 \if@bbllx\if@bblly
  500.                                                 \if@bburx\if@bbury
  501.                                                         \def\@p@sfile{#1}%
  502.                                                         \def\@p@sbbfile{#1}%
  503.                                                         \@decmprfalse
  504.                                                 \fi\fi\fi\fi
  505.                                         \else\closein1
  506.                                                 \def\@p@sfile{\figurepath#1}%
  507.                                                 \def\@p@sbbfile{\figurepath#1}%
  508.                                                 \@decmprfalse
  509.                                         \fi%
  510.                                 \else\closein1%
  511.                                         \def\@p@sfile{#1}
  512.                                         \def\@p@sbbfile{#1}
  513.                                         \@decmprfalse
  514.                                 \fi
  515.                         \else
  516.                                 \def\@p@sfile{\figurepath#1}
  517.                                 \def\@p@sbbfile{\figurepath#1.bb}
  518.                                 \@decmprtrue
  519.                         \fi
  520.                 \else
  521.                         \def\@p@sfile{#1}
  522.                         \def\@p@sbbfile{#1.bb}
  523.                         \@decmprtrue
  524.                 \fi}
  525.  
  526. \def\@p@@sfile#1{\@p@@sfigure{#1}}
  527.  
  528. \def\@p@@sbbllx#1{
  529.                 %\ps@typeout{bbllx is #1}
  530.                 \@bbllxtrue
  531.                 \dimen100=#1
  532.                 \edef\@p@sbbllx{\number\dimen100}
  533. }
  534. \def\@p@@sbblly#1{
  535.                 %\ps@typeout{bblly is #1}
  536.                 \@bbllytrue
  537.                 \dimen100=#1
  538.                 \edef\@p@sbblly{\number\dimen100}
  539. }
  540. \def\@p@@sbburx#1{
  541.                 %\ps@typeout{bburx is #1}
  542.                 \@bburxtrue
  543.                 \dimen100=#1
  544.                 \edef\@p@sbburx{\number\dimen100}
  545. }
  546. \def\@p@@sbbury#1{
  547.                 %\ps@typeout{bbury is #1}
  548.                 \@bburytrue
  549.                 \dimen100=#1
  550.                 \edef\@p@sbbury{\number\dimen100}
  551. }
  552. \def\@p@@sheight#1{
  553.                 \@heighttrue
  554.                 \dimen100=#1
  555.                 \edef\@p@sheight{\number\dimen100}
  556.                 %\ps@typeout{Height is \@p@sheight}
  557. }
  558. \def\@p@@swidth#1{
  559.                 %\ps@typeout{Width is #1}
  560.                 \@widthtrue
  561.                 \dimen100=#1
  562.                 \edef\@p@swidth{\number\dimen100}
  563. }
  564. \def\@p@@srheight#1{
  565.                 %\ps@typeout{Reserved height is #1}
  566.                 \@rheighttrue
  567.                 \dimen100=#1
  568.                 \edef\@p@srheight{\number\dimen100}
  569. }
  570. \def\@p@@srwidth#1{
  571.                 %\ps@typeout{Reserved width is #1}
  572.                 \@rwidthtrue
  573.                 \dimen100=#1
  574.                 \edef\@p@srwidth{\number\dimen100}
  575. }
  576. \def\@p@@sangle#1{
  577.                 %\ps@typeout{Rotation is #1}
  578.                 \@angletrue
  579. %               \dimen100=#1
  580.                 \edef\@p@sangle{#1} %\number\dimen100}
  581. }
  582. \def\@p@@ssilent#1{ 
  583.                 \@verbosefalse
  584. }
  585. \def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
  586. \def\@p@@spostlog#1{\@postlogfiletrue\def\@postlogfileval{#1}}
  587. \def\@cs@name#1{\csname #1\endcsname}
  588. \def\@setparms#1=#2,{\@cs@name{@p@@s#1}{#2}}
  589. %
  590. % initialize the defaults (size the size of the figure)
  591. %
  592. \def\ps@init@parms{
  593.                 \@bbllxfalse \@bbllyfalse
  594.                 \@bburxfalse \@bburyfalse
  595.                 \@heightfalse \@widthfalse
  596.                 \@rheightfalse \@rwidthfalse
  597.                 \def\@p@sbbllx{}\def\@p@sbblly{}
  598.                 \def\@p@sbburx{}\def\@p@sbbury{}
  599.                 \def\@p@sheight{}\def\@p@swidth{}
  600.                 \def\@p@srheight{}\def\@p@srwidth{}
  601.                 \def\@p@sangle{0}
  602.                 \def\@p@sfile{} \def\@p@sbbfile{}
  603.                 \def\@p@scost{10}
  604.                 \def\@sc{}
  605.                 \@prologfilefalse
  606.                 \@postlogfilefalse
  607.                 \@clipfalse
  608.                 \if@noisy
  609.                         \@verbosetrue
  610.                 \else
  611.                         \@verbosefalse
  612.                 \fi
  613. }
  614. %
  615. % Go through the options setting things up.
  616. %
  617. \def\parse@ps@parms#1{
  618.                 \@psdo\@psfiga:=#1\do
  619.                    {\expandafter\@setparms\@psfiga,}}
  620. %
  621. % Compute bb height and width
  622. %
  623. \newif\ifno@bb
  624. \def\bb@missing{
  625.         \if@verbose{
  626.                 \ps@typeout{psfig: searching \@p@sbbfile \space  for bounding box}
  627.         }\fi
  628.         \no@bbtrue
  629.         \epsf@getbb{\@p@sbbfile}
  630.         \ifno@bb \else \bb@cull\epsf@llx\epsf@lly\epsf@urx\epsf@ury\fi
  631. }       
  632. \def\bb@cull#1#2#3#4{
  633.         \dimen100=#1 bp\edef\@p@sbbllx{\number\dimen100}
  634.         \dimen100=#2 bp\edef\@p@sbblly{\number\dimen100}
  635.         \dimen100=#3 bp\edef\@p@sbburx{\number\dimen100}
  636.         \dimen100=#4 bp\edef\@p@sbbury{\number\dimen100}
  637.         \no@bbfalse
  638. }
  639. % rotate point (#1,#2) about (0,0).
  640. % The sine and cosine of the angle are already stored in \sine and
  641. % \cosine.  The result is placed in (\p@intvaluex, \p@intvaluey).
  642. \newdimen\p@intvaluex
  643. \newdimen\p@intvaluey
  644. \def\rotate@#1#2{{\dimen0=#1 sp\dimen1=#2 sp
  645. %               calculate x' = x \cos\theta - y \sin\theta
  646.                   \global\p@intvaluex=\cosine\dimen0
  647.                   \dimen3=\sine\dimen1
  648.                   \global\advance\p@intvaluex by -\dimen3
  649. %               calculate y' = x \sin\theta + y \cos\theta
  650.                   \global\p@intvaluey=\sine\dimen0
  651.                   \dimen3=\cosine\dimen1
  652.                   \global\advance\p@intvaluey by \dimen3
  653.                   }}
  654. \def\compute@bb{
  655.                 \no@bbfalse
  656.                 \if@bbllx \else \no@bbtrue \fi
  657.                 \if@bblly \else \no@bbtrue \fi
  658.                 \if@bburx \else \no@bbtrue \fi
  659.                 \if@bbury \else \no@bbtrue \fi
  660.                 \ifno@bb \bb@missing \fi
  661.                 \ifno@bb \ps@typeout{FATAL ERROR: no bb supplied or found}
  662.                         \no-bb-error
  663.                 \fi
  664.                 %
  665. %\ps@typeout{BB: \@p@sbbllx, \@p@sbblly, \@p@sbburx, \@p@sbbury} 
  666. %
  667. % store height/width of original (unrotated) bounding box
  668.                 \count203=\@p@sbburx
  669.                 \count204=\@p@sbbury
  670.                 \advance\count203 by -\@p@sbbllx
  671.                 \advance\count204 by -\@p@sbblly
  672.                 \edef\ps@bbw{\number\count203}
  673.                 \edef\ps@bbh{\number\count204}
  674.                 %\ps@typeout{ psbbh = \ps@bbh, psbbw = \ps@bbw }
  675.                 \if@angle 
  676.                         \Sine{\@p@sangle}\Cosine{\@p@sangle}
  677.                         {\dimen100=\maxdimen\xdef\r@p@sbbllx{\number\dimen100}
  678.                                             \xdef\r@p@sbblly{\number\dimen100}
  679.                                             \xdef\r@p@sbburx{-\number\dimen100}
  680.                                             \xdef\r@p@sbbury{-\number\dimen100}}
  681. %
  682. % Need to rotate all four points and take the X-Y extremes of the new
  683. % points as the new bounding box.
  684.                         \def\minmaxtest{
  685.                            \ifnum\number\p@intvaluex<\r@p@sbbllx
  686.                               \xdef\r@p@sbbllx{\number\p@intvaluex}\fi
  687.                            \ifnum\number\p@intvaluex>\r@p@sbburx
  688.                               \xdef\r@p@sbburx{\number\p@intvaluex}\fi
  689.                            \ifnum\number\p@intvaluey<\r@p@sbblly
  690.                               \xdef\r@p@sbblly{\number\p@intvaluey}\fi
  691.                            \ifnum\number\p@intvaluey>\r@p@sbbury
  692.                               \xdef\r@p@sbbury{\number\p@intvaluey}\fi
  693.                            }
  694. %                       lower left
  695.                         \rotate@{\@p@sbbllx}{\@p@sbblly}
  696.                         \minmaxtest
  697. %                       upper left
  698.                         \rotate@{\@p@sbbllx}{\@p@sbbury}
  699.                         \minmaxtest
  700. %                       lower right
  701.                         \rotate@{\@p@sbburx}{\@p@sbblly}
  702.                         \minmaxtest
  703. %                       upper right
  704.                         \rotate@{\@p@sbburx}{\@p@sbbury}
  705.                         \minmaxtest
  706.                         \edef\@p@sbbllx{\r@p@sbbllx}\edef\@p@sbblly{\r@p@sbblly}
  707.                         \edef\@p@sbburx{\r@p@sbburx}\edef\@p@sbbury{\r@p@sbbury}
  708. %\ps@typeout{rotated BB: \r@p@sbbllx, \r@p@sbblly, \r@p@sbburx, \r@p@sbbury}
  709.                 \fi
  710.                 \count203=\@p@sbburx
  711.                 \count204=\@p@sbbury
  712.                 \advance\count203 by -\@p@sbbllx
  713.                 \advance\count204 by -\@p@sbblly
  714.                 \edef\@bbw{\number\count203}
  715.                 \edef\@bbh{\number\count204}
  716.                 %\ps@typeout{ bbh = \@bbh, bbw = \@bbw }
  717. }
  718. %
  719. % \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
  720. %       then leaves the result in @result
  721. %
  722. \def\in@hundreds#1#2#3{\count240=#2 \count241=#3
  723.                      \count100=\count240        % 100 is first digit #2/#3
  724.                      \divide\count100 by \count241
  725.                      \count101=\count100
  726.                      \multiply\count101 by \count241
  727.                      \advance\count240 by -\count101
  728.                      \multiply\count240 by 10
  729.                      \count101=\count240        %101 is second digit of #2/#3
  730.                      \divide\count101 by \count241
  731.                      \count102=\count101
  732.                      \multiply\count102 by \count241
  733.                      \advance\count240 by -\count102
  734.                      \multiply\count240 by 10
  735.                      \count102=\count240        % 102 is the third digit
  736.                      \divide\count102 by \count241
  737.                      \count200=#1\count205=0
  738.                      \count201=\count200
  739.                         \multiply\count201 by \count100
  740.                         \advance\count205 by \count201
  741.                      \count201=\count200
  742.                         \divide\count201 by 10
  743.                         \multiply\count201 by \count101
  744.                         \advance\count205 by \count201
  745.                         %
  746.                      \count201=\count200
  747.                         \divide\count201 by 100
  748.                         \multiply\count201 by \count102
  749.                         \advance\count205 by \count201
  750.                         %
  751.                      \edef\@result{\number\count205}
  752. }
  753. \def\compute@wfromh{
  754.                 % computing : width = height * (bbw / bbh)
  755.                 \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}
  756.                 %\ps@typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
  757.                 \edef\@p@swidth{\@result}
  758.                 %\ps@typeout{w from h: width is \@p@swidth}
  759. }
  760. \def\compute@hfromw{
  761.                 % computing : height = width * (bbh / bbw)
  762.                 \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}
  763.                 %\ps@typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
  764.                 \edef\@p@sheight{\@result}
  765.                 %\ps@typeout{h from w : height is \@p@sheight}
  766. }
  767. \def\compute@handw{
  768.                 \if@height 
  769.                         \if@width
  770.                         \else
  771.                                 \compute@wfromh
  772.                         \fi
  773.                 \else 
  774.                         \if@width
  775.                                 \compute@hfromw
  776.                         \else
  777.                                 \edef\@p@sheight{\@bbh}
  778.                                 \edef\@p@swidth{\@bbw}
  779.                         \fi
  780.                 \fi
  781. }
  782. \def\compute@resv{
  783.                 \if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
  784.                 \if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
  785.                 %\ps@typeout{rheight = \@p@srheight, rwidth = \@p@srwidth}
  786. }
  787. %               
  788. % Compute any missing values
  789. \def\compute@sizes{
  790.         \compute@bb
  791.         \if@scalefirst\if@angle
  792. % at this point the bounding box has been adjsuted correctly for
  793. % rotation.  PSFIG does all of its scaling using \@bbh and \@bbw.  If
  794. % a width= or height= was specified along with \psscalefirst, then the
  795. % width=/height= value needs to be adjusted to match the new (rotated)
  796. % bounding box size (specifed in \@bbw and \@bbh).
  797. %    \ps@bbw       width=
  798. %    -------  =  ---------- 
  799. %    \@bbw       new width=
  800. % so `new width=' = (width= * \@bbw) / \ps@bbw; where \ps@bbw is the
  801. % width of the original (unrotated) bounding box.
  802.         \if@width
  803.            \in@hundreds{\@p@swidth}{\@bbw}{\ps@bbw}
  804.            \edef\@p@swidth{\@result}
  805.         \fi
  806.         \if@height
  807.            \in@hundreds{\@p@sheight}{\@bbh}{\ps@bbh}
  808.            \edef\@p@sheight{\@result}
  809.         \fi
  810.         \fi\fi
  811.         \compute@handw
  812.         \compute@resv}
  813.  
  814. %
  815. % \psfig
  816. % usage : \psfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
  817. %                       rheight=, rwidth=, clip=}
  818. %
  819. % "clip=" is a switch and takes no value, but the `=' must be present.
  820. \def\psfig#1{\vbox {
  821.         % do a zero width hard space so that a single
  822.         % \psfig in a centering enviornment will behave nicely
  823.         %{\setbox0=\hbox{\ }\ \hskip-\wd0}
  824.         %
  825.         \ps@init@parms
  826.         \parse@ps@parms{#1}
  827.         \compute@sizes
  828.         %
  829.         \ifnum\@p@scost<\@psdraft{
  830.                 %
  831.                 \special{ps::[begin]    \@p@swidth \space \@p@sheight \space
  832.                                 \@p@sbbllx \space \@p@sbblly \space
  833.                                 \@p@sbburx \space \@p@sbbury \space
  834.                                 startTexFig \space }
  835.                 \if@angle
  836.                         \special {ps:: \@p@sangle \space rotate \space} 
  837.                 \fi
  838.                 \if@clip{
  839.                         \if@verbose{
  840.                                 \ps@typeout{(clip)}
  841.                         }\fi
  842.                         \special{ps:: doclip \space }
  843.                 }\fi
  844.                 \if@prologfile
  845.                     \special{ps: plotfile \@prologfileval \space } \fi
  846.                 \if@decmpr{
  847.                         \if@verbose{
  848.                                 \ps@typeout{psfig: including \@p@sfile.Z \space }
  849.                         }\fi
  850.                         \special{ps: plotfile "`zcat \@p@sfile.Z" \space }
  851.                 }\else{
  852.                         \if@verbose{
  853.                                 \ps@typeout{psfig: including \@p@sfile \space }
  854.                         }\fi
  855.                         \special{ps: plotfile \@p@sfile \space }
  856.                 }\fi
  857.                 \if@postlogfile
  858.                     \special{ps: plotfile \@postlogfileval \space } \fi
  859.                 \special{ps::[end] endTexFig \space }
  860.                 % Create the vbox to reserve the space for the figure.
  861.                 \vbox to \@p@srheight sp{
  862.                 % 1/92 TJD Changed from "true sp" to "sp" for magnification.
  863.                         \hbox to \@p@srwidth sp{
  864.                                 \hss
  865.                         }
  866.                 \vss
  867.                 }
  868.         }\else{
  869.                 % draft figure, just reserve the space and print the
  870.                 % path name.
  871.                 \if@draftbox{           
  872.                         % Verbose draft: print file name in box
  873.                         \hbox{\frame{\vbox to \@p@srheight sp{
  874.                         \vss
  875.                         \hbox to \@p@srwidth sp{ \hss \@p@sfile \hss }
  876.                         \vss
  877.                         }}}
  878.                 }\else{
  879.                         % Non-verbose draft
  880.                         \vbox to \@p@srheight sp{
  881.                         \vss
  882.                         \hbox to \@p@srwidth sp{\hss}
  883.                         \vss
  884.                         }
  885.                 }\fi    
  886.  
  887.  
  888.  
  889.         }\fi
  890. }}
  891. \psfigRestoreAt
  892. \let\@=\LaTeXAtSign
  893.  
  894.  
  895.