%^^A last update: Tue  02-04-1997
% \def\fileversion{v1.0c} \def\filedate{1997/02/04}
% 
% \title{Package \expandafter\ifx\csname circfonts\endcsname\relax\else
%   \circuit2 \CIRCLogo \endcircuit\fi\\[5mm]
%        \fileversion\ last revised \filedate}
% 
% \author{Sebastian Tannert\\Andreas Tille}%
% \parskip 1mm\parindent0pt
% 
% \font\manual=logo10
% \def\MF{{\manual METAFONT}\xspace}
% \def\CIRC{{\sf CIRC}\xspace}
% \ifx\LaTeXe\undefined\def\LaTeXe{\LaTeX 2$\epsilon$}\fi
% \def\CB#1{{\tt\char'134 #1}\index{#1@\string\texttt{\string\char'134 #1}}}
% \def\warp#1{{\tt\char'134 #1}}
% \def\Blank{{\tt\char32}}
% \def\einruck{\hspace*{1cm}}
% \def\example#1{\par\medskip\einruck#1\par\medskip}
% \def\kohm{$\,$k$\Omega$}
% \newcommand{\Descriptionlabel}[1]{\mbox{\textsf{#1}}\hfil}
% \newenvironment{Description}[1]%
%  {\begin{list}{}%
%         {\renewcommand{\makelabel}{\Descriptionlabel}%
%          \setlength{\parsep}{0pt}%
%          \setlength{\itemsep}{0pt}%
%          \setlength{\itemindent}{0pt}%
%          \setlength{\topsep}{0pt}%
%          \setbox0=\hbox{\Descriptionlabel{#1}}%
%          \setlength{\labelwidth}{\wd0}%
%          \dimen0=\labelwidth\advance\dimen0 by \labelsep%
%          \setlength{\leftmargin}{\dimen0}}}%
%  {\end{list}}
%
% \batchmode
% \iffalse First we have to check the fonts. \fi
% \font\checkcircfonts=csyrest
% \dimen0=\fontdimen6\checkcircfonts
% \ifdim\dimen0>0pt \def\circfonts{exist}\fi
% \errorstopmode
% \maketitle
%
% \begin{abstract}
% The package \CIRC is a tool for typesetting circuit diagrams.
% It defines several electrical symbols such as resistors, capacitors,
% transistors etc. These symbols can be connected with wires in a
% very easy way.
%
% To use \CIRC you only need \MF and \LaTeX{}. You do not need
% PostScript or any drawing tool. You can expand \CIRC easily with
% your own symbols, written in \MF.
% \end{abstract}
%
% \vskip 15mm
% \expandafter\ifx\csname circfonts\endcsname\relax\else
% \begin{circuit}{0}
%\.1 \- 1 r \nl\cc\R1 {R} h
%\frompin .1 \- 3 l \- 2 d \<\nl\R9 {2R} v \- 10 d \.7
%\frompin .7 \- 3 l \cc\U0 {} u
%\frompin .1 \- 2 d \<\nl\cc\R2 {2\,R} v \nl\SW1 {} s U
%\frompin SW1c \vtopin U0+ \.8
%\frompin SW1o \vtopin U0- \.9
% \iffalse
%\frompin R1r \- 1 r
%\.2 \- 1 r \nl\cc\R3 {R} h
%\frompin .2 \- 2 d \<\nl\cc\R4 {2\,R} v \nl\SW2 {} s u
%\frompin SW2c \vtopin U0- \.10
%\frompin SW2o \vtopin U0+ \.11
% \fi
%\frompin R1r \- 1 r
%\.3 \- 1 r \nl\cc\R5 {R} h
%\frompin .3 \- 2 d \<\nl\cc\R6 {2\,R} v \nl\SW3 {} s u
%\frompin SW3c \vtopin U0- \.12
%\frompin SW3o \vtopin U0+ \.13
%
%\frompin R5r \- 1 r
%\.4 \- 2 r \nl\cc\R7 {R$_1$= 2R} h
%\frompin .4 \- 2 d \<\nl\cc\R8 {2\,R} v \nl\SW4 {} s U
%\frompin SW4c \vtopin U0+ \htopin U0+
%\frompin SW4o \vtopin U0- \.15
%
%\frompin R7r \- 1 r \nl\whatI1 {I} r
%\- 1 r \.5 \- 1 r \nl\OV1 {} - {} {} {}
%\frompin .5 \- 3 u \centerto OV1 \nl\cc\R10 {R$_2$} h
%\frompin R10l \htopin .5
%\atpin OV1O \.6 \vtopin R10r \htopin R10r
%\frompin .6 \- 1 r \connection1 {$U_a$} r
%\frompin OV1+ \- 1 l \- 3 d \<\nl\cc\R11 {R$_3$} v
%\frompin R11d \vtopin .7 \.8 \GND1 \frompin .7 \htopin .8
%\frompin .7 \- 3 l \cc\U0 {} u
%\end{circuit}\fi
% \clearpage
% \tableofcontents
% \enlargethispage{.5cm}
% \section{Introduction}
%
% In several sciences circuit diagrams are necessary in publications.
% Perhaps there are some PostScript tools for typesetting them or
% a drawing program has to be used.
% With \CIRC it is now possible to typeset circuit diagrams using
% \TeX commands. The commands
% describe the logical structure of the wiring scheme and \TeX{}
% builds the connections according to this structure.
%
% \CIRC defines several electrical symbols such as resistors, capacitors,
% transistors etc. These symbols can be connected with wires in a
% very easy way.
%
% To use \CIRC you only need \MF and \LaTeX{}. You do not need
% PostScript or any drawing tool. You can expand \CIRC with
% your own symbols, written in \MF.
%
% \CIRC has been implemented as a turtle system. That means, there is
% a current position from where the symbols and wires are drawn.
% It is possible to choose the drawing direction and drawing position.
%
% \CIRC consists of commands in order to
% \begin{Description}{position}
%  \item[draw] symbols and wires into the scheme,
%  \item[justify] symbols within the scheme,
%  \item[link] symbols with wires,
%  \item[position] symbols absolutely or relatively.
% \end{Description}
%
% \section{Installation}
%
% Run |circ.ins| through \LaTeX. You will get a couple of
% |*.mf| files. Use \MF to create |*.pk| fonts from all these files.
% These steps depend on your installation.
% For example, type:
% \begin{verbatim}
%    mf \mode=localfont; input csywidko.mf
%    gftopk csywidko.300
% \end{verbatim}
% Do this with all the |*.mf| sources. Copy the resulting |*.tfm|
% and |*.pk| files into appropriate directories.
%
% If you use EM-\TeX{} from Eberhard Mattes you can use |circ.mfj|
% to do this job by |mfjob.exe|.
%
% Copy the |*.sty|, |*.def| files, obtained from |circ.ins| into appropriate
% directories in your |TEXINPUT| path.
%
% Read the documentation carefully.
%
% Enjoy \CIRC.
%
%
% \section{System requirements}
%
% \CIRC requires \LaTeXe.
% With some changes it should be possible to use \CIRC with plain-\TeX.
% In this case NFSS is necessary.
% 
%
% \section{Usage}
%
% \subsection{Preambel}
%
% \CIRC is divided into several parts. To use a part put the suitable
% option in the |\usepackage| command. All parts are included
% in the following example:
% \example{\warp{usepackage[basic,box,gate,ic,optics]}\{|circ|\}}
%
% The parts contain:
% \begin{Description}{optics\,:}
% \item[basic\,:]  a lot of symbols such as resistors, capacitors, switches,
%                  diodes, transistors, etc.,
% \item[box\,:]    blackbox, oscilloscope, generator and amplifier,
% \item[gate\,:]   several logical circuits,
% \item[ic\,:]     integrated circuits (flip flops, etc.) and
% \item[optics\,:] the optical stuff with lenses, mirrors, etc.
%                  (see section \ref{optic}).
% \end{Description}
% A complete list of available symbols is given in the appendix.
%
% \subsection{Starting a circuit diagram}
%
% It is recommended to draw a sketch with pen and paper before using
% \CIRC.
%
% Every circuit diagram is enclosed in the
% |circuit| environment
% \example{\CB{begin\{circuit\}}{\em size}}
% where {\em size} is an integer
% between 0 and 4 giving the size of symbols and describing text. A size
% of 4 is useful for overhead foils.
%
% All \CIRC macros and the necessary parameters are separated by
% spaces (\Blank). For a clearly arranged \CIRC diagram it is
% advisable to put every command in a separate line (a linebreak
% is interpreted as a blank as it is used in \TeX).
%
% \subsection{Drawing symbols}
%
% The table in the appendix contains a complete list of all 
% \CIRC symbols available and corresponding drawing commands.
% On the left hand of the table are the symbols and on the right hand the
% \TeX commands which put the symbols into the circuit diagram.
% The syntax of drawing commands is:
% \example{\warp{}{\sf symbolname}{\em number\Blank
%  inscription\Blank{\tt[}specification\_parameter{\tt]}\Blank direction}}
% or for more complex symbols:
% \example{\warp{}{\sf symbolname}{\em number\Blank {\tt[}further\_parameters\tt ]}}
% Note that you can leave out the blank between the symbol-command
% and the following {\em number} parameter. This parameter has to
% be unique in one drawing and is necessary for correct referring
% (see |\atpin| in section \ref{poscmd}).
%
% Due to the fact, that there are different symbols for different
% drawing directions the right {\em direction} parameter is important.
% The table in the appendix contains valid {\em direction} parameters
% for every drawing command. This may be |h| (horizontal) or |v|
% (vertical) for symbols with the symmetry two; |l| (left), |r| (right),
% |u| (up) and |d| (down) for symbols with the symmetry four or
% for symbols with the symmetry eight |l|, |L|, |r|, |R|, |u|, |U|,
% |d| or |D|. The latter may need further {\em specification} parameter
% in front of the {\em direction} parameter.
% This {\em specification} parameter marks the pin
% that should be on the current drawing position (see variable resistor and
% several transistors).
%
% In the appendix {\tt X} was used for the {\em inscription} and the
% necessary {\em number} was set to {\tt 1}. Note the position
% at the symbol where the inscription is set.
% The inscription can be suppressed by the \CB{nv} command in front
% of the symbol-command.
%
% By default every \CIRC symbol is marked by a label.
% This label consists of an abbreviation of the symbol indexed by
% the {\em number}. To suppress
% this labeling use \CB{nl} in front of the symbol-command.
%
% Another command affecting the inscription of a symbol is
% \CB{cc}. It is also used in front of a symbol-command and causes the
% change of label-position and inscription-position. By default the
% inscription is typeset left or over the symbol while the labeling
% is done right or under the symbol depending on the vertical or
% horizontal orientation of the symbol.
%
% Some symbols need {\em further\_parameter}s. The usage
% is selfdocumenting in the appendix table.
%
% Junctions can be made by the \CB{.} command
% (\CB{junction})\footnote{Commands within
% parenthesis are synonyms for the last introduced command.}.
% The syntax is:
% \example{\warp{.}{\em number}}
% Every junction needs a {\em number} argument for further referencing.
%
% \subsection{Referencing symbols and pins}
%
% Some commands use reference parameters
% to mark symbols or connections of symbols drawn before.
%
% The {\em symbol\_reference} parameters consist of two parts:
% \example{{\sf symbolname}$\;${\em number}}
%
% The {\em pin\_reference} parameters consist of three parts:
% \example{{\sf symbolname}$\;${\em number}$\;${\sf pinname}\footnote{See appendix, pinnames are drawn by the pins.}}
% These three parts form the {\em reference} parameter.
%
% {\em Note that there is no blank between the parts!}
%
% For example, to refer to the \underline{l}eft connection of the
% resistor with the {\em number} 1 the {\em pin\_reference} parameter
% would be
% \example{{\tt R1l}}
% or to refer to the whole symbol the {\em symbol\_reference} is
% \example{{\tt R1}\quad.}
%
% At least it is possible to set markers which work like pin references.
% \example{\CB{P}{\em number}}
% sets a marker which can be referred to by |P|{\em number}.
%
% \subsection{Connecting symbols}
%
% Simple connections between the symbols can be made with the
% \CB{-} command, which is an abbreviation of the \CB{wire}
% command (see appendix). The syntax is
% \example{\warp{-}\Blank{\em length}\Blank{\em direction}.}
% The parameter {\em length} is an integer giving the number of
% lengthsteps. In \CIRC wires are build as a queue of characters
% 2.5\,mm each. Thus the length of wire is measured in multiples
% of this length.
%
% The parameter {\em direction} determines the direction. Valid
% values are |l| for left, |r| for right, |u| for up and |d| for
% down. For instance, a wire is drawn to the left with a length of
% 1\,cm (4 units) by typing
% \example{\warp{-\Blank 4\Blank l}}
%
% There are some other line types to connect symbols. The command
% \example{\CB{dashed}\Blank{\em length\Blank direction}}
% draws a dashed line. It is written as the \warp{-} command.
% With
% \example{\CB{bundle}\Blank{\em text\Blank length\Blank direction} \\
%          \einruck\CB{wwire}\Blank{\em text\Blank length\Blank direction}}
% a bundle of wire could be drawn or a pair of wire, respectively.
% You can use \CB{=} as an abbreviation of |\wwire|.
% The {\em text} may contain any comments.
%
% To connect the drawing position horizontally or vertically with
% a certain pin of a symbol by using a reference, the useful
% commands \CB{htopin} and \CB{vtopin} exist.
% The syntax is:
% \example{\warp{htopin}\Blank{\em pin\_reference} \\
%          \einruck\warp{vtopin}\Blank{\em pin\_reference}}
% Provided that the resistor |R1| defined before by a |\R| command,
% the command
% \example{\warp{vtopin\Blank R1l}}
% draws a vertical wire up to this height, where the resistor numbered
% with |1| (|R1|) is situated. |\htopin| does the same but horizontally.
%
% The connection will be done by default with the \CB{wire} command.
% To change the type of the connection use the \CB{by} command.
% The syntax is:
% \example{\warp{by\{}{\em command\/}|\}|}
% where {\em command} can be one of the following: \CB{wire} (\CB{-}), \CB{dashed},
% \mbox{\CB{bundle}\Blank{\em text}}, \mbox{\CB{wwire}\Blank{\em text}}
% or \CB{oa} (which is declared in the optics part, see section \ref{optic}).
%
% For example, the command
% \example{\warp{by\{}\warp{dashed\}}}
% changes the drawing style from \warp{[hv]topin} to a dashed lines.
% Do not forget to switch back to wires using
% \example{\warp{by\{}\warp{wire\}}}
% to end the dashed lines.
%
% Note that it is usually necessary to combine the |htopin|- and
% |vtopin| commands, because these commands draw {\em only} horizontally
% or vertically to the x- or the y-coordinates
% of the given pin.
%
% \subsection{\label{poscmd}Positioning commands}
% Positioning commands are used to change the current
% drawing position.
%
% The direct positioning command \CB{at} (\CB{from}) sets the drawing position
% to an absolute coordinate.
% \example{\warp{at\{{\em x}\}\Blank\{{\em y}\}\Blank}}
% sets the drawing position to the point ({\em x},{\em y}) in the coordinate
% system, where {\em x} and {\em y} are integers counting the number of
% arbitrary units (2.5\,mm). \CIRC starts drawing at $(0,0)$.
%
% It is recommended to avoid the absolute positioning of symbols, because
% it tends to destroy the logical structure of the circuit diagram.
%
% The drawing position can be changed in relation to the current position
% with the indirect positioning command \CB{moverel} (\CB{shift}).
% \example{\warp{moverel\{{\em x}\}\Blank\{{\em y}\}\Blank}}
% moves the drawing position {\em x} units to the right
% and {\em y} units upwards.
%
% The command \CB{atpin} (\CB{frompin}) sets the drawing
% position to a reference pin.
% \example{\warp{atpin}\Blank{\em pin\_reference}}
% allows further drawing starting from the reference pin. For example,
% \example{\warp{atpin C2r}}
% sets the drawing position to the right pin of the capacitor numbered 2.
%
% \subsection{Orientation commands}
% The command \CB{<} changes the drawing direction of the following
% circuit symbol. It has to be written  in front of a drawing command.
% By default the drawing direction is upwards or
% to the right. If it is necessary to draw downwards or to the left
% the direction has to be switched. This change works for
% one symbol only.
%
% \subsection{Justify commands}
%
% The command \CB{hcenterto} forces horizontal centering
% according to a symbol referred to. The command \CB{vcenterto} does the
% same but vertically.
% The command \CB{centerto} centers the following symbol according to the
% reference symbol
% horizontally or vertically depending on the drawing direction of
% the symbol beeing drawn.
%
% The syntax is:
% \example{\warp{hcenterto}\Blank{\em symbol\_reference} \\
%          \einruck\warp{vcenterto}\Blank{\em symbol\_reference} \\
%          \einruck\warp{centerto}\Blank{\em symbol\_reference}}
% For example,
% \example{\warp{hcenterto L4}}
% would force horizontal centering according to the coil numbered 4.
% 
% \subsection{Text commands}
%
% The command
% \example{\CB{text}|\{|{\em text}|\}|}
% puts {\em text} at the current drawing position.
% A synonym for \warp{text} is
% \example{\CB{put}|\{|{\em text}|\}|}
% It can be used in the same way as the \warp{put} command of the
% \LaTeX |picture| environment, but the coordinates have to be omitted
% (because they are given by the current drawing position).
%
% To comment something the commands
% \example{\CB{Utext}\Blank{\em text\Blank{\tt from}\Blank pin\_reference1\Blank{\tt to}\Blank pin\_reference2} \\
%  \einruck\CB{centertext}\Blank{\em text\Blank{\tt from}\Blank pin\_reference1\Blank{\tt to}\Blank pin\_reference2}}
% can be used. \warp{centertext} prints {\em text} centered between
% {\em pin\_reference1} and {\em pin\_reference2}.
% \warp{Utext} additionally draws an arrow from
% {\em pin\_reference1} to {\em pin\_reference2}.
% Note that the reference pins have to have the same x- or y-coordinate.
%
% To write overlapping information like the \TeX\ commands
% \warp{rlap} and \warp{llap} the following commands are used:
% \example{\CB{blap}|\{|{\em text}|\}| \\
%          \einruck\CB{tlap}|\{|{\em text}|\}|}
% They put {\em text} which overlap to the bottom or the top, respectively.
%
% \expandafter\ifx\csname circfonts\endcsname\relax
% \LARGE Please generate the fonts now. Then you will get a
% complete documentation.\stop\fi
%
% \subsection{Example}
%
% A simple example is the diagram showing a circuit which is used for measuring
% the amplification of current by a transistor.
% \vskip 4mm
% \begin{circuit}0
% \npn1 {?} B l
% \frompin npn1C
% \- 1 u
% \nl\A1 {$I_C$} v
% \atpin npn1B
% \- 1 l
% \<\R1 {510\kohm} h
% \- 1 l
% \centerto A1
% \nl\A2 {$I_B$} v
% \frompin A2d
% \vtopin R1l
% \frompin A1u
% \- 1 u \.1
% \frompin A2u
% \vtopin .1
% \htopin .1
% \- 1 u
% \cc\connection1 {$U_b$} u
% \frompin npn1E
% \- 1 d
% \GND1
% \end{circuit}
% \vskip 4mm
% 
% How to cope with such sketches?
%
% First of all, it is necessary to decide, which symbol should be the
% first one.
% The transistor seems to be a good choice to begin with in this
% special case. The command \CB{npn} produces a npn-transistor
% (see appendix); so the first line is
% \example{\warp{npn1 {?} B l}}
% which names the transistor |npn1| for further reference.
% Instead of |{?}| any text describing the specific transistor
% may be written. The third parameter |B| means, that the
% \underline{b}ase of the transistor should be on the current
% drawing position. Further more |C| for \underline{c}ollector
% or |E| for the \underline{e}mitter contact would be possible.
% The last parameter gives the direction, in this case the
% base contact points to the \underline{l}eft (|l|).
%
% Use
% \example{\warp{frompin npn1C}}
% to continue drawing from the collector, and type
% \example{\warp{- 1 u}}
% to draw the needed wire \underline{u}pwards
% to connect the amperemeter to measure $I_C$ which is created by the command
% \example{\warp{nl}\warp{A1 \{\$I\_C\$\} v}}\qquad .
%
% The command \CB{nl} in front of the amperemeter avoids the default
% inscription of "$I_1$" because this would not make any sense in this
% case. Instead, the labeling is $I_C$. The last parameter {\tt v}
% marks the direction (\underline{v}ertical).
%
% To draw the resistor connected with the base of the transistor
% the proceeding is the same: use
%
% |\atpin npn1B |
% to set drawing position (different from the current position),
%
% |\- 1 l |
% to draw a piece of wire to the left and
%
% |\<\R1 {510\kohm} h |
% for the resistor itself.
%
% Note that it is necessary to switch the drawing
% direction (\CB{<}) of the resistor
% from the right (default) to the left.
% Otherwise the resistor would have the same position as the transistor.
%
% A further horizontal piece of wire connects the resistor with the
% second amperemeter: |\- 1 l |.
%
% The second amperemeter, measuring the current of the base ($I_B$),
% would look nice at if drawn the same height as the first one,
% measuring ($I_C$).
% Measuring the length of wire needed to match the same height would be
% difficult and a change of the diagram would cause further changes in
% order to maintain the desired position.
% Therefore it is advisable to use
% \example{\CB{centerto} {\tt A1}\quad \warp{nl}\warp{A2 \{\$I\_B\$\} v}}
% which leeds to the intended centering automatically. Because of the
% \underline{v}ertical orientation of {\tt A2}, the centering is the same as
% in the vertical direction.
%
% A vertical connection is needed to connect the amperemeter
% with {$R_1$}. This may be done by
% \example{\warp{frompin A2d} \\
%          \einruck\warp{vtopin R1l}}
% which draw a wire down to the horizontal wire, starting at
% |A2d|. Instead of the second line |\vtopin npn1B| would do the same job
% because the horizontal position is irrelevant for \CB{vtopin}.
%
% To connect the two amperemeters the drawing position is set to |A1u|,
% from where a wire is drawn upwards and a junction point is marked
% at that point by using
% \example{\warp{frompin A1u} \\
%          \einruck\warp{- 1 u} \\
%          \einruck\warp{.1}}
% The commands for connecting the second amperemeter are:
% \example{\warp{frompin A2u} \\
%          \einruck\warp{vtopin .1} \\
%          \einruck\warp{htopin .1}}
% The combination of \CB{htopin} and \CB{vtopin} is very useful
% to connect two points with an edge of wire.
% The driving voltage is typeset by
% \example{\warp{- 1 u} \\
%          \einruck\warp{cc}\warp{connection1 \{\$U\_b\$\} u}}
% because it looks better to put the inscription of the voltage on the
% right. That is why the prefix \CB{cc} is used in front of
% the \warp{connection} command.
%
% Finally the emitter contact leads to the ground:
% \example{\warp{frompin npn1E} \\
%          \einruck\warp{- 1 d} \\
%          \einruck\warp{GND1}}
% 
% The whole example once more in an overview:
% \begin{verbatim}
% \begin{circuit}0
% \npn1 {?} B l              % transistor
% \frompin npn1C             % draw from collector
% \- 1 u                     % some wire
% \nl\A1 {$I_C$} v           % amperemeter for current of collector
% \atpin npn1B               % continue drawing from base
% \- 1 l                     % some wire
% \<\R1 {510\kohm} h         % resistor
% \- 1 l                     % some wire to the edge
% \centerto A1               % draw centered to amperemeter 1
% \nl\A2 {$I_B$} v           % amperemeter 2
% \frompin A2d               % link amperemeter 2 with resistor
% \vtopin R1l
% \frompin A1u
% \- 1 u
% \.1                        % junction
% \frompin A2u               % wire to amperemeter 2
% \vtopin .1
% \htopin .1
% \- 1 u
% \cc\connection1 {$U_b$} u  % driving voltage
% \frompin npn1E
% \- 1 d
% \GND1                      % ground
% \end{circuit}
% \end{verbatim}
%
% \section{\label{optic}Optics}
%
% If the |optics| option is given in the |\usepackage| command, the
% creation of simple optical diagrams is possible.
%
% The optical axis can be drawn with the \CB{oa} command, which
% creates a dashed line.
% The optical symbols
% which are available are listed at the end of the appendix.
% 
% Here is an example for using |optics|. With the knowledge
% of drawing circuits the following code will speak for itself.
% \vskip 4mm
% 
%   \begin{circuit}{0}
%      \nl\Laser1 {} h
%      \oa 2 r
%      \Polar1 {} h
%      \oa 2 r
%      \nl\OM1 P1 {} {} {} {} h
%      \atpin OM1P3
%      \oa 4 r
%      \cc\BLens1 {} h
%      \oa 2 r
%      \nl\Pinhole1 {} h
%      \oa 7 r
%      \cc\SLens2 {} h
%      \oa 1 r
%      \Polar2 {} h
%      \oa 3 r
%      \nl\BSplit1 {} + d
%      \atpin BSplit1+
%      \oa 2 r
%      \nl\Cam1 {camera} l
%      \atpin BLens1: \shift 0 2 \P3
%      \atpin Pinhole1: \shift 0 2 \P4
%      \atpin SLens2: \shift 0 2 \P5
%      \Dtext{\small $f_1$} from P3 to P4
%      \Dtext{\small $f_2$} from P4 to P5
%      \atpin BSplit1.
%      \oa 5 d
%      \Mirror1 {} * R
%      \oa 2 r
%      \nl\ScrL1 {screen} h
%   \end{circuit}
% 
% Here is the code:
% 
% \begin{verbatim}
%    \begin{circuit}{0}
%       \nl\Laser1 {} h                    % laser
%       \oa 2 r                            % optical axis
%       \Polar1 {} h                       % polarizer
%       \oa 2 r
%       \nl\OM1 P1 {} {} {} {} h           % optical modulator
%       \atpin OM1P3
%       \oa 4 r
%       \cc\BLens1 {} h                    % 1. lens
%       \oa 2 r
%       \nl\Pinhole1 {} h                  % pinhole
%       \oa 7 r
%       \cc\SLens2 {} h                    % 2. lens
%       \oa 1 r     
%       \Polar2 {} h                       % analyzer
%       \oa 3 r
%       \oa 3 r
%       \nl\BSplit1 {} + d                 % beam splitter
%       \atpin BSplit1+                    % continue drawing right
%       \oa 2 r
%       \nl\Cam1 {camera} l                % camera
%       \atpin BLens1: \shift 0 2 \P3      % mark middle of 1. lens
%       \atpin Pinhole1: \shift 0 2 \P4    % mark middle of pinhole
%       \atpin SLens2: \shift 0 2 \P5      % mark middle of 2. lens
%       \Dtext{\small $f_1$} from P3 to P4 % f_1
%       \Dtext{\small $f_2$} from P4 to P5 % f_2
%       \atpin BSplit1.                    % second part of beam down
%       \oa 5 d
%       \Mirror1 {} * R                    % mirror
%       \oa 2 r
%       \nl\ScrL1 {screen} h               % white screen
%    \end{circuit}
% \end{verbatim}
%
%
% \section{Some hints for \CIRC programmers}
%
% Here are some hints to add further symbols to \CIRC.
%
% Before creating any new symbol consult very carefully the file |csym.mf|.
% It contains a lot of very useful definitions to simplify writing new symbols.
% Examples for the use of these definitions are given in the files
% |csywidko.mf| and |optic.mf|.
% When possible it is stronly recommended to use the \MF commands
% \begin{Description}{|fourfourchars|}
% \item[|twochars|] for symbols with the symmetry two,
% \item[|fourchars|] for symmetry four and
% \item[|fourfourchars|] for symmetry eight,
% \end{Description}
% because the definition of the corresponding \TeX command
% will need only one line! If there are any problems with \MF{}
% do not hesitate to contact the authors.
%
% A new option file with the extension |def|,
% for instance |newcirc.def|, has to be created to include
% the written symbols. To include the new definitions add
% |newcirc| to the options in the \warp{usepackage} command:
% \example{\warp{usepackage[basic,newcirc]\{circ\}}\qquad .}
%
% The \CIRC-command \CB{freecirc} has to be used to start the
% definitions of new commands in the file |newcirc.def|.
% This ensures, that the asterix (`*') becomes active, because
% all internal \CIRC commands contain the asterix. It is comparable to
% \LaTeX 's \warp{makeatletter}. The \CIRC-command \CB{protectcirc}
% has to be used at the end of the file |newcirc.def|
% in order to restore the former
% behaviour (comparable to \warp{makeatother}).
%
% The \CB{cdef*} commands are strongly recommended to declare commands
% with the new symbols, because only one line is needed for the definition.
% The files |basic.def| or |optics.def| contain examples for \warp{cdef} and
% related commands, which are defined in |circ.sty|.
%
% To ensure that the new symbols are inserted in the right
% magnification the command \CB{extracircinit} may be used.
% It can be used in the same way as \warp{opticfontinit} is used
% in |optics.def|. Both are defined in |circ.sty| as \warp{relax}
% and are called when a new diagram is initialized. If it is necessary
% to do any operations before starting a circuit diagram, then
% it is possible to redefine \warp{extracircinit} to do the job.
%
% \section{Contacting the authors}
% Any bug reports, remarks, proposals for new options and symbols,
% any improvements to both the code or the documentation
% as well as some nice postcards are welcome.
%
% \medskip
% \begin{tabular}{@{}p{.5\hsize}@{}p{.5\hsize}@{}}
% Sebastian Tannert              & Andreas Tille                 \\
% Lafontainestra\ss e 21         & Max-Lademann-Stra\ss e 19   \\
% D-06114 Halle / Saale          & D-06128 Halle / Saale         \\
%                                &                               \\
% psiay@mlucom.urz.uni-halle.de  & e2od5@mlucom.urz.uni-halle.de
% \end{tabular}
% \iffalse Some changes to the layout for the appendix. \fi
%\advance\textheight\topmargin
%\advance\textheight60pt
%\advance\textheight\headsep
%\advance\textheight\headheight
%\newpage
%\topmargin-30pt
%\headsep0pt
%\headheight0pt
%\oddsidemargin10pt
%\parindent 0pt
%\lineskip4mm

%^^A last update: Tue  02-04-1997
% \section{\appendixname}
% \MakePercentComment\input{circsyms}\MakePercentIgnore
% \advance\hsize-4cm
% \oddsidemargin35pt
% \newpage
% \PrintIndex
% \iffalse DON'T process driver definitions!
%<*driver>
\documentclass{ltxdoc}
\usepackage[basic,box,gate,ic,optics]{circ}
\usepackage{t1enc}
\usepackage{xspace}
\IndexPrologue{\section{Index}}
\makeindex
\begin{document}
\DocInput{circ.dtx}
\end{document}
%</driver>
% \fi
%^^A last update: Tue  02-04-1997
% \newpage
% {\Large\bf The code of \CIRC.}\\\vskip 1mm
% First all options were defined.
%    \begin{macrocode}
%<*code>
\ProvidesPackage{circ}
\DeclareOption{basic}{\input{basic.def}}
\DeclareOption{box}{\input{box.def}}
\DeclareOption{gate}{\input{gate.def}}
\DeclareOption{ic}{\input{ic.def}}
\DeclareOption{optics}{\input{optics.def}}
\DeclareOption*{\InputIfFileExists{\CurrentOption.def}{\wlog{Loading
  \CurrentOption.def}}{\errhelp{^^J^^JCheck spelling or think about
  the location of file.^^JI tried to load macros for
  CIRC.}\errmessage{CIRC Error : File \CurrentOption.def not found^^J}}}
%    \end{macrocode}
%
% Sorry, but it's better to stop here.
% The sourcecode is formatted worst. \endinput
%
% F"ur die interne Namensgebung m"ussen einige Zeichen
% in ihrem Kategoriekode als Buchstaben (11) eingetragen werden.
% Der jetzige Kode wird in Definitionen abgelegt.
% Das betrifft die Zeichen \verb+* [ ] @+.
%
%    \begin{macrocode*}
\def\freecirc{\chardef\ccat\the\catcode`\@\catcode`\@=11
              \chardef\@cclb\the\catcode`\[
              \chardef\@ccrb\the\catcode`\]
              \chardef\@ccst\the\catcode`\*
              \catcode`\[=11\catcode`\]=11\catcode`\*=11 }
\def\protectcirc{\catcode`\[=\@cclb\catcode`\]=\@ccrb\catcode`\*=\@ccst
                 \catcode`\@=\ccat\relax}
\freecirc
%    \end{macrocode*}
%^^A last update: Tue  02-04-1997
% Zu Testzwecken kann "uber \verb+\showpointstrue+ die
% Anzeige aller definierter Anschlu"spunkte eingestellt werden.
%    \begin{macrocode}
\newif\ifshowpoints
\showpointsfalse
%    \end{macrocode}
%
% Alle mit * gekennzeichneten Schalter werden nach jeder Zeichenoperation
% auf den entsprechenden Standardwert gesetzt.
%
% Die Darstellung der Beschriftung mit Schaltzeichentyp und Nummer
% wird "uber \verb+\iflab+ getsteuert. *
%    \begin{macrocode}
\newif\iflab*
\lab*true
%    \end{macrocode}
%
% Schaltzeichenwerte k"onnen auch ausgeblendet werden. *
%    \begin{macrocode}
\newif\ifval*
\val*true
%    \end{macrocode}
%
% Die  Zeichenrichtung wird durch \verb+\ifld+ bestimmt.
%    \begin{macrocode}
\newif\ifld*
\ld*false
%    \end{macrocode}
%
%    \begin{macrocode}
\newif\ifcc*
\cc*false
%    \end{macrocode}
%
%
%    \begin{macrocode}
\newif\ifpin
\pintrue
%    \end{macrocode}
%
%    \begin{macrocode}
\newif\ifxoutofgrid
\newif\ifyoutofgrid
\xoutofgridfalse
\youtofgridfalse
%    \end{macrocode}
%
%    \begin{macrocode}
\newif\ifcen*
\cen*false
%    \end{macrocode}
%
%    \begin{macrocode}
\newif\ifhvcen*
\hvcen*false
%    \end{macrocode}
\newif\ifcheck*
%
% F"ur die Ermittlung der kleinsten Umschlie"senden Box werden die
% beiden Variablen \verb+\X*max+ und \verb+\X*min+ bei jeder
% Zeichenoperation aktualisiert. Sie enthalten die minimale und die
% maximale Ausdehnung der Zeichenfl"ache in horizontaler Richtung.
%    \begin{macrocode}
\newdimen\X*max
\newdimen\X*min
%    \end{macrocode}
%
%    \begin{macrocode}
\newdimen\*X*
\newdimen\*Y*
%    \end{macrocode}
%
%    \begin{macrocode}
\newdimen\**X
\newdimen\**Y
%    \end{macrocode}
%
%    \begin{macrocode}
\newdimen\***X
\newdimen\***Y
%    \end{macrocode}
%
%  In der Box \verb+\*bbox+ wird f"ur eine Zeichenoperation
%  das entsprechende horizontale Material gesammelt.
%  Diese Box wird dann durch \verb+\put*bbox+ entsprechend
%  der aktuellen Zeichenposition in die Box der entstehenden
%  Zeichnung "ubernommen.
%    \begin{macrocode}
\newbox\*bbox
%    \end{macrocode}
%
%    \begin{macrocode}
\newbox\box*
\newdimen\ic*
\newdimen\ht*
\newdimen\wd*
\newdimen\dp*
%
\newcount\cc*
\newdimen\*spc
\newtoks\ldd*   %linke untere Beschriftung
\newtoks\rud*   %rechte obere Beschriftung
%
\newtoks\llpos*
\newtoks\ldpos*
\newtoks\rlpos*
\newtoks\rdpos*
\newtoks\ulpos*
\newtoks\udpos*
\newtoks\dlpos*
\newtoks\ddpos*
%
\newcount\cnta*
\newcount\cntb*
%
\newtoks\name*  %Bauelementname
\newtoks\ld*pin   %Bezeichnung linker Anschlu"s
\newtoks\ru*pin   % ...
\newtoks\m*pin    % ...
%    \end{macrocode}
%
%
%    \begin{macrocode}
\newdimen\outerspace
%    \end{macrocode}
%
%    \begin{macrocode}
\newtoks\*Ilist
\newtoks\*Olist
%    \end{macrocode}

%    \begin{macrocode}
\newdimen\pin*spc
\newdimen\pin*ind
\newdimen\io*ind
\newdimen\mid*ind
\newdimen\pinnum*spc
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\getc*#1 {\advance\cc* by #1%
  \ifcc*
     \toks0\ldd*\ldd*\rud*\rud*\toks0
     \ifval*
       \iflab*\val*true\else\val*false\fi
       \lab*true
     \else
       \iflab*\val*true\else\val*false\fi
      \lab*false
     \fi
  \fi
  \global\setbox\box*=\hbox{\char\cc*\/\global\ic*=\lastkern\unkern}%
  \global\ht*\ht\box*\global\wd*\wd\box*\global\dp*\dp\box*}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\check*max#1{\dimen0=#1\advance\dimen0\*X*
               \ifdim\dimen0>\X*max\global\X*max\dimen0\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\check*X{\ifcheck*\ifdim\*X*<\X*min\global\X*min\*X*\fi
                      \ifdim\*X*>\X*max\global\X*max\*X*\fi\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\check*min#1{\dimen0=-#1\advance\dimen0\*X*
               \ifdim\dimen0<\X*min\global\X*min\dimen0\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\check*#1{\check*min{#1}\check*max{#1}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\check*cen{\ifcen*\errhelp{Use `\hcenterto' or `\vcenterto'.}%
  \errmessage{You can't use `\string\centerto' to center `\the\name*'}\fi}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%  Jede Zeichenoperation ruft \verb+\put*box+ auf, dieses
%  Makro setzt die Box \verb+\*bbox+ an die aktuelle Zeichenposition.
%    \begin{macrocode}
\def\put*box{\hbox to 0pt{\kern\*X*\raise\*Y*\box\*bbox\hss}}
%    \end{macrocode}
%
%
%  In Erweiterung zu \verb+\llap+ und \verb+\rlap+ werden
%  hier weitere Abk"urzungen definiert.
%    \begin{macrocode}
\def\hc*#1{\hbox to 0pt{\hss#1\hss}}
\def\vc*#1{\vbox to 0pt{\vss#1\vss}}
\def\tlap#1{\vbox to 0pt{\vss#1}}
\def\blap#1{\vbox to 0pt{#1\vss}}
\def\ac*#1{\vc*{\hc*{#1}}}
%    \end{macrocode}
%
%
%  Zur"ucksetzen der auf eine Zeichenoperation wirkenden Schalter.
%    \begin{macrocode}
\def\reset*ifs{\ld*false\cen*false\hvcen*false\lab*true\val*true\cc*false}
%    \end{macrocode}
%
% Das Kernmakro f"ur die Speicherung von Anschlu"spunkten.
%    \begin{macrocode}
\def\store*XY#1{\ifshowpoints\message{#1}\fi
  \expandafter\xdef\csname#1\endcsname{\*X*\the\*X*\*Y*\the\*Y*}}
%    \end{macrocode}
%
% Retten der aktuellen Zeichenposition.
%    \begin{macrocode}
\def\save*XY{\**X\*X*\**Y\*Y*}
\def\save*xy{\***X\*X*\***Y\*Y*}
%    \end{macrocode}
%
% Wiederherstellen der aktuellen Zeichenposition
%    \begin{macrocode}
\def\restore*XY{\*X*\**X\*Y*\**Y}
\def\restore*xy{\*X*\***X\*Y*\***Y}
%    \end{macrocode}
%
% Abstand zwischen dem gespeichertem Punkt und dem aktuellen
% in x- und y-Richtung bestimmen
%    \begin{macrocode}
\def\diff*XY{\advance\**X-\*X*\advance\**Y-\*Y*}
%    \end{macrocode}
%
% Zentrierung auf angegebenes Schaltzeichen einschalten.
% Richtung ist durch die folgende Zeichenoperation bestimmt.
%    \begin{macrocode}
\def\centerto#1 {\cen*true\save*XY\frompin#1: }
%    \end{macrocode}
%
% Zentrierung auf angegebenes Schaltzeichen einschalten.
% Die aktuelle y-Position wird beibehalten.
%    \begin{macrocode}
\def\hcenterto#1 {\hvcen*true\**Y\*Y*\frompin#1: \*Y*\**Y}
%    \end{macrocode}
%
% Zentrierung auf angegebenes Schaltzeichen einschalten.
% Die aktuelle x-Position wird beibehalten.
%    \begin{macrocode}
\def\vcenterto#1 {\hvcen*true\**X\*X*\frompin#1: \*X*\**X}
%    \end{macrocode}
%
%
%    \begin{macrocode}
\def\do*Ilist{\ifshowpoints\message{|<}\fi
  \check*true
  \save*XY\the\*Ilist\ifshowpoints\message{>|}\fi\restore*XY\*Ilist={}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\shift*Ilist#1{\ifshowpoints\message{|<}\fi
  \check*false
  \save*XY\the\*Ilist\frompin{\the\name*#1}
  \ifshowpoints\message{| shift \the\name*#1 |}\fi
  \advance\**X\**X\advance\**X-\*X*\*X*\**X
  \advance\**Y\**Y\advance\**Y-\*Y*\*Y*\**Y
  \check*true
  \save*XY\the\*Ilist\restore*XY
  \ifshowpoints\message{>|}\fi\*Ilist={}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\shift*IOlist#1{\ifshowpoints\message{|<}\fi
  \check*false
  \save*XY\the\*Ilist\restore*XY\advance\*X*\wd\*bbox\the\*Olist
  \frompin{\the\name*#1}
  \ifshowpoints\message{| shift \the\name*#1 |}\fi
  \advance\**X\**X\advance\**X-\*X*\*X*\**X
  \advance\**Y\**Y\advance\**Y-\*Y*\*Y*\**Y
  \check*true
  \save*XY\the\*Ilist\restore*XY\advance\*X*\wd\*bbox\the\*Olist
  \restore*XY\ifshowpoints\message{>|}\fi\*Ilist={}\*Olist={}}
%    \end{macrocode}
%
% \Ladd*x  erweitert die Tokenliste \argi um Makros, die das
% Dimensionsregister \XXX um \argii erh"ohen.
% \argii wird als aktueller
% Zahlenwert in die Tokenliste "ubernommen, \argiii wird
% expandiert.
%    \begin{macrocode}
\def\Ladd*x#1#2{\dimen9=#2%
  \edef\next{{\the#1\advance\*X*\the\dimen9 }}%
  \global#1\next}
%    \end{macrocode}
%
% \Ladd*y  ist \verb+\Ladd*x+ in seiner Funktion gleich, das Makro
% ver"andert jedoch \YYY.
%    \begin{macrocode}
\def\Ladd*y#1#2{\dimen9=#2%
  \edef\next{{\the#1\advance\*Y*\the\dimen9 }}%
  \global#1\next}
%    \end{macrocode}
%
% \Lstore* f"ugt in die Tokenliste \argi Makros ein, die die Position unter
% \argii speichern.
%    \begin{macrocode}
\def\Lstore*#1#2{\edef\next{{\the#1\noexpand\store*XY{\the\name*#2}}}%
  \global#1\next}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\Lstopos*#1{\global#1\expandafter{\the#1\save*xy}}
\def\Lrstpos*#1{\global#1\expandafter{\the#1\restore*xy}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\LX*check#1{\global#1\expandafter{\the#1\check*X}}
%    \end{macrocode}
%
% Die folgenden Makros sind schon auf die Tokenliste \verb+\*Ilist+
% festgelegt, da fast alle Anschlu"sdefinitionen nur eine Liste
% benutzen.
%    \begin{macrocode}
\def\add*x{\Ladd*x\*Ilist}
\def\add*y{\Ladd*y\*Ilist}
\def\store*{\Lstore*\*Ilist}
\def\stopos*{\Lstopos*\*Ilist}
\def\rstpos*{\Lrstpos*\*Ilist}
\def\X*check{\LX*check\*Ilist}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\Cadd*#1{\Ladd*y#1{-\pin*spc}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\Cstore*#1#2{\ifx{#2}*\else\Lstore*#1{#2}\fi}
%    \end{macrocode}
%
%  Um einen Anschlu"spunkt zur neuen Zeichenposition zu erkl"aren,
%  wird nur das entsprechende Makro aufgerufen, nachdem zuvor
%  getestet wurde ob es existiert.
%    \begin{macrocode}
\def\frompin#1 {\expandafter\ifx\csname#1\endcsname\relax
  \errhelp{Check spelling! Look up in the description of circuits.}%
  \errmessage{Point >#1< is not defined}\else\csname#1\endcsname\fi}
%    \end{macrocode}
%
% F"ur eine sch"onere Lesbarkeit wird neben {\em von Punkt}
% auch noch {\em am Punkt} definiert.
%    \begin{macrocode}
\let\atpin\frompin
%    \end{macrocode}
%
%
%    \begin{macrocode}
\def\h*twopins{\ifcen*\*Y*\**Y\hvcen*true\fi
\wd\box*=.5\wd*
\advance\ht*\*spc
%
\X*check\store*{\the\ld*pin}\add*x{.5\wd*}\store*:\add*x{.5\wd*}%
\store*{\the\ru*pin}\X*check
\ifhvcen*\shift*Ilist:\else\ifld*\shift*Ilist{\the\ru*pin}\else\do*Ilist\fi\fi
%
\labelfont
\setbox0=\hbox{\the\rud*}\setbox1=\hbox{\the\ldd*}%
\**X\*X*\advance\*X*.5\wd*
\iflab*\check*{.5\wd0}\fi%
\ifval*\check*{.5\wd1}\fi%
\*X*\**X
%
\setbox\*bbox=\hbox{\box\box*
  \iflab*\raise\ht*\hc*{\unhbox0}\fi
  \ifval*\lower\dp*\vtop{\kern\*spc\hc*{\unhbox1}}\fi
  \add*cmds}%
\put*box
\ifld*\else\advance\*X*\wd*\fi\reset*ifs}
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\def\v*twopins{\ifcen*\*X*\**X\hvcen*true\fi
%
\labelfont
\setbox0=\hbox{\ifval*\the\ldd*\kern\*spc\fi\kern\dp*}\dimen1\wd0
\setbox1=\hbox{\kern\wd*\iflab*\kern\*spc\the\rud*\fi}\dimen0\wd1
\dp0=0pt\dp1=0pt
%
\wd\box*=0pt\dp\box*=0pt
\setbox\*bbox=\hbox{\box\box*
  \raise.5\ht*\hbox{\vc*{\hbox{\llap{\box0}\rlap{\box1}}}\add*cmds}}%
%
\store*{\the\ld*pin}\add*y{.5\ht*}\store*:\add*y{.5\ht*}\store*{\the\ru*pin}%
\ifhvcen*\shift*Ilist:\else\ifld*\shift*Ilist{\the\ru*pin}\else\do*Ilist\fi\fi
%
\check*X
\check*max{\dimen0}%
\check*min{\dimen1}%
%
\put*box
\ifld*\else\advance\*Y*\ht*\fi\reset*ifs}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\ii*#1 {\if#1h\ld*pin{l}\ru*pin{r}\getc*0 \h*twopins\else
            \if#1v\ld*pin{d}\ru*pin{u}\getc*1 \v*twopins\else
            \if#1u\ld*pin{d}\ru*pin{u}\getc*1 \v*twopins\else
            \if#1d\ld*pin{d}\ru*pin{u}\getc*1 \ld*true\v*twopins\else
            \if#1l\ld*pin{l}\ru*pin{r}\getc*0 \ld*true\h*twopins\else
            \if#1r\ld*pin{l}\ru*pin{r}\getc*0 \h*twopins\else
                  \errhelp{Direction >h<, >v<, >l<, >u<, >r< or >d< expected.}%
                  \errmessage{Bad direction specified! You typed:>#1<.}%
                  \fi\fi\fi\fi\fi\fi}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\change*pins{\toks0\ld*pin\ld*pin\ru*pin\ru*pin\toks0}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\iv*#1 {\if#1l            \getc*0 \h*twopins\else
            \if#1r\change*pins\getc*2 \h*twopins\else
            \if#1d            \getc*1 \v*twopins\else
            \if#1u\change*pins\getc*3 \v*twopins\else
            \errhelp{Direction >l<, >r<, >u< or >d< expected.}%
            \errmessage{Bad direction >#1<}\fi\fi\fi\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\iviv*#1 {\if#1l            \getc*4 \h*twopins\else
              \if#1r\change*pins\getc*2 \h*twopins\else
              \if#1d            \getc*5 \v*twopins\else
              \if#1u\change*pins\getc*3 \v*twopins\else
              \if#1L            \getc*0 \h*twopins\else
              \if#1R\change*pins\getc*6 \h*twopins\else
              \if#1D            \getc*1 \v*twopins\else
              \if#1U\change*pins\getc*7 \v*twopins\else
              \errhelp{Direction >l<, >r<, >u<, >d<, >L<, >R<, >U< or >D<
                       expected.}%
              \errmessage{Bad direction >#1<}\fi\fi\fi\fi\fi\fi\fi\fi}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\lviii*#1{\store*{\the\m*pin}\X*check
              \add*x\wd*\stopos*\add*y{-\dp*}\store*{\the\ld*pin}\X*check
              \rstpos*\add*y\ht*\store*{\the\ru*pin}\rstpos*
              \dimen0\ht*\advance\dimen0-\dp*\add*y{.5\dimen0}\store*:
              \rstpos*\add*x\ic*\X*check
              \ifhvcen*\shift*Ilist:\else\shift*Ilist{#1}\fi
              \setbox\*bbox=\hbox{\labelfont
                \the\llpos*\box\box*\the\ldpos*}\put*box}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\rviii*#1{\store*{\the\m*pin}\X*check
              \add*x{-\wd*}\stopos*\add*y\ht*\store*{\the\ru*pin}\X*check
              \rstpos*\add*y{-\dp*}\store*{\the\ld*pin}\rstpos*
              \dimen0\ht*\advance\dimen0-\dp*\add*y{.5\dimen0}\store*:
              \rstpos*\add*x{-\ic*}\X*check
              \ifhvcen*\shift*Ilist:\else\shift*Ilist{#1}\fi
              \setbox\*bbox=\hbox{\labelfont
                \the\rdpos*\box\box*\the\rlpos*}\put*box}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\dviii*#1{\store*{\the\m*pin}%
              \add*y\dp*\stopos*\add*x\ic*\store*{\the\ru*pin}\X*check
              \rstpos*\add*x{-\wd*}\store*{\the\ld*pin}\X*check
              \rstpos*\dimen0-\wd*\advance\dimen0\ic*\add*x{.5\dimen0}\store*:
              \ifhvcen*\shift*Ilist:\else\shift*Ilist{#1}\fi
              \wd\box*=0pt\dp\box*=0pt
              \setbox\*bbox=\hbox{\labelfont
                \the\dlpos*\box\box*\the\ddpos*}\put*box}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\uviii*#1{\store*{\the\m*pin}%
              \add*y{-\ht*}\stopos*\add*x\ic*\store*{\the\ru*pin}\X*check
              \rstpos*\add*x{-\wd*}\store*{\the\ld*pin}\X*check
              \rstpos*\dimen0-\wd*\advance\dimen0\ic*\add*x{.5\dimen0}\store*:
              \ifhvcen*\shift*Ilist:\else\shift*Ilist{#1}\fi
              \wd\box*=0pt\ht\box*=0pt
              \setbox\*bbox=\hbox{\labelfont
                \the\ulpos*\box\box*\the\udpos*}\put*box}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\viii*#1 #2 {\check*cen
                 \if#2l            \getc*0 \lviii*{#1}\else
                 \if#2r            \getc*1 \rviii*{#1}\else
                 \if#2d            \getc*3 \dviii*{#1}\else
                 \if#2u            \getc*2 \uviii*{#1}\else
                 \if#2L\change*pins\getc*4 \lviii*{#1}\else
                 \if#2R\change*pins\getc*5 \rviii*{#1}\else
                 \if#2D\change*pins\getc*7 \dviii*{#1}\else
                 \if#2U\change*pins\getc*6 \uviii*{#1}\else
                 \errhelp{Direction >l<, >r<, >u<, >d<, >L<, >R<, >U< or >D<
                          expected.}%
                 \errmessage{Bad direction >#2<}\fi\fi\fi\fi\fi\fi\fi\fi
                 \reset*ifs}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\cdef#1 #2 #3#4 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\cc*#4 #3\ii*}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\cdefiv#1 #2 #3#4 #5 #6 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\ld*pin{#5}\ru*pin{#6}\cc*#4 #3
   \iv*}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\cdefiviv#1 #2 #3#4 #5 #6 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{$#2_{##1}$}\ldd*{##2}\ld*pin{#5}\ru*pin{#6}\cc*#4 #3
   \iviv*}}
%    \end{macrocode}
%
%
%    \begin{macrocode}
\def\cdefNL#1 #2#3 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\cc*#3 #2\ii*}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\cdefivNL#1 #2#3 #4 #5 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\ld*pin{#4}\ru*pin{#5}\cc*#3 #2\iv*}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\cdefivivNL#1 #2#3 #4 #5 {\expandafter\def\csname#1\endcsname##1 ##2 {%
   \name*{#1##1}\rud*{}\ldd*{##2}\ld*pin{#4}\ru*pin{#5}\cc*#3 #2\iviv*}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\cdefviii#1 #2 #3#4 #5 #6 #7 {\expandafter
   \def\csname#1\endcsname##1 ##2 {\name*{#1##1}%
   \rud*{$#2_{##1}$}\ldd*{##2}\ld*pin{#5}\m*pin{#6}\ru*pin{#7}\cc*#4 #3\viii*}}
%    \end{macrocode}
%    \begin{macrocode}
\def\cwdef#1 #2 {\expandafter\def\csname#1\endcsname##1 ##2 {\cc*#2
                 \cnta*##1\toks2{}\toks4{}\dimen2=##1em\test*xygrid
                 \csname line*##2\endcsname}}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\black*boxii#1 #2 #3 #4 #5 #6 #7 {\check*cen
  \if#7h\getc*0
  \store*{P1}\X*check\add*x{.5\wd*}\stopos*\X*check\store*:
  \add*y\ht*\store*{P4}\rstpos*\add*y{-\dp*}\store*{P2}\rstpos*
  \add*x{.5\wd*}\X*check\store*{P3}%
  \ifhvcen*\shift*Ilist:\else\shift*Ilist{#2}\fi
  \setbox\*bbox=\hbox{\ifpin\pinnumberfont
    \setbox0=\hbox{#3\kern\*spc}\check*min{\wd0}%
    \raise\pinnum*spc\llap{#3\kern\*spc}%
    \setbox0=\hbox{\kern\*spc\kern\wd*#5}\check*max{\wd0}\wd0=0pt
    \raise\pinnum*spc\box0
    \setbox0=\hbox{\kern\pinnum*spc\kern.5\wd*#6}\check*max{\wd0}\wd0=0pt
    \dimen0\ht*\advance\dimen0\*spc
    \raise\dimen0\box0
    \setbox0=\hbox{\kern\pinnum*spc\kern.5\wd*#4}\check*max{\wd0}\wd0=0pt
    \dimen0\dp*\advance\dimen0\*spc
    \lower\dimen0\vtop{\kern0pt\box0}\fi
    \hc*{\kern\wd*\ctextfont\vc*{\hbox{#1}}}\box\box*}\put*box\reset*ifs
  \else\if#7v\getc*1
  \store*{P4}\X*check\add*x{.5\wd*}\stopos*\X*check\store*:
  \add*y\ht*\store*{P3}\rstpos*\add*y{-\dp*}\store*{P1}\rstpos*
  \add*x{.5\wd*}\X*check\store*{P2}%
  \ifhvcen*\shift*Ilist:\else\shift*Ilist{#2}\fi
  \setbox\*bbox=\hbox{\ifpin\pinnumberfont
    \setbox0=\hbox{#6\kern\*spc}\check*min{\wd0}%
    \raise\pinnum*spc\llap{#6\kern\*spc}%
    \setbox0=\hbox{\kern\*spc\kern\wd*#4}\check*max{\wd0}\wd0=0pt
    \raise\pinnum*spc\box0
    \setbox0=\hbox{\kern\pinnum*spc\kern.5\wd*#5}\check*max{\wd0}\wd0=0pt
    \dimen0\ht*\advance\dimen0\*spc
    \raise\dimen0\box0
    \setbox0=\hbox{\kern\pinnum*spc\kern.5\wd*#3}\check*max{\wd0}\wd0=0pt
    \dimen0\dp*\advance\dimen0\*spc
    \lower\dimen0\vtop{\kern0pt\box0}\fi
    \hc*{\kern\wd*\ctextfont\vc*{\hbox{#1}}}\box\box*}\put*box\reset*ifs
  \else\errhelp{Direction >h< or >v< expected.}%
  \errmessage{ >#1<  Bad direction specified}\fi\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\black*box#1 #2 #3 #4 #5 #6 {\black*boxii{#1} {#2} {#3} {#4} {#5} {#6} h }
%    \end{macrocode}
%
%    \begin{macrocode}
\def\sym*box#1 #2 {\check*cen
  \getc*0
  \store*{P1}\X*check\stopos*
  \add*x{.5\wd*}\store*:\add*x{.5\wd*}\store*{P3}\X*check\rstpos*
  \add*y{-1em}\store* b
  \add*x{\wd*}\store* e\rstpos*
  \add*y{1em}\store* a
  \add*x{\wd*}\store* f\rstpos*
  \add*x{.5\wd*}\stopos*
  \add*y\ht*\store*{P4}%
  \add*x{1em}\store* g
  \rstpos*\add*y\ht*
  \add*x{-1em}\store* h
  \rstpos*\add*y{-\dp*}\store*{P2}%
  \add*x{1em}\store* d
  \rstpos*\add*y{-\dp*}%
  \add*x{-1em}\store* c
  \ifhvcen*\shift*Ilist:\else\shift*Ilist{#2}\fi
  \setbox\*bbox=
    \hbox{\hc*{\kern\wd*\ctextfont\vc*{\hbox{#1}}}\box\box*}\put*box
    \reset*ifs}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\bbdef#1 #2#3 {\expandafter
   \def\csname#1\endcsname##1 {\name*{#1##1}\cc*#3 #2\black*box}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\bbdefNeT#1 #2#3 #4 {\expandafter
   \def\csname#1\endcsname##1 {\name*{#1##1}\cc*#3#2\black*box{#4} }}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\bbdefNeTii#1 #2#3 #4 {\expandafter
   \def\csname#1\endcsname##1 {\name*{#1##1}\cc*#3#2\black*boxii{#4} }}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\sbdef#1 #2#3 #4 {\expandafter
   \def\csname#1\endcsname##1 {\name*{#1##1}\cc*#3#2\sym*box{#4} }}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
% ^^A beschr p l1 l2 l3
%
% ^^A\cc*
% ^^A\name*
% ^^A\**pin
% ^^A\ldd* -> innenbeschriftung
%
%</code>
%<+gate>\ProvidesFile{gate.def}
%<+gate>\freecirc
%<*gate>
%    \begin{macrocode}
\def\g*iio#1 #2 #3 #4 #5 {\dimen4\*X*\dimen5\*Y*
  \rud*{#1}\getc*0
  \stopos*\add*y\ic*\X*check\store*{\the\ru*pin}\rstpos*
  \add*y{-\ic*}\store*{\the\ld*pin}\rstpos*
  \add*x{.5\wd*}\store*:\add*x{.5\wd*}\X*check\store*{\the\m*pin}%
  \ifhvcen*\shift*Ilist:\else\shift*Ilist{#2}\fi
  \setbox\*bbox=\hbox{\ifpin\pinnumberfont
    \dimen0\ic*\advance\dimen0\pinnum*spc
    \raise\dimen0\rlap{\kern\pin*ind\hc*{#3}}%
    \dimen0-\ic*\advance\dimen0\pinnum*spc
    \raise\dimen0\rlap{\kern\pin*ind\hc*{#4}}%
    \raise\pinnum*spc\rlap{\kern\wd*\kern-\pin*ind\hc*{#5}}\fi
    \the\ldd*\box\box*}\put*box\reset*ifs
  \*X*\dimen4\*Y*\dimen5}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\g*io#1 #2 #3 #4 {\dimen4\*X*\dimen5\*Y*
  \rud*{#1}\getc*0
  \store*{\the\ld*pin}%
  \add*x{.5\wd*}\store*:\add*x{.5\wd*}\X*check\store*{\the\m*pin}%
  \ifhvcen*\shift*Ilist:\else\shift*Ilist{#2}\fi
  \setbox\*bbox=\hbox{\ifpin\pinnumberfont
    \raise\pinnum*spc\rlap{\kern\pin*ind\hc*{#3}}%
    \raise\pinnum*spc\rlap{\kern\wd*\kern-\pin*ind\hc*{#4}}\fi
    \the\ldd*\box\box*}\put*box\reset*ifs
  \*X*\dimen4\*Y*\dimen5}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\gateIIO#1 #2#3 #4#5 #6 #7 {\expandafter
  \def\csname#1\endcsname##1 {\name*{#1##1}\ldd*{#4}%
    \ld*pin{#5}\m*pin{#6}\ru*pin{#7}\cc*#3 #2\g*iio}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\ldd*gN#1{\raise\fontdimen10\c*fntb\rlap{\kern\fontdimen11\c*fntb
    \blap{\llap{\symfont#1}}}\lower\dp*\vtop{\kern\*spc
    \hc*{\labelfont\kern\wd*\the\rud*}}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\ldd*OV{\ac*{\kern.8\wd*\ctextfont\the\rud*}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\NgateIIO#1 #2#3 #4 {\expandafter
  \def\csname#1\endcsname##1 {\name*{#1##1}\ldd*{\ldd*gN{#4}}%
    \ld*pin{I2}\m*pin{O}\ru*pin{I1}\cc*#3 #2\g*iio}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\gateIO#1 #2#3 #4#5 #6 {\expandafter
  \def\csname#1\endcsname##1 {\name*{#1##1}\ldd*{#4}%
    \ld*pin{#4}\m*pin{#5}\cc*#3 #2\g*io}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\NgateIO#1 #2#3 #4 {\expandafter
  \def\csname#1\endcsname##1 {\name*{#1##1}\ldd*{\ldd*gN{#4}}%
    \ld*pin{I}\m*pin{O}\cc*#3 #2\g*io}}
%    \end{macrocode}
%</gate>
%<*code>
%^^A last update: Tue  02-04-1997
%</code>
%<*doc>
{\small\it\xdef\itf{\the\font}}
{\normalsize\tt\xdef\ttf{\the\font}\small\xdef\stt{\the\font}}
\def\myindex#1{\index{#1@\string\texttt{\string\char'134 #1}}}
\def\cmd#1 {\myindex{#1}\ttf\expandafter\string\csname#1\endcsname\itf number\ttf\sspc}
\def\cmdni#1 {\ttf\expandafter\string\csname#1\endcsname\itf number\ttf\sspc}
\def\cmdx#1 {\myindex{#1}\ttf\expandafter\string\csname#1\endcsname\ }
\def\optionline#1 {\vskip5mm\rm\textbf{symbols of option:} {\large\tt#1}\vskip3mm}
\def\synt{\rm syntax of following symbols: }
\def\sspc{\char'40}
\def\lpin#1 {\shift -1.5 0 \text{} \shift 1.5 0
             {\shift -.5 0 \text{\vbox to 0pt{\vss\llap{\stt #1}\vss}} }}
\def\rpin#1 {\shift 1.5 0 \text{} \shift -1.5 0
             {\shift .5  0 \text{\vbox to 0pt{\vss\hbox{\stt #1}\vss}} }}
\def\upin#1 {\shift 1.5 0 \text{} \shift -1.5 0
             {\shift 0 .5 \text{\hbox to 0pt{\hss\stt#1\hss}} }}
\def\dpin#1 {\shift -1.5 0 \text{} \shift 1.5 0
             {\shift 0 -.5 \text{\vtop{\kern0pt\llap{\stt#1\hss}}} }}
\def\inbrackets#1 {\itf[\/\ttf#1\itf\/]\ttf\sspc}
\def\valtxt {\itf inscription\ttf\sspc}
\def\txt {\itf text\ttf\sspc}
\def\sty{\itf style\ttf\sspc}
\def\arg#1 {\ttf#1\sspc}
\def\pnt#1 {\itf pin\_reference#1\ttf\sspc}
\def\spec {\itf specification\_parameter\ttf\sspc}
\def\twolab {\itf label1\ttf\sspc\itf label2\ttf\sspc}
\def\threelab {\twolab \itf label3\ttf\sspc}
\def\fourlab {\threelab \itf label4\ttf\sspc}
\def\length {\itf length\ttf\sspc}
\def\printtwo#1 #2{\hfill
\valign{\vfil##\vfil\cr
\hbox{\circuit0 \lpin l \csname#1\endcsname1 {X} h \rpin r \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin d \csname#1\endcsname1 {X} v \upin u \endcircuit}
\cr
\vbox{\hbox to 7.5cm{\qquad #2\hss}\kern1mm
      \hbox to 7.5cm{\qquad\cmd#1 \valtxt \inbrackets{h v} \hss}}\cr}
\vskip0pt}
\def\printfour#1 #2#3#4{\hfill
\valign{\vfil##\vfil\cr
\hbox{\circuit0 \lpin#2 \csname#1\endcsname1 {X} l \rpin#3 \endcircuit}
\cr
\hbox{\quad\circuit0 \lpin#3 \csname#1\endcsname1 {X} r \rpin#2 \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin#3 \csname#1\endcsname1 {X} u \upin#2 \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin#2 \csname#1\endcsname1 {X} d \upin#3 \endcircuit}
\cr
\vbox{\hbox to 7.5cm{\qquad #4\hss}\kern1mm
      \hbox to 7.5cm{\qquad\cmd#1 \valtxt \inbrackets{l r u d} \hss}}\cr}
\vskip0pt}
\def\printfourfour#1 #2#3#4{\hfill
\valign{\vfil##\vfil\cr
\hbox{\circuit0 \lpin#2 \csname#1\endcsname1 {X} l \rpin#3 \endcircuit}
\cr
\hbox{\quad\circuit0 \lpin#3 \csname#1\endcsname1 {X} r \rpin#2 \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin#3 \csname#1\endcsname1 {X} u \upin#2 \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin#2 \csname#1\endcsname1 {X} d \upin#3 \endcircuit}
\cr
\vbox{\hbox to 7.5cm{\qquad #4\hss}\kern1mm
      \hbox to 7.5cm{\qquad\cmd#1 \valtxt \inbrackets{l r u d} \hss}}\cr}
\vskip0pt\hfill\valign{\vfil##\vfil\cr
\hbox{\circuit0 \lpin#2 \csname#1\endcsname1 {X} L \rpin#3 \endcircuit}
\cr
\hbox{\quad\circuit0 \lpin#3 \csname#1\endcsname1 {X} R \rpin#2 \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin#3 \csname#1\endcsname1 {X} U \upin#2 \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin#2 \csname#1\endcsname1 {X} D \upin#3 \endcircuit}
\cr
\hbox to 7.5cm{\qquad\cmd#1 \valtxt \inbrackets{L R U D} \hss}\cr}
\vskip0pt}
\def\printeight#1 #2#3#4#5{\hfill
\valign{\vfil##\vfil\cr
\hbox{\circuit0 \lpin#2 \csname#1\endcsname1 {X} #2 l
      \atpin#11#3 \dpin#3 \atpin#11#4 \upin#4 \endcircuit}
\cr
\hbox{\quad\circuit0 \rpin#2 \csname#1\endcsname1 {X} #2 r
      \atpin#11#3 \dpin#3 \atpin#11#4 \upin#4 \endcircuit}
\cr
\hbox{\quad\circuit0 \upin#2 \csname#1\endcsname1 {X} #2 u
      \atpin#11#3 \lpin#3 \atpin#11#4 \rpin#4 \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin#2 \csname#1\endcsname1 {X} #2 d
      \atpin#11#3 \lpin#3 \atpin#11#4 \rpin#4 \endcircuit}
\cr
\vbox{\hbox to 7.5cm{\qquad #5\hss}\kern1mm
      \hbox to 7.5cm{\qquad\cmd#1 \valtxt \inbrackets{#2\ #3\ #4}
                   \inbrackets{l r u d} \hss}}
\cr}
\vskip 0mm\hfill
\valign{\vfil##\vfil\cr
\hbox{\circuit0 \lpin#2 \csname#1\endcsname1 {X} #2 L
      \atpin#11#3 \upin#3 \atpin#11#4 \dpin#4 \endcircuit}
\cr
\hbox{\quad\circuit0 \rpin#2 \csname#1\endcsname1 {X} #2 R
      \atpin#11#3 \upin#3 \atpin#11#4 \dpin#4 \endcircuit}
\cr
\hbox{\quad\circuit0 \upin#2 \csname#1\endcsname1 {X} #2 U
      \atpin#11#3 \rpin#3 \atpin#11#4 \lpin#4 \endcircuit}
\cr
\hbox{\quad\circuit0 \dpin#2 \csname#1\endcsname1 {X} #2 D
      \atpin#11#3 \rpin#3 \atpin#11#4 \lpin#4 \endcircuit}
\cr
\hbox to 7.5cm{\qquad\cmd#1 \valtxt \inbrackets{#2\ #3\ #4}
                   \inbrackets{L R U D} \hss}
\cr}
\vskip0pt}
\def\printthree#1 #2#3#4#5{\indent\hbox{\vbox{
\hbox{\circuit0 \csname#1\endcsname1 {X} #2 l1 l2 l3
  \atpin #11#2 \lpin #2 \atpin #11#3 \lpin #3 \atpin #11#4 \rpin #4
\endcircuit}
  \hbox{\rm #5\quad}\kern1mm
  \hbox{\cmdx#1 \ldots \quad}}~} }
%
\def\threegate#1 #2{\printthree#1 {I1}{I2}{O}{#2}}
%
\def\twogate#1 #2{\indent\hbox{\vbox{
\hbox{\circuit0 \csname#1\endcsname1 {X} I l1 l2
  \atpin #11I \lpin I \atpin #11O \rpin O
\endcircuit}
\hbox{\rm #2\quad}\kern1mm
\hbox{\cmdx#1 \ldots \quad}}~} }
%
\def\printone#1 #2 {\indent\hbox{\vbox{
\hbox{\circuit0 \csname#1\endcsname1 \endcircuit}\kern1mm
\hbox{\rm #2\quad}\kern1mm
\hbox{\cmd#1 \quad}}~} }
%
\def\textdef#1 {%
\valign{\vfil##\vfil\cr
\hbox{\circuit0 \.1 \at 6 0 \.2 \text{}
      \csname#1\endcsname{text} from .1 to .2 \endcircuit}
\cr
\hbox{\circuit0 \at -4 0 \text{} \at 0 0 \.1 \at 0 6 \.2 \at 8 0 \text{}
      \csname#1\endcsname{text} from .1 to .2 \endcircuit}
\cr
 \hbox{\cmdx#1 \txt \arg from \pnt1 \arg to \pnt2 }
\cr}\vskip0mm}
\def\cwdef#1 #2 #3 {%
\valign{\vfil##\vfil\cr
\hbox{\circuit0 \csname#1\endcsname 4 l \at 6 0 \text{} \endcircuit}
\cr
\hbox{\circuit0 \csname#1\endcsname 4 u \at 8 0 \text{} \endcircuit}
\cr
 \hbox{\cmdx#1 length \inbrackets{l r u d} }
\cr}\vskip0mm}
\def\cwwdef#1 #2 {%
\valign{\vfil##\vfil\cr
\hbox{\circuit0 \csname#1\endcsname X 4 l \at 6 0 \text{} \endcircuit}
\cr
\hbox{\circuit0 \csname#1\endcsname X 4 u \at 8 0 \text{} \endcircuit}
\cr
 \hbox{\cmdx#1 \txt length \inbrackets{l r u d} }
\cr}\vskip0mm}
\def\cdef#1 #2 #3#4 #5 {\printtwo#1 {#5}}
\def\cdefiviv#1 #2 #3#4 #5 #6 #7 {\printfourfour#1 {#5}{#6}{#7}}
\def\cdefiv#1 #2 #3#4 #5 #6 #7 {\printfour#1 {#5}{#6}{#7}}
\def\cdefNL#1 #2#3 #4 {\printtwo#1 {#4}}
\def\cdefivivNL#1 #2#3 #4 #5 #6 {\printfourfour#1 {#4}{#5}{#6}}
\def\cdefivNL#1 #2#3 #4 #5 #6 {\printfour#1 {#4}{#5}{#6}}
\def\cdefviii#1 #2 #3#4 #5 #6 #7 #8 {\printeight#1 {#6}{#5}{#7}{#8}}
%
\def\bbdef#1 #2#3 #4 {\indent\hbox{\vbox{
\hbox{\circuit0 \csname#1\endcsname1 X P1 l1 l2 l3 l4 \endcircuit}
\hbox{\rm #4\qquad}\kern1mm\hbox{\cmdx#1 \ldots\qquad}}\quad} }
%
\def\bbdefNeT#1 #2#3 #4 #5 {\indent\hbox{\vbox{
\hbox{\circuit0 \csname#1\endcsname1 P1 l1 l2 l3 l4 \endcircuit}
\hbox{\rm #5\qquad}\kern1mm\hbox{\cmdx#1 \ldots\qquad}}\quad} }
%
\def\bbdefNeTii#1 #2#3 #4 #5 {\valign{\vfil##\vfil\cr
\hbox{\circuit0 \csname#1\endcsname1 P1 l1 l2 l3 l4 h \endcircuit}
\cr
\hbox{\quad\circuit0 \csname#1\endcsname1 P1 l1 l2 l3 l4 v \endcircuit}
\cr
\vtop{\hbox{\qquad\rm #5}\kern1mm
\hbox{\qquad\cmd#1 \spec \fourlab \inbrackets{h v} }}\cr}
\vskip0pt}
%
\def\sbdef#1 #2 #3 #4 {\valign{\vfil##\vfil\cr
\hbox{\circuit0 \csname#1\endcsname1 P1
   \atpin #11P1 \shift -1 0 \lpin P1
   \atpin #11a \lpin a \atpin #11b \lpin b
   \atpin #11c \dpin c \atpin #11P2 \shift 0 -1 \dpin  P2
   \atpin #11d \dpin d \atpin #11e \rpin e \atpin #11P3 \shift 1 0 \rpin P3
   \atpin #11f \rpin f \atpin #11g \upin g \atpin #11P4 \shift 0 1 \upin P4
   \atpin #11h \upin h \endcircuit}\cr
\vtop{\hbox{\qquad #4}\kern1mm\hbox{\qquad\cmd#1 \spec }}\cr}\vskip0pt}
\def\gateIIO#1 #2#3 #4#5 #6 #7 #8 {\printthree#1 {#5}{#7}{#6}{#8}}
\def\NgateIIO#1 #2#3 #4 #5 {\threegate#1 {#5}}
\def\NgateIO#1 #2#3 #4 #5 {\twogate#1 {#5}}
\def\Clpin#1 {\expandafter\atpin\CNAME#1 \lpin{#1} }
\def\Crpin#1 {\expandafter\atpin\CNAME#1 \rpin{#1} }
\def\Ccirc#1 #2 #3 #4 {\def\CNAME{#11}\indent\hbox{\vbox{
\hbox{\circuit0 \csname#1\endcsname1 {X} #2 {} #4 \endcircuit}
\hbox{\rm #3\quad}\kern1mm\hbox{\cmdx#1 \ldots\quad}}~} }
%
\freecirc
\advance\hsize by 4cm
\hbox{\circuit0 \CIRCLogo \endcircuit\hskip3cm
  \verb|\CIRCLogo|\ttf\sspc }\vskip5mm
%</doc>
%<*code,doc>
\cwdef        wire   {128\c*fnt}
%<+doc> {wire}
\cwdef        dashed {120\c*fnt}
%<+doc> {dashed wire}
%<+doc>\cwwdef bundle {bundle}
%<+doc>\cwwdef wwire {double wire}
%<+doc>\textdef Utext
%<+doc>\textdef centertext
%</code,doc>
%<*basic>
\ProvidesFile{basic.def}
\freecirc
\def\GND#1 {\setbox\*bbox=\hbox{\c*fnt\char254}%
  \check*min{\wd\*bbox}\check*max{\wd\*bbox}\put*box
  \store*XY{GND#1}\reset*ifs}
\def\gnd#1 {\setbox\*bbox=\hbox{\c*fnt\char253}%
  \check*min{\wd\*bbox}\check*max{\wd\*bbox}\put*box
  \store*XY{gnd#1}\reset*ifs}
\def\junction#1 {\setbox\*bbox=\hbox{\c*fnt\char255}\check*{\wd\*bbox}\check*X
                 \put*box\store*XY{.#1:}\store*XY{junction#1:}%
                 \store*XY{junction#1}\store*XY{.#1}\reset*ifs}
%</basic>
%<*basic,doc>
%<+doc>\optionline basic
%<+doc>\printone GND ground
%<+doc>\printone gnd ground
%<+doc>\myindex{junction}\printone . junction \par
\cdef         R     R     \c*fntw    0
%<+doc> {resistor}
\cdefviii     Rvar  R     \c*fntw    8          . S *
%<+doc> {variable resistor}
\cdef         C     C     \c*fntw  128
%<+doc> {capacitor}
\cdef         Cvar  C     \c*fntw  130
%<+doc> {variable capacitor}
\cdefiv       Cel   C     \c*fntw  136          - +
%<+doc> {electrolytic capacitor}
\cdefiv       D     D     \c*fntd    0          K A
%<+doc> {diode}
\cdefiv       ZD    D     \c*fntd    4          K A
%<+doc> {Zener diode}
\cdefiviv     LED   D     \c*fntd    8          K A
%<+doc> {light emitting diode}
\cdefiv       Dcap  D     \c*fntd   16          K A
%<+doc> {capacitance variation diode}
\cdefiv       whatI I     \c*fnt   248          . *
%<+doc> {current flow}
\cdefiv       U     U     \c*fnt    16          + -
%<+doc> {voltage source}
\cdefiv       Uvar  U     \c*fnt    20          + -
%<+doc> {variable voltage source}
\cdef         I     I     \c*fnt    12
%<+doc> {current source}
\cdef         Ivar  I     \c*fnt    14
%<+doc> {variable current source}
\cdef         V     U     {\def\add*cmds{\clr*acmds
                           \ac*{\symfont V}}\c*fnt}8
%<+doc> {voltmeter}
\cdef         A     I     {\def\add*cmds{\clr*acmds
                           \ac*{\symfont A}}\c*fnt}8
%<+doc> {amperemeter}
\cdefiv       L     L     \c*fnt     0          . *
%<+doc> {coil}
\cdef         Q     Q     \c*fnt     4
%<+doc> {quartz crystal}
\cdef         La    La    \c*fnt     6
%<+doc> {incandescent lamp} % electric bulb
\cdef         S     S     \c*fnt    24
%<+doc> {switch}
\cdefviii     SW    S     \c*fnt    32          o s c
%<+doc> {changeover switch}
\cdefivNL     mconnection \c*fnt   232          . *
%<+doc> {connection (pointed)}
\cdefivNL     connection  \c*fnt   240          . *
%<+doc> {connection (round empty)}
\cdefivNL     fconnection \c*fnt   244          . *
%<+doc> {connection (round full)}
\cdefviii     npnEC T     \c*fntt    0          E . C
%<+doc> {npn-transistor without base}
\cdefviii     pnpEC T     \c*fntt    8          E . C
%<+doc> {pnp-transistor without base}
\cdefviii     npn   T     \c*fntt   16          E B C
%<+doc> {npn-transistor}
\cdefviii     pnp   T     \c*fntt   24          E B C
%<+doc> {pnp-transistor}
\cdefviii     nfet  T     \c*fntt   32          S G D
%<+doc> {n-channel field effect transistor}
\cdefviii     pfet  T     \c*fntt   40          S G D
%<+doc> {p-channel field effect transistor}
\cdefviii     nvmos T     \c*fntt   48          S G D
%<+doc> {}
\cdefviii     pvmos T     \c*fntt   56          S G D
%<+doc> {}
\cdefviii     namos T     \c*fntt   64          S G D
%<+doc> {}
\cdefviii     pamos T     \c*fntt   72          S G D
%<+doc> {}
%<+basic>\protectcirc
%</basic,doc>
%<*gate,doc>
%<+doc>\pagebreak
%<+doc>\optionline gate
%<+doc>\synt \cmdni??? \txt \spec \threelab \par
\gateIIO      OV          \c*fntb  255 \ldd*OV  + O -
%<+doc> {operational amplifier}
\gateIIO      ov          \c*fntb  254 \ldd*OV  - O +
%<+doc> {operational amplifier}
%<+doc>
\NgateIIO     NAND        \c*fntb  132 {$\&$}
%<+doc> {NAND-gate}
\NgateIIO     AND         \c*fntb  131 {$\&$}
%<+doc> {AND-gate}
\NgateIIO     OR          \c*fntb  131 {$\ge$1}
%<+doc> {OR-gate}
\NgateIIO     NOR         \c*fntb  132 {$\ge$1}
%<+doc> {NOR-gate}
\NgateIIO     XOR         \c*fntb  131 {$=$1}
%<+doc> {XOR-gate}
\NgateIIO     XNOR        \c*fntb  131 {$=$\vrule width 0pt height 1.5ex\,}
%<+doc> {XNOR-gate}
%<+doc>\vskip3mm\synt \cmdni??? \txt \spec \twolab \par
\NgateIO      INV         \c*fntb  130 {1\,}
%<+doc> {NOT-gate}
\NgateIO      ST          \c*fntb  128 {{\c*fnts\char7}}
%<+doc> {Schmitt trigger}
\NgateIO      STINV       \c*fntb  130 {{\c*fnts\char7}}
%<+doc> {inverted Schmitt trigger}
\NgateIO      BUF         \c*fntb  130 {{\c*fnts\char25}}
%<+doc> {buffer}
%<+gate>\protectcirc
%</gate,doc>
%<*box,doc>
%<+box>\ProvidesFile{box.def}
%<+box>\freecirc
%<+doc>\optionline box
%<+doc>If there is no specification parameter drawn on the symbol,
%<+doc>{\ttf P1, P2 P3} or {\ttf P4} is possible.
%<+doc>\vskip3mm\synt \cmdni??? \txt \spec \fourlab \par
\bbdef        BBa         \c*fntb  252
%<+doc> {black box analog}
\bbdef        BBd         \c*fntb  253
%<+doc> {black box digital}
%<+doc>\pagebreak
%<+doc>\vskip3mm\synt \cmdni??? \spec \fourlab \par
\bbdefNeT oscillograph \c*fnt  142 {}
%<+doc> {oscillograph}
\bbdefNeT G    \c*fntb 250 \vbox{\hc*{\symfont G}\kern1.5\*spc%
                                 \hc*{\c*fnts\char16}}
%<+doc> {generator}
\bbdefNeT Gvar \c*fntb 250 \vbox{\hc*{\symfont G}\kern1.5\*spc%
                                 \hc*{\c*fnts\char17}}
%<+doc> {generator, variable}
\bbdefNeT Impulse \c*fntb 250 \c*fnts\char4
%<+doc> {generator, pulses}
\bbdefNeT Amp  \c*fntb 250 \c*fnts\char24
%<+doc> {amplifier}
%<+doc>
\sbdef ACtoDC \c*fntb 251 \hbox{\raise.6\ht*\hbox{\c*fnts\char16}%
                                \lower.6\dp*\hbox{\symfont$=$}}
%<+doc> {AC to DC converter}
%<+box>\protectcirc
%</box,doc>
%<*doc>
\optionline ic
Today the style parameter should be empty. Like {\ttf\{\}}.
\vskip3mm\synt \cmdni??? \txt \spec \sty \par
\Ccirc RSFF S {RS flip flop} {\Clpin S \Clpin R \Crpin Q \Crpin NQ}
\Ccirc NRSFF S {RS flip flop} {\Clpin S \Clpin R \Crpin Q \Crpin NQ}
\Ccirc DFF C {D flip flop} {\Clpin C \Clpin D \Crpin Q \Crpin NQ}
\Ccirc JKMSFF R {JK master slave flip flop}
  {\Clpin S \Clpin J \Clpin C \Clpin K \Clpin R \Crpin Q \Crpin NQ }
\Ccirc fff R {timer NE\,555}
  {\Clpin IS \Clpin IT \Clpin R \Crpin OK \Crpin O \Crpin OD }
%</doc>
%^^A last update: Tue  02-04-1997
%<*optics>
% First lets define the header of module OPTICS.
%    \begin{macrocode}
\ProvidesFile{optics.def}
\freecirc
%    \end{macrocode}
%    \begin{macrocode}
\def\Dtext#1 from #2 to #3 {{
  \frompin{#2} \save*XY\frompin{#3} \diff*XY
    \ifdim\**X=0pt
      \dimen0\**Y
      \ifdim\**Y<0pt\dimen0-\dimen0\fi
      \c*fnts\setbox0=\hbox{\char9}\setbox1=\hbox{\char11}%
      \c*fnt\setbox2=\hbox{\char132}\dp1=0pt
        \advance\dimen0-\ht0\calc*u
        \setbox\*bbox=
          \vtop{\box1\loop\ifnum\cntb*>0\copy2
            \advance\cntb*-1\repeat\box0}%
      \put*box\advance\*X*\*spc\advance\*Y*.5\**Y\text\vc*{\hbox{#1}}
    \else
    \ifdim\**Y=0pt
      \advance\*X*\**X
      \dimen0\**X
      \ifdim\**X<0pt\dimen0-\dimen0\fi
        \c*fnts\setbox0=\hbox{\char8}\setbox1=\hbox{\char10}%
        \c*fnt\advance\dimen0-\wd0\calc*u
        \setbox\*bbox=\hbox{\box0\loop\ifnum\cntb*>0\advance\cntb*-1
        \char129\repeat\box1}%
      \put*box\advance\*X*-.5\**X\advance\*Y*\*spc\text\hc*{#1}
    \else\errhelp{Only horizontal or vertical labeling allowed.}%
    \errmessage{Bad points!}\fi\fi}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\opticfontinit{\font\c*fnto=optic     scaled \*mag}
%    \end{macrocode}
%
%</optics>
%<*optics,doc>
%<+doc>\optionline optics
%<+doc>\textdef Dtext
%    \begin{macrocode}
\cwdef     oa          {128\c*fnto}
%<+doc> {optical axis}
\cdef      SLens    L  \c*fnto   0
%<+doc> {thin lens}
\cdefiv    HSLens   L  \c*fnto   2 {} {}
%<+doc> {half thin lens}
\cdef      BLens    L  \c*fnto   6
%<+doc> {thick lens}
\cdefiv    HBLens   L  \c*fnto   8 {} {}
%<+doc> {half thick lens}
\cdef      VLens    L  \c*fnto  12
%<+doc> {concave lens}
\cdefiv    HVLens   L  \c*fnto  14 {} {}
%<+doc> {half concave lens}
\cdefviii  Mirror   M  \c*fnto  85 * . {}
%<+doc> {mirror}
\cdefviii  BSplit   BS \c*fnto  36 * . +
%<+doc> {beam splitter}
\cdef      Polar    P  \c*fnto  44
%<+doc> {polarizer}
\cdef      Pinhole  {} \c*fnto  46
%<+doc> {pinhole}
\cdefiv    Cam      {} \c*fnto  66 {} {}
%<+doc> {camera}
\cdef      ScrL     {} \c*fnto  72
%<+doc> {screen, look at the left side}
\cdef      ScrR     {} \c*fnto  74
%<+doc> {screen, look at the right side}
\cdef      ScrBL    {} \c*fnto  76
%<+doc> {screen, look behind the left side}
\cdef      ScrBR    {} \c*fnto  78
%<+doc> {screen, look behind the right side}
\cdef      ScrTL    {} \c*fnto  80
%<+doc> {screen, look trough the left side}
\cdef      ScrTR    {} \c*fnto  82
%<+doc> {screen, look trough the right side}
\cdef      Laser    {} \c*fnto 160
%<+doc> {laser}
\cdef      PM       {} \c*fnto 162
%<+doc> {photometer, -multiplyer, etc.}
\bbdefNeTii  OM          \c*fnto 164  {}
%<+doc> {optical modulator}
%</optics,doc>
%<*optics>
\protectcirc
%    \end{macrocode}
%</optics>
%^^A last update: Tue  02-04-1997
%<*doc>
\protectcirc
%    \end{macrocode}
%</doc>
%<*code>
%^^A last update: Tue  02-04-1997
%
%    \begin{macrocode}
\def\line*r{\check*X\ifnum\cnta*=0\else\check*max{\dimen2}\ifxoutofgrid
  \advance\dimen2-.5\fontdimen6\c*fnt\fi
  \setbox\*bbox=\hbox{\ifxoutofgrid\else\char\cc*\fi\advance\cc*1%
                      \loop\ifnum\cnta*>1\char\cc*
                      \advance\cnta*-1\repeat}\put*box
  \advance\*X*.5\dimen2\the\toks2\advance\*X*.5\dimen2
  \advance\cc*2\setbox\*bbox=\hbox{\char\cc*}\put*box\xoutofgridfalse\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\line*l{\advance\*X*-\dimen2
            \ifxoutofgrid\advance\*X*.5\fontdimen6\c*fnt\fi
            \**X\*X*\line*r\*X*\**X}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\line*u{\check*X\ifnum\cnta*=0\else\advance\cc*4\ifyoutofgrid
  \advance\dimen2-.5\fontdimen6\c*fnt\fi
  \setbox\box*=\hbox{\char\cc*}\advance\cc*-1%
  \setbox\*bbox=\vbox{\loop\ifnum\cnta*>1\copy\box*
                      \advance\cnta*-1\repeat
                      \ifyoutofgrid\else\hbox{\char\cc*}\fi}\put*box
  \advance\*Y*.5\dimen2\the\toks4\advance\*Y*.5\dimen2
  \advance\cc*2\setbox\*bbox=\vbox{\hbox{\char\cc*}}\put*box\youtofgridfalse\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\line*d{\advance\*Y*-\dimen2
            \ifyoutofgrid\advance\*Y*.5\fontdimen6\c*fnt\fi
            \**Y\*Y*\line*u\*Y*\**Y}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\test*xygrid{\dimen9\fontdimen6\c*fnt\count@\dimen9
                \cntb*\*X*\divide\cntb*\count@
                \dimen0\*X*\advance\dimen0-\cntb*\dimen9
                \advance\dimen9-.1pt
                \ifdim\dimen0<0pt \dimen0-\dimen0 \fi
                \ifdim\dimen0>0.1pt \ifdim\dimen0<\dimen9 \xoutofgridtrue\fi\fi
                \cntb*\*Y*\divide\cntb*\count@
                \dimen0\*Y*\advance\dimen0-\cntb*\fontdimen6\c*fnt
                \ifdim\dimen0<0pt \dimen0-\dimen0 \fi
                \ifdim\dimen0>0.1pt \ifdim\dimen0<\dimen9 \youtofgridtrue\fi\fi}
%    \end{macrocode}
%
%
%    \begin{macrocode}
\def\bundle#1 #2 #3 {\cc*136\c*fnt\cnta*#2\dimen2=#2em
                     \toks2{\setbox\box*=\hbox{\char134}%
                     \setbox\*bbox=\rlap{\raise\ht\box*
                     \hc*{\labelfont#1}\unhbox\box*}\put*box}%
                     \toks4{\setbox\*bbox=\hbox{\char135\labelfont
                     \vc*{\hbox{#1}}}%
                     \check*max{\wd\*bbox}\put*box}%
                     \test*xygrid\csname line*#3\endcsname}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\wwire#1 #2 #3 {\cc*112\c*fnt\cnta*#2\dimen2=#2em
                    \toks2{\setbox\*bbox=\rlap{\raise\*spc
                    \hc*{\labelfont#1}}\put*box}%
                    \toks4{\setbox\*bbox=\hbox{\kern\*spc\labelfont
                    \vc*{\hbox{#1}}}%
                    \check*max{\wd\*bbox}\put*box}%
                    \test*xygrid\csname line*#3\endcsname}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\by#1 {\def\by*cmd{#1}}
\by{\wire}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\calc*u{\cnta*\fontdimen6\c*fnt\advance\dimen0 .5\fontdimen6\c*fnt
            \cntb*\dimen0\divide\cntb*\cnta*}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\vtopin#1 {\save*XY\frompin{#1} \test*xygrid
               \dimen0\**Y\advance\dimen0-\*Y*\restore*XY
               \ifdim\dimen0<0pt\dimen0-\dimen0
               \calc*u\by*cmd {\cntb*} u
               \else\calc*u\by*cmd {\cntb*} d \fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\htopin#1 {\save*XY\frompin{#1} \test*xygrid
               \dimen0\**X\advance\dimen0-\*X*\restore*XY
               \ifdim\dimen0<0pt\dimen0-\dimen0
               \calc*u\by*cmd {\cntb*} r
               \else\calc*u\by*cmd {\cntb*} l \fi}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\Utext #1 from #2 to #3 {{%
  \frompin{#2} \save*XY\frompin{#3} \diff*XY
    \ifdim\**X=0pt
      \setbox1=\hbox{\c*fnt\char132}%
      \ifdim\**Y<0pt
        \dimen0-\**Y
        \setbox0=\hbox{\c*fnt\char'373}\advance\dimen0-\ht0\dp0=0pt
        \calc*u
        \setbox\*bbox=
          \vtop to -\**Y{\vfill\box0\loop\ifnum\cntb*>2\copy1
            \advance\cntb*-1\repeat\vfill}%
      \else
        \dimen0\**Y
        \setbox0=\hbox{\c*fnt\char'371}\advance\dimen0-\ht0\dp0=0pt
        \calc*u
        \setbox\*bbox=
          \vbox to \**Y{\vfill\loop\ifnum\cntb*>2\copy1
            \advance\cntb*-1\repeat\box0\vfill}%
      \fi
      \put*box\advance\*X*\*spc\advance\*Y*.5\**Y\text\vc*{\hbox{#1}}
    \else
    \ifdim\**Y=0pt
      \ifdim\**X<0pt
        \dimen0-\**X
        \setbox0=\hbox{\c*fnt\char'372}\advance\dimen0-\wd0
        \calc*u
        \setbox\*bbox=\llap{\hbox to -\**X{\hfill\loop\ifnum\cntb*>2\char129
          \advance\cntb*-1\repeat\box0\hfill}}%
      \else
        \dimen0\**X
        \setbox0=\hbox{\c*fnt\char'370}\advance\dimen0-\wd0
        \calc*u
        \setbox\*bbox=\hbox to \**X{\hfill\box0\loop\ifnum\cntb*>2\char129
          \advance\cntb*-1\repeat\hfill}%
      \fi
      \put*box\advance\*X*.5\**X\advance\*Y*\*spc\text\hc*{#1}
    \else\errhelp{Only horizontal or vertical labeling allowed.}%
    \errmessage{Bad points!}\fi\fi}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\centertext #1 from #2 to #3 {%
  {\frompin{#2} \save*XY\frompin{#3} \diff*XY
    \ifdim\**X=0pt
      \advance\*Y*.5\**Y\text\vc*{\hbox{#1}}
    \else
    \ifdim\**Y=0pt
      \advance\*X*.5\**X\text\hc*{#1}
    \else\errhelp{Only horizontal or vertical labeling allowed.}%
    \errmessage{Bad points}\fi\fi}}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
% Die absolute Positionierung in einem Raster von 7\,pt wird durch
% das direkte Setzen der aktuellen Zeichenposition realisiert.
% Die x-, und y-Position bezieht sich dabei auf den Punkt der
% ersten Zeichenoperation, dem die Werte $(0,0)$ zugeordnet wurden.
%    \begin{macrocode}
\def\from#1 #2 {\c*fnt\*X*=#1em\*Y*=#2em\check*X}
\let\at\from
%    \end{macrocode}
%
%    \begin{macrocode}
\def\moverel#1 #2 {\c*fnt\advance\*X* #1em\advance\*Y* #2em\check*X}
\let\shift\moverel
%    \begin{macrocode}
%
%    \begin{macrocode}
\def\text*circ#1 {\setbox\*bbox=\hbox{\ctextfont#1}\check*X\check*max{\wd\*bbox}%
            \put*box}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\nl{\lab*false}
\def\nv{\val*false}
\def\cc{\cc*true}
\def\clr*acmds{\global\let\add*cmds\relax}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%    \begin{macrocode}
\def\*fdef#1 {\expandafter\xdef\csname#1\endcsname{\the\toks0}}
%    \end{macrocode}
%
%    \begin{macrocode}
\let\extracircinit\relax
\let\opticfontinit\relax
%    \end{macrocode}
%
%    \begin{macrocode}
\def\circuit#1 {\let\add*cmds\relax
    \*Ilist{}\*Olist{}\check*true
    \xdef\*mag{\magstep{#1}}%
    \global\X*max-\maxdimen
    \global\X*min\maxdimen
\ifcase#1 % magstep 0
    \toks0={\normalsize\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\normalsize\sf}%
    \*fdef symfont
    \toks0={\scriptsize\rm}%
    \*fdef pinnumberfont
    \*fdef functionfont
    \toks0={\footnotesize\rm}%
    \*fdef circlabelfont
    \toks0={\footnotesize\sf}%
    \*fdef inlabelfont
\or       % magstep 1
    \toks0={\large\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\large\sf}%
    \*fdef symfont
    \toks0={\footnotesize\rm}%
    \*fdef pinnumberfont
    \toks0={\small\rm}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\small\sf}%
    \*fdef inlabelfont
\or       % magstep 2
    \toks0={\Large\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\Large\sf}%
    \*fdef symfont
    \toks0={\small\rm}%
    \*fdef pinnumberfont
    \toks0={\normalsize\rm}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\normalsize\sf}%
    \*fdef inlabelfont
\or       % magstep 3
    \toks0={\LARGE\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\LARGE\sf}%
    \*fdef symfont
    \toks0={\normalsize\rm}%
    \*fdef pinnumberfont
    \toks0={\large\rm}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\large\sf}%
    \*fdef inlabelfont
\or       % magstep 4
    \toks0={\huge\rm}%
    \*fdef outlabelfont
    \*fdef labelfont
    \*fdef ctextfont
    \toks0={\huge\sf}%
    \*fdef symfont
    \toks0={\large\rm}%
    \*fdef pinnumberfont
    \toks0={\Large\rm}%
    \*fdef functionfont
    \*fdef circlabelfont
    \toks0={\sf\Large}%
    \*fdef inlabelfont
\else\errhelp{0 ... 4 expected.}\errmessage{Bad magnification!}\fi
%
{\outlabelfont
\global\*spc 0.4em}%
%
\font\c*fnt=csyrest      scaled \*mag
\font\c*fntb=csycirc     scaled \*mag
\font\c*fntd=csydiod     scaled \*mag
\font\c*fntt=csybimos    scaled \*mag
\font\c*fntw=csywidko    scaled \*mag
\font\c*fnts=csysym      scaled \*mag
%
\outerspace1mm
\pinnum*spc.7mm
\pin*ind\fontdimen12\c*fntb
\pin*spc\fontdimen13\c*fntb
\io*ind\fontdimen14\c*fntb
\mid*ind\fontdimen16\c*fntb
\X*min\maxdimen
\X*max-\maxdimen
%
\extracircinit
\opticfontinit
\begingroup
%
  \def\P##1 {\store*XY{P##1}\check*X\reset*ifs}
  \let\.\junction
  \let\put\text*circ
  \let\text\text*circ
  \def\- ##1 ##2 {\wire##1 ##2 }%
  \def\= ##1 ##2 ##3 {\bundle##1 ##2 ##3 }%
  \def\<{\ld*true}%
%
\parindent0pt
\offinterlineskip\setbox\*bbox=\hbox\bgroup\at 0 0 }
%    \end{macrocode}
%
%    \begin{macrocode}
\def\endcircuit{\egroup\hbox{\kern-\X*min\unhbox\*bbox\kern\X*max}\endgroup}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
%
\def\fallingEdge{{\c*fnts\char3}}
\def\raisingEdge{{\c*fnts\char2}}
\def\spike{{\c*fnts\char4}}
\def\ispike{{\c*fnts\char12}}
\def\squarePulse{{\c*fnts\char1}}
\def\squarePulses{{\c*fnts\char5}}
\def\sawtoothPuls{{\c*fnt\char6}}
%
%^^A last update: Tue  02-04-1997
% The last thing we define is the logo of CIRC.
% This pretty small grey elephant was choosen and then digitized as a
% result of a discussion about the incomming of new symbols into
% CIRC. Idea by Andreas Tille.
%    \begin{macrocode}
\def\CIRCLogo {\setbox\*bbox=\hbox{\symfont
  \raise1.5ex\rlap{\kern1ex CIRC}\c*fnt\char252}%
  \check*max{\wd\*bbox}\put*box\reset*ifs}
%    \end{macrocode}
%^^A last update: Tue  02-04-1997
% Alle internen Buchstaben werden wieder auf ihren vormaligen
% Kategoriekode gesetzt.
%    \begin{macrocode}
\protectcirc
%    \end{macrocode}
% Now we are ready to process all options of CIRC.
% That means to load all modules.
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%</code>
%^^A last update: Tue  02-04-1997
%<*ic>
%    \begin{macrocode}
\ProvidesFile{ic.def}
%    \end{macrocode}
%    \begin{macrocode}
\freecirc
%    \end{macrocode}
%
%    \begin{macrocode}
\def\**[#1 #2 #3 #4 {\cc*\cnta*\advance\cc*32 \advance\cc*#1
  \Cstore*\*Ilist{#2}\Cadd*\*Ilist
  \rlap{\kern\pin*ind\ifpin\raise\pinnum*spc\hc*{\pinnumberfont{#3}}\fi
  \kern\io*ind\c*fntb\vc*{\hc*{\inlabelfont{#4}}}}\char\cc*
  \cc*\cnta*\advance\cc*97\char\cc*}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\**]#1 #2 #3 #4 {\cc*\cnta*\advance\cc*48 \advance\cc*#1
  \Cstore*\*Olist{#2}\Cadd*\*Olist
  \rlap{\kern.5\mid*ind\vc*{\hc*{\inlabelfont{#3}}}\kern\io*ind
  \ifpin\raise\pinnum*spc\hc*{\pinnumberfont{#4}}\fi}\char\cc*}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\*F[#1 #2 #3 #4 #5 {\cc*\cnta*\advance\cc*#1
  \X*check\Cstore*\*Ilist{#2}\Cadd*\*Ilist
  \rlap{\kern\pin*ind\ifpin\raise\pinnum*spc\hc*{\pinnumberfont{#3}}\fi
  \kern\io*ind\c*fntb\vc*{\hc*{\inlabelfont{#4}}}}%
  \rlap{\kern\io*ind\kern\mid*ind
  \blap{\kern0pt\hc*{\functionfont{#5}}}}\char\cc*
  \cc*\cnta*\advance\cc*96\char\cc*}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\*F]#1 #2 #3 #4 {\cc*\cnta*\advance\cc*16 \advance\cc*#1
  \LX*check\*Olist\Cstore*\*Olist{#2}\Cadd*\*Olist
  \rlap{\kern.5\mid*ind\vc*{\hc*{\inlabelfont{#3}}}\kern\io*ind
  \ifpin\raise\pinnum*spc\hc*{\pinnumberfont{#4}}\fi}\char\cc*}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\*L[#1 #2 #3 #4 #5 {\cc*\cnta*\advance\cc*64 \advance\cc*#1
  \Cstore*\*Ilist{#2}\Cadd*\*Ilist
  \rlap{\kern\pin*ind\ifpin\raise\pinnum*spc\hc*{\pinnumberfont{#3}}\fi
  \kern\io*ind\c*fntb\vc*{\hc*{\inlabelfont{#4}}}}%
  \rlap{\iflab*\kern\io*ind\kern\mid*ind
  \vtop{\kern\fontdimen17\c*fntb\kern\outerspace
  \hc*{\circlabelfont{#5}}}\fi}\char\cc*
  \cc*\cnta*\advance\cc*98\char\cc*}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\*L]#1 #2 #3 #4 {\cc*\cnta*\advance\cc*80 \advance\cc*#1
  \Cstore*\*Olist{#2}\Cadd*\*Olist
  \rlap{\kern.5\mid*ind\vc*{\hc*{\inlabelfont{#3}}}\kern\io*ind
  \ifpin\raise\pinnum*spc\hc*{\pinnumberfont{#4}}\fi}\char\cc*}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\C*init{\dimen4\*X*\dimen5\*Y*
  \setbox\*bbox=\vtop\bgroup\c*fntb\cnta*=0 \ignorespaces}
%    \end{macrocode}
%
%
%    \begin{macrocode}
\def\C*exit#1{\egroup\shift*IOlist{#1}\put*box\*X*\dimen4\*Y*\dimen5}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\*o#1{$\overline{\hbox{#1}}$}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\*|#1| {\hbox{#1}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\JKMSFF#1 #2 #3 #4 {\name*{JKMSFF#1}\C*init
\*|\*F[2  S   {}   S   {}     \*F]0  .  {}      {} |
\*|\**[1  J   {}   1J         \**]1  Q  $\neg$  {} |
\*|\**[3  C   {}   C1         \**]0  .  {}      {} |
\*|\**[1  K   {}   1K         \**]2  NQ $\neg$  {} |
\*|\*L[2  R   {}   R   {#2}   \*L]0  .  {}      {} |
\C*exit{#3}}
%    \end{macrocode}
%    \begin{macrocode}
\def\DFF#1 #2 #3 #4 {\name*{DFF#1}\C*init
\*|\*F[1  D   {}   1D  {}     \*F]1  Q  {}      {} |
\*|\**[0  .   {}   {}         \**]0  .  {}      {} |
\*|\*L[3  C   {}   C1  {#2}   \*L]2  NQ {}      {} |
\C*exit{#3}}
%    \end{macrocode}
%    \begin{macrocode}
\def\RSFF#1 #2 #3 #4 {\name*{RSFF#1}\C*init
\*|\*F[1  R   {}   R   {}     \*F]1  Q  {}      {} |
\*|\**[0  .   {}   {}         \**]0  .  {}      {} |
\*|\*L[1  S   {}   S  {#2}    \*L]2  NQ {}      {} |
\C*exit{#3}}
%    \end{macrocode}
%    \begin{macrocode}
\def\NRSFF#1 #2 #3 #4 {\name*{NRSFF#1}\C*init
\*|\*F[2  R   {}   R   {}     \*F]1  Q  {}      {} |
\*|\**[0  .   {}   {}         \**]0  .  {}      {} |
\*|\*L[2  S   {}   S  {#2}    \*L]2  NQ {}      {} |
\C*exit{#3}}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\fff#1 #2 #3 #4 {\name*{fff#1}\C*init
\*|\*F[1  IS  {6}  IS   {         }     \*F]1  OK  OK 5  |
\*|\**[0  .   {}   {}                   \**]0  .   {} {} |
\*|\**[1  IT  {2}  IT                   \**]1  O   O  3  |
\*|\**[0  .   {}   {}                   \**]0  .   {} {} |
\*|\*L[2  R   {4}  R    {#2}            \*L]1  OD  OD 7  |
\C*exit{#3}}
%    \end{macrocode}
%    \begin{macrocode}
\protectcirc
%    \end{macrocode}
%</ic>
%^^A last update: Tue  02-04-1997
%
%<*csydiod>
input csym;
designsize:=1lLE#;

def diode =  % "uberarbeiten
  numeric pl;
  pl:=.5(did_lt-did_wd);
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z1+(did_wd,0);
  z3=z2+(pl,0);
  z4-z5=z6-z7=(0,did_ht);
  z1=.5[z4,z5];
  z2=.5[z6,z7];
  z8=z4+(did_zlt,0);
  z9=z0+(0,thy_ht);

  z10=.35[z5,z7];
  z11=z10-(.5Dcap_spc,0);
  z12=z10+(.5Dcap_spc,0);
  y13=y15; y14=y16;
  x13=x14; x15=x16;
  y13-y14=Dcap_ht;
  z11=.5[z13,z14];
  z12=.5[z15,z16];
  z17=z11-(Dcap_wd,0);
  z18=z12+(Dcap_wd,0);


  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z2--z3;
  draw z4--z5;
  draw  z1--z6--z7--cycle;
enddef;

def Dcap =
  pickup pensquare scaled normalline;
  draw z17--z11;
  draw z13--z14;
  draw z15--z16;
  draw z12--z18;
enddef;

def led_arrows =  % "uberarbeiten
  numeric pl;
  numeric x[],y[];
  transform arr_a,arr_b;
  pickup pencircle scaled thinline;
  pl:=.5(did_lt-did_wd);
  z0=(0,0);
  z4=z0+(pl,0);
  z1=z0+(led_lt,0);
  (z1-z2)=(led_wd,0) rotated led_phi;
  (z1-z3)=(led_wd,0) rotated -led_phi;
  arr_a:=identity rotated led_psi shifted (z4+(led_spx,led_spy));
  arr_b:=identity rotated led_psi shifted (z4+(led_spx,led_spy+led_spc));
  draw (z0--z1) transformed arr_a;
  draw (z0--z1) transformed arr_b;
  draw (z2--z1) transformed arr_a;
  draw (z2--z1) transformed arr_b;
  draw (z3--z1) transformed arr_a;
  draw (z3--z1) transformed arr_b;
enddef;

"Diode";
fourchars(0)(diode)(z3)(.5did_ht#,did_lt#,.5did_ht#);

"Z-Diode";
fourchars(4)(diode; draw z4--z8)(z3)(.5did_ht#,did_lt#,.5did_ht#);

"LED";
fourfourchars(8)(diode; led_arrows)(z3)(1.2did_ht#,did_lt#,.5did_ht#);

"Kapazit"&ditto&"atsdiode";
fourchars(16)(diode; Dcap)(z3)(.5did_ht#,did_lt#,.65did_ht#);


"Thyristor";
%fourchars(128)(diode; draw z1--z9)(z3)(thy_ht#,did_lt#,.5did_ht#);

end;
%</csydiod>
%
%^^A last update: Tue  02-04-1997
%
%<*csycirc>
input csym;

designsize:=2lLE#;

fontdimen10: .4gat_ht#;
fontdimen11: .65gat_lt#;

fontdimen12: .5pin_lt#;
fontdimen13:  pin_spc#;
fontdimen14: .5ios_wd#+.5pin_lt#;
fontdimen15:  mid_wd#+ios_wd#;
fontdimen16:  ios_wd#;
fontdimen17:  out_spc#;

%fontdimen7:  .4gat_ht#;
%fontdimen8:  .5pin_lt#;
%fontdimen9:  .5(pin_lt#+ios_wd#);
%fontdimen10: .5mid_wd#;
%fontdimen11: .5ios_wd#;
%fontdimen16: pin_spc#;

def defcircleabout(expr p, rad)=
  z[p]=.5[z[p+1],z[p+3]]=.5[z[p+2],z[p+4]];
  y[p+1]=y[p+3];
  x[p+2]=x[p+4];
  x[p]=lft(x[p+1])-rad;
  y[p]=top(y[p+4])+rad;
enddef;

def gate=
  charic:=.5pin_spc#;
  z0=(0,0);
  x20=x15=x1=x6=x7=  x0+pin_lt;
  y8=y6=-y7=         y0+.5gat_ht;
  x8=x9=x10=         x1+gat_lt-2pin_lt;
  y15=-y20=          y0+.5pin_spc;
  x25-x0=            gat_lt;

  y9=y7; y25=y10=y1=y0;
  x0=x26=x27;
  y26=y15; y27=y20;

  pickup pencircle scaled thickline;
  defcircleabout(1,inv_rad);
  defcircleabout(10,inv_rad);
  defcircleabout(15,inv_rad);
  defcircleabout(20,inv_rad);
enddef;

def segment =
  z0=(0,0);
  x1-x0=pin_lt; y0=y1;
  defcircleabout(1,inv_rad); % z2 z3 z4 z5 defined
  z1=.5[z6,z7]; x6=x7=x8;
  y7-y6=pin_spc;
  y8-y1=out_spc;
  x9-x8=ios_wd; y8=y9;
enddef;


def topbotsegs(expr fc, myht, mydp) =
  beginchar(fc+0,pin_lt#+ios_wd#,myht,mydp);
    pickup pensquare scaled thickline;
    segment
    draw z6--z8--z9;
  endchar;
  beginchar(fc+1,pin_lt#+ios_wd#,myht,mydp);
    pickup pensquare scaled thickline;
    segment
    draw z6--z8--z9;
    pickup pensquare scaled normalline;
    draw z0--z1;
  endchar;
  beginchar(fc+2,pin_lt#+ios_wd#,myht,mydp);
    pickup pensquare scaled thickline;
    segment
    draw z6--z5;
    draw z3--z8--z9;
    pickup pencircle scaled normalline;
    draw fullcircle scaled 2inv_rad shifted z1;
    pickup pensquare scaled normalline;
    draw z0--z4;
  endchar;
  beginchar(fc+3,pin_lt#+ios_wd#,myht,mydp);
    pickup pensquare scaled thickline;
    segment
    draw z6--z8--z9;
    pickup pensquare scaled normalline;
    draw z0--z1;
    pickup pencircle scaled normalline;
    draw z3--z2--z5;
  endchar;
enddef;

def midsegs(expr fc, myht, mydp) =
  beginchar(fc+0,pin_lt#+ios_wd#,myht,mydp);
    pickup pensquare scaled thickline;
    segment
    draw z6--z8;
  endchar;
  beginchar(fc+1,pin_lt#+ios_wd#,myht,mydp);
    pickup pensquare scaled thickline;
    segment
    draw z6--z8;
    pickup pensquare scaled normalline;
    draw z0--z1;
  endchar;
  beginchar(fc+2,pin_lt#+ios_wd#,myht,mydp);
    pickup pensquare scaled thickline;
    segment
    draw z6--z5;
    draw z3--z8;
    pickup pencircle scaled thickline;
    draw fullcircle scaled 2inv_rad shifted z1;
    pickup pensquare scaled normalline;
    draw z0--z4;
  endchar;
  beginchar(fc+3,pin_lt#+ios_wd#,myht,mydp);
    pickup pensquare scaled thickline;
    segment
    draw z6--z8;
    pickup pensquare scaled normalline;
    draw z0--z1;
    pickup pencircle scaled normalline;
    draw z3--z2--z5;
  endchar;
enddef;


"obere Segmente Eing"&ditto&"ange";
topbotsegs(0,out_spc#,.5pin_spc#);

"obere Segmente Ausg"&ditto&"ange";
{{
  addTF(reflectedabout((.5(ios_wd+pin_lt),0),(.5(ios_wd+pin_lt),1)));
  topbotsegs(16,out_spc#,.5pin_spc#);
}}

"mittlere Segmente Eing"&ditto&"ange";
midsegs(32,.5pin_spc#,.5pin_spc#);

"mittlere Segmente Eing"&ditto&"ange";
{{
  addTF(reflectedabout((.5(ios_wd+pin_lt),0),(.5(ios_wd+pin_lt),1)));
  midsegs(48,.5pin_spc#,.5pin_spc#);
}}

"untere Segmente Eing"&ditto&"ange";
{{
  addTF(reflectedabout(left,right));
  topbotsegs(64,.5pin_spc#,out_spc#);
}}

"untere Segmente Ausg"&ditto&"ange";
{{
  addTF(reflectedabout(left,right));
  addTF(reflectedabout((.5(ios_wd+pin_lt),0),(.5(ios_wd+pin_lt),1)));
  topbotsegs(80,.5pin_spc#,out_spc#);
}}

"oberes Zwischensegment";
beginchar(96,mid_wd#,out_spc#,.5pin_spc#);
  pickup pensquare scaled thickline;
  draw (0,out_spc)--(mid_wd,out_spc);
endchar;

"Zwischensegment";
beginchar(97,mid_wd#,.5pin_spc#,.5pin_spc#);
endchar;

"unteres Zwischensegment";
beginchar(98,mid_wd#,.5pin_spc#,out_spc#);
  pickup pensquare scaled thickline;
  draw (0,-out_spc)--(mid_wd,-out_spc);
endchar;


"Gatter: Eingang, Ausgang";
beginchar(128,gat_lt#,.5gat_ht#,.5gat_ht#);
  gate;
  pickup pensquare scaled thickline;
  draw z6--z8--z9--z7--cycle;
  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z10--z25;
endchar;

"Gatter: Eingang negiert, Ausgang";
beginchar(129,gat_lt#,.5gat_ht#,.5gat_ht#);
  gate;
  pickup pensquare scaled thickline;
  draw z3--z6--z8--z9--z7--z5;
  pickup pencircle scaled thickline;
  draw fullcircle scaled 2inv_rad shifted z1;
  pickup pensquare scaled normalline;
  draw z0--z4;
  draw z10--z25;
endchar;

"Gatter: Eingang, Ausgang negiert";
beginchar(130,gat_lt#,.5gat_ht#,.5gat_ht#);
  gate;
  pickup pensquare scaled thickline;
  draw z14--z9--z7--z6--z8--z12;
  pickup pencircle scaled thickline;
  draw fullcircle scaled 2inv_rad shifted z10;
  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z11--z25;
endchar;

"Gatter: zwei Eing"&ditto&"ange, Ausgang";
beginchar(131,gat_lt#,.5gat_ht#,.5gat_ht#);
  gate;
  pickup pensquare scaled thickline;
  draw z6--z8--z9--z7--cycle;
  pickup pensquare scaled normalline;
  draw z15--z26;
  draw z20--z27;
  draw z10--z25;
endchar;

"Gatter: zwei Eing"&ditto&"ange, Ausgang negiert";
beginchar(132,gat_lt#,.5gat_ht#,.5gat_ht#);
  gate;
  pickup pensquare scaled thickline;
  draw z14--z9--z7--z6--z8--z12;
  pickup pencircle scaled thickline;
  draw fullcircle scaled 2inv_rad shifted z10;
  pickup pensquare scaled normalline;
  draw z15--z26;
  draw z20--z27;
  draw z11--z25;
endchar;

"box symbol empty";
beginchar(250,box_wd#,.5box_wd#,.5box_wd#);
  z0=(0,0);
  x0=x1=x2; x3=x4;
  y0=.5[y2,y1];
  y1=y3; y2=y4;
  y2-y1=x3-x1=box_wd;
  pickup pensquare scaled thickline;
  draw z1--z2--z4--z3--cycle;
endchar;

"box symbol cutted by line";
beginchar(251,box_wd#,.5box_wd#,.5box_wd#);
  z0=(0,0);
  x0=x1=x2; x3=x4;
  y0=.5[y2,y1];
  y1=y3; y2=y4;
  y2-y1=x3-x1=box_wd;
  pickup pensquare scaled thickline;
  draw z1--z2--z4--z3--cycle;
  pickup pencircle scaled normalline;
  draw z1--z4;
endchar;

"Black Box analog";
beginchar(252,bba_wd#,.5bba_ht#,.5bba_ht#);
  z0=(0,0); x1=x0=x2;
  z0=.5[z1,z2];
  y1-y2=y3-y4=bba_ht;  y1=y3;
  x3=x4=x0+bba_wd;
  pickup pensquare scaled thickline;
  draw z1--z2--z4--z3--cycle;
endchar;

"Black Box digital";
beginchar(253,bbd_wd#,.5bbd_ht#,.5bbd_ht#);
  z0=(0,0); x1=x0=x2;
  z0=.5[z1,z2];
  y1-y2=y3-y4=bbd_ht;  y1=y3;
  x3=x4=x0+bbd_wd;
  pickup pensquare scaled thickline;
  draw z1--z2--z4--z3--cycle;
endchar;

"OPV";
beginchar(254,opv_lt#,opv_ht#,opv_ht#);
  charic:=opv_dis#;
  numeric pl;
  pl:=pin_lt;
  z0=(0,0);
  z1=z0+(pl,opv_dis);
  z2=z0+(pl,opv_ht);
  z3=z0+(pl+opv_frc*2opv_ht,0);
  x4=x2; y4=-y2;
  x5=x1; y5=-y1;
  z6=z1-(pl,0);
  z7=z5-(pl,0);
  z8=z0+(opv_lt,0);
  z9=z5+(3pt,0);
  z10=z9+(4pt,0);
  z11=z1+(3pt,0);
  z12=z11+(4pt,0);
  z13=z11+(2pt,2pt);
  z14=z11+(2pt,-2pt);
  pickup pensquare scaled thickline;
  draw z2--z3--z4--cycle;
  pickup pensquare scaled normalline;
  draw z9--z10;
  draw z11--z12;
  draw z13--z14;
  draw z6--z1;
  draw z7--z5;
  draw z3--z8;
endchar;

"OPV";
beginchar(255,opv_lt#,opv_ht#,opv_ht#);
  charic:=opv_dis#;
  numeric pl;
  pl:=pin_lt;
  z0=(0,0);
  z1=z0+(pl,opv_dis);
  z2=z0+(pl,opv_ht);
  z3=z0+(pl+opv_frc*2opv_ht,0);
  x4=x2; y4=-y2;
  x5=x1; y5=-y1;
  z6=z1-(pl,0);
  z7=z5-(pl,0);
  z8=z0+(opv_lt,0);
  z9=z1+(3pt,0);
  z10=z9+(4pt,0);
  z11=z5+(3pt,0);
  z12=z11+(4pt,0);
  z13=z11+(2pt,2pt);
  z14=z11+(2pt,-2pt);
  pickup pensquare scaled thickline;
  draw z2--z3--z4--cycle;
  pickup pensquare scaled normalline;
  draw z9--z10;
  draw z11--z12;
  draw z13--z14;
  draw z6--z1;
  draw z7--z5;
  draw z3--z8;
endchar;

end;
%</csycirc>
%
%^^A last update: Tue  02-04-1997
%<*optic>
input csym;

% half of linelength of optical axis
hsoa:=.128lLE;

% lenses
% thin convex lens 
slens_ht#   :=   2lLE#;
slens_lt#   :=   2lLE#;
slens_phi   :=   60;
% lensthickness:
slens_spc   :=   .55lLE; 
define_pixels(slens_lt,slens_ht);

% thick convex lens
blens_ht#   :=   2lLE#;
blens_lt#   :=   2lLE#;
blens_phi   :=   45;
blens_spc   :=   .88lLE;
define_pixels(blens_lt,blens_ht);

% thin concave lens
sklens_ht#  :=   2lLE#;
sklens_lt#  :=   2lLE#;
sklens_phi  :=   60;
sklens_spc  :=   .58lLE;
sklens_bt   :=   1lLE;     % Breite Bottom und Top
define_pixels(sklens_lt,sklens_ht);

% mirror
mir_ht#     :=  2lLE#;
mir_lt#     :=  2lLE#;
mir_wd      :=  .5lLE;    % Schraffurl"ange
define_pixels(mir_ht,mir_lt);

% boxes for optical modulator and laser
omb_wd# := 3lLE#;
omb_ht# := 2lLE#;
lab_wd# := 4lLE#;
lab_ht# := 2lLE#;
define_pixels(omb_wd,omb_ht,lab_wd,lab_ht);

% polarizer
pol_ht#  :=  2lLE#;
pol_lt#  :=  2lLE#;
pol_spc  := .2lLE;
define_pixels(pol_ht,pol_lt);

% pinhole
pin_ht#  :=  2lLE#;
pin_lt#  :=  2lLE#;
pin_spx  := .16lLE;
pin_spy  := .08lLE;
pin_spz  := .5lLE;
define_pixels(pin_ht,pin_lt);

% camera
cam_ht#  := 2lLE#;
cam_lt#  := 3lLE#;
cam_spx  := 2lLE;
cam_spy  := 1lLE;
define_pixels(cam_ht,cam_lt);

% screen
scr_ht#  := 4lLE#;
scr_lt#  := 2lLE#;
scr_spx  := 1lLE;
scr_spy  := 1lLE;
define_pixels(scr_ht,scr_lt);

def rectangle(expr width, height, xs, ys) =
  draw (xs,.5height+ys)--(width+xs,.5height+ys)--(width+xs,-.5height+ys)--
       (xs,-.5height+ys)--cycle;
enddef;

def small_lens =
  pickup pensquare scaled normalline;
  numeric pl;
  pl:=.5(slens_lt-slens_spc);
  z0=(.5slens_lt,-.5slens_ht);
  z1=(.5slens_lt,.5slens_ht);
  z2=(.5lLE,0); z3=z2+(hsoa,0);
  z4=(slens_lt-.5lLE,0); z5=z4-(hsoa,0);
  draw z0{dir slens_phi}..z1;
  draw z0{dir (180-slens_phi)}..z1;
  opticalaxis(normalline)(0);
  opticalaxis(normalline)(1lLE);
enddef;

def half_small_lens =
  pickup pensquare scaled normalline;
  numeric pl;
  pl:=.5(slens_lt-slens_spc);
  z0=(.5slens_lt,-.5slens_ht);
  z1=(.5slens_lt,.5slens_ht);
  z4=(slens_lt-.5lLE,0); z5=z4-(hsoa,0);
  draw z0{dir slens_phi}..z1;
  draw z1--z0;
  opticalaxis(normalline)(0);
  opticalaxis(normalline)(1lLE);
enddef;

def bold_lens =
  pickup pensquare scaled normalline;
  numeric pl;
  pl:=.5(blens_lt-blens_spc);
  z0=(.5blens_lt,-.5blens_ht);
  z1=(.5blens_lt,.5blens_ht);
  draw z0{dir blens_phi}..z1;
  draw z0{dir (180-blens_phi)}..z1;
  opticalaxis(normalline)(0);
  opticalaxis(normalline)(1lLE);
enddef;

def half_bold_lens =
  pickup pensquare scaled normalline;
  numeric pl;
  pl:=.5(blens_lt-blens_spc);
  z0=(.5blens_lt,-.5blens_ht);
  z1=(.5blens_lt,.5blens_ht);
  draw z0{dir blens_phi}..z1;
  draw z1--z0;
  opticalaxis(normalline)(0);
  opticalaxis(normalline)(1lLE);
enddef;

def small_konkav_lens =
  pickup pensquare scaled normalline;
  numeric pl, ql;
  pl:=.5(sklens_lt-sklens_spc);
  ql:=.5(sklens_lt-sklens_bt);
  z0=(ql,-.5sklens_ht);
  z1=(sklens_lt-ql,-.5sklens_ht);
  z2=(ql,.5sklens_ht);
  z3=(sklens_lt-ql,.5sklens_ht);
  z4=(.5lLE,0); z5=z4+(hsoa,0);
  z6=(sklens_lt-.5lLE,0); z7=z6-(hsoa,0);
  draw z0{dir sklens_phi}..z2--z3{dir (180+sklens_phi)}..z1--z0;
  draw z4--z5; draw z6--z7;
  opticalaxis(normalline)(0);
  opticalaxis(normalline)(1lLE);
enddef;

def half_small_konkav_lens =
  pickup pensquare scaled normalline;
  numeric pl, ql;
  pl:=.5(sklens_lt-sklens_spc);
  ql:=.5(sklens_lt+sklens_bt);
  z0=(.5sklens_lt,-.5sklens_ht);
  z1=(ql,-.5sklens_ht);
  z2=(.5sklens_lt,.5sklens_ht);
  z3=(ql,.5sklens_ht);
  draw z0--z2--z3{dir (180+sklens_phi)}..z1--z0;
  opticalaxis(normalline)(0);
  opticalaxis(normalline)(1lLE);
enddef;

def mirror =
  pickup pensquare scaled normalline;
  opticalaxis(normalline)(0);
  opticalaxisdown(normalline)(.5mir_lt,0);
  halfmirror;
  pickup pensquare scaled thinline;
  for i=.125 step .125 until .875:
     draw (i*mir_lt,(.5-i)*mir_ht)--(mir_wd+i*mir_lt,mir_wd+(.5-i)*mir_ht);
  endfor
enddef;
  
def halfmirror =
  pickup pensquare scaled thickline;
  draw (.5mir_wd,.5(mir_ht-mir_wd))--(mir_lt-.5mir_wd,.5(mir_wd-mir_ht));
enddef;

def halfmirrorline =
  pickup pensquare scaled normalline;
  opticalaxis(normalline)(0);
  opticalaxisdown(normalline)(.5mir_lt,.5mir_ht);
  opticalaxisdown(normalline)(.5mir_lt,0);
enddef;

def polarizer =
  pickup pensquare scaled thinline;
  numeric pl;
  pl:=.5(pol_lt-pol_spc);
  z0=(pl,.5pol_ht);
  z1=z0+(0,-pol_ht);
  z2=z1+(pol_spc,0);
  z3=z0+(pol_spc,0);
  draw z0--z1--z2--z3--cycle;
  % optical axis
  opticalaxis(normalline)(0);
  opticalaxis(normalline)(1lLE);
enddef;

def pinhole =
  pickup pensquare scaled thinline;
  numeric pl;
  pl:=.5(pin_lt-pin_spx);
  fill (.5pin_lt,.5pin_spy)--(pl,.5pin_spz)--(pl,.5pin_ht)--
       (pl+pin_spx,.5pin_ht)--(pl+pin_spx,.5pin_spz)--cycle;
  fill (.5pin_lt,-.5pin_spy)--(pl,-.5pin_spz)--(pl,-.5pin_ht)--
       (pl+pin_spx,-.5pin_ht)--(pl+pin_spx,-.5pin_spz)--cycle;
  % optical axis
  opticalaxis(normalline)(0);
  opticalaxis(normalline)(1lLE);
enddef;

def screenleft (expr gray) =
  pickup pensquare scaled normalline;
  path a, b;
  numeric pl;
  pl:=.5(scr_lt-scr_spx);
  z0=(pl,.5scr_ht);
  z1=(pl+scr_spx,scr_spy);
  z2=(pl+scr_spx,-.5scr_ht);
  z3=(pl,-scr_spy);
  draw z0--z1--z2--z3--cycle;
  a:=z0--z1;
  b:=z2--z3;
  vshade(b, a, gray, unitsquare);
enddef;

def screenright (expr gray) =
  pickup pensquare scaled normalline;
  path a, b;
  numeric pl;
  pl:=.5(scr_lt-scr_spx);
  z0=(pl,-.5scr_ht);
  z1=(pl,scr_spy);
  z2=(pl+scr_spx,.5scr_ht);
  z3=(pl+scr_spx,-scr_spy);
  draw z0--z1--z2--z3--cycle;
  a:=z1--z2;
  b:=z3--z0;
  vshade(b, a, gray, unitsquare);
enddef;

% optical Axis as dashed line
def opticalaxis(expr linethickness)(expr offset) =
  pickup pensquare scaled linethickness;
  draw (offset,0)--(offset+hsoa,0);
  draw (offset+3hsoa,0)--(offset+5hsoa,0);
  draw (offset+7hsoa,0)--(offset+1lLE,0);
enddef;

% half optical Axis as dashed line
def halfopticalaxis(expr linethickness)(expr offset) =
  pickup pensquare scaled linethickness;
  draw (offset,0)--(offset+hsoa,0);
  draw (offset+3hsoa,0)--(offset+.5lLE,0);
enddef;

% optical Axis as dashed line downwards
def opticalaxisdown(expr linethickness)(expr xoffset, yoffset) =
  pickup pensquare scaled linethickness;
  draw (xoffset,yoffset)--(xoffset,yoffset-hsoa);
  draw (xoffset,yoffset-3hsoa)--(xoffset,yoffset-5hsoa);
  draw (xoffset,yoffset-7hsoa)--(xoffset,yoffset-1lLE);
enddef;

% half optical Axis as dashed line downwards
def halfopticalaxisdown(expr linethickness)(expr xoffset, yoffset) =
  pickup pensquare scaled linethickness;
  draw (xoffset,yoffset)--(xoffset,yoffset-hsoa);
  draw (xoffset,yoffset-3hsoa)--(xoffset,yoffset-.5lLE);
enddef;

% Camera
def camera =
  pickup pensquare scaled thickline;
  numeric pl;
  pl:=cam_lt-cam_spx;
  draw (pl,.25cam_spy)--(0,.5cam_spy)--(0,-.5cam_spy)--(pl,-.25cam_spy);
  draw (pl,.5cam_ht)--(pl,-.5cam_ht)--(cam_lt,-.5cam_ht)--(cam_lt,.5cam_ht)--cycle;
enddef;

"SmallLens";
twochars(0)(small_lens)(.5slens_ht#,slens_lt#,.5slens_ht#);

"HalfSmallLens";
fourchars(2)(half_small_lens)((slens_lt,0))(.5slens_ht#,slens_lt#,.5slens_ht#);

"BoldLens";
twochars(6)(bold_lens)(.5blens_ht#,blens_lt#,.5blens_ht#);

"HalfBoldLens";
fourchars(8)(half_bold_lens)((blens_lt,0))(.5blens_ht#,blens_lt#,.5blens_ht#);

"SmallKonkavLens";
twochars(12)(small_konkav_lens)(.5sklens_ht#,sklens_lt#,.5sklens_ht#);

"HalfSmallKonkavLens";
fourchars(14)(half_small_konkav_lens)((sklens_lt,0))(.5sklens_ht#,sklens_lt#,.5sklens_ht#);

"Mirror";
eightchars(85)(mirror)(.5mir_lt#,.5mir_ht#,.5mir_ht#,.5mir_lt#);

"BeamSplitter";
eightchars(36)(halfmirror;halfmirrorline)(.5mir_lt#,.5mir_ht#,.5mir_ht#,.5mir_lt#);

"Polarizer";
twochars(44)(polarizer)(.5pol_ht#,pol_lt#,.5pol_ht#);

"Pinhole";
twochars(46)(pinhole)(.5pin_ht#,pin_lt#,.5pin_ht#);

"Camera";
fourchars(66)(camera)((cam_lt,0))(.5cam_ht#,cam_lt#,.5cam_ht#);

"ScreenLeft";
twochars(72)(screenleft(2);opticalaxis(normalline)(0))(.5scr_ht#,scr_lt#,.5scr_ht#);

"ScreenRight";
twochars(74)(screenright(2);opticalaxis(normalline)(1lLE))(.5scr_ht#,scr_lt#,.5scr_ht#);

"ScreenLeftBehind";
twochars(76)(screenleft(2);halfopticalaxis(normalline)(1.5lLE))(.5scr_ht#,scr_lt#,.5scr_ht#);

"ScreenRightBehind";
twochars(78)(screenright(2);halfopticalaxis(normalline)(0))(.5scr_ht#,scr_lt#,.5scr_ht#);

"VScreenLeft";
twochars(80)(screenleft(4);opticalaxis(normalline)(0);halfopticalaxis(normalline)(1.5lLE))(.5scr_ht#,scr_lt#,.5scr_ht#);

"VScreenRight";
twochars(82)(screenright(4);opticalaxis(normalline)(1lLE);halfopticalaxis(normalline)(0))(.5scr_ht#,scr_lt#,.5scr_ht#);

"horizontal dashed half line to the right";
beginchar(128,.5lLE#,0pt,0pt);
   halfopticalaxis(normalline)(0);
endchar;

"horizontal dashed long line to the right";
beginchar(129,1lLE#,0pt,0pt);
   opticalaxis(normalline)(0);
endchar;

"horizontal dashed half line to the left";
beginchar(130,.5lLE#,0pt,0pt);
   halfopticalaxis(normalline)(-.5lLE);
endchar;

"horizontal dashed half line up";
beginchar(131,0pt,.5lLE#,0pt);
   halfopticalaxisdown(normalline)(0,.5lLE);
endchar;

"horizontal dashed long line up";
beginchar(132,0pt,1lLE#,0pt);
   opticalaxisdown(normalline)(0,1lLE);
endchar;

"horizontal dashed half line down";
beginchar(133,0pt,0pt,.5lLE#);
   halfopticalaxisdown(normalline)(0,0);
endchar;

"bold horizontal dashed half line to the right";
beginchar(136,.5lLE#,0pt,0pt);
   halfopticalaxis(2normalline)(0);
endchar;

"bold horizontal dashed long line to the right";
beginchar(137,1lLE#,0pt,0pt);
   opticalaxis(2normalline)(0);
endchar;

"bold horizontal dashed half line to the left";
beginchar(138,.5lLE#,0pt,0pt);
   halfopticalaxis(2normalline)(-.5lLE);
endchar;

"bold horizontal dashed half line up";
beginchar(139,0pt,.5lLE#,0pt);
   halfopticalaxisdown(2normalline)(0,.5lLE);
endchar;

"bold horizontal dashed long line up";
beginchar(140,0pt,1lLE#,0pt);
   opticalaxisdown(2normalline)(0,1lLE);
endchar;

"bold horizontal dashed half line down";
beginchar(141,0pt,0pt,.5lLE#);
   halfopticalaxisdown(2normalline)(0,0);
endchar;

% This is a part of mf-output from Gnuplot. It adds the possibility to
% use Text within METAFONT-Symbols
if unknown cmbase: input cmbase fi

tracingstats:=1;
picture r[];

def put_text(expr ts,xstart,ystart,rot,justification) =
  begingroup
    text_width:=0;text_height:=0;
    for ind:=0 step 1 until length(ts)-1:
      dec_num:=ASCII substring (ind,ind+1) of ts;
      if unknown r[dec_num]: dec_num:=32; fi
      if dec_num=32: 
        text_width:=text_width+wd[65];
        text_height:=max(text_height,ht[65]+dp[65]);
      elseif dec_num>=0: 
        text_width:=text_width+wd[dec_num];
        text_height:=max(text_height,ht[dec_num]+dp[dec_num]);
      fi
    endfor
    if rot=90:
      if justification=1: ynext:=ystart;
      elseif justification=2: ynext:=round(ystart-text_width/2);
      else: ynext:=round(ystart-text_width);
      fi
      xnext:=xstart+text_height/2;
    else:
      if justification=1: xnext:=xstart;
      elseif justification=2: xnext:=round(xstart-text_width/2);
      else: xnext:=round(xstart-text_width);
      fi
      ynext:=ystart-text_height/2;
    fi
    for ind:=0 step 1 until length(ts)-1:
      dec_num:=ASCII substring (ind,ind+1) of ts;
      if unknown r[dec_num]: dec_num:=32; fi
      if dec_num=32: 
        xnext:=xnext+wd[65]*cosd rot;
        ynext:=ynext+wd[65]*sind rot;
      elseif dec_num>=0: 
        currentpicture:=currentpicture+r[dec_num] shifted(xnext,ynext)
          rotatedaround ((xnext,ynext),rot); 
        xnext:=xnext+wd[dec_num]*cosd rot;
        ynext:=ynext+wd[dec_num]*sind rot;
      fi
    endfor
  endgroup 
enddef;

def endchar =
  r[charcode]:=currentpicture;
  wd[charcode]:=w;ht[charcode]:=h;dp[charcode]:=d;
  endgroup;
enddef;
let endchar_ = endchar;
let generate = relax;
let roman = relax;
input cmss10.mf
if ligs>1: font_coding_scheme:="TeX text";
else: font_coding_scheme:=
  if ligs=0: "TeX typewriter text"
  else: "TeX text without f-ligatures" fi;
fi
font_setup;
input romanu.mf %Roman uppercase.
input romanl.mf %Roman lowerrcase.

def endchar =
  % Next line should probably be removed if CM base is used
%  l:=0; r:=w;
  %Include the next two lines if you want to
  %rotate the picture 90 deg.(Portrait to Landscape)
  %currentpicture:=currentpicture rotated 90 shifted (h,0);
  %tmp:=charht; charht:=charwd; charwd:=tmp;
  scantokens extra_endchar;
  if proofing>0: makebox(proofrule); fi
  chardx:=w;
  shipit;
  if displaying>0: makebox(screenrule); showit; fi
  endgroup 
enddef;
let endchar_ = saveendchar;
let generate = input;
let roman = roman;
def t_ = transformed currenttransform enddef;
% End of Gnuplot-Part

"Laser Box horizontal";
beginchar(160,lab_wd#,.5lab_ht#,.5lab_ht#);
  pickup pensquare scaled thickline;
  rectangle(lab_wd,lab_ht,0,0);
  pickup pencircle scaled normalline;
  put_text("Laser",.5lab_wd,0,0,2);
endchar;

"Laser Box vertical";
beginchar(161,.5lab_ht#,lab_wd#,.5lab_ht#);
  pickup pensquare scaled thickline;
  rectangle(lab_ht,lab_wd,-.5lab_ht,.5lab_wd);
  pickup pencircle scaled normalline;
  put_text("Laser",0,.5lab_wd,90,2);
endchar;

"Photometer Box horizontal";
beginchar(162,omb_wd#,.5omb_ht#,.5omb_ht#);
  pickup pensquare scaled thickline;
  rectangle(omb_wd,omb_ht,0,0);
  pickup pencircle scaled normalline;
  put_text("PM",.5omb_wd,0,0,2);
endchar;

"Photometer Box vertical";
beginchar(163,.5omb_ht#,omb_wd#,.5omb_ht#);
  pickup pensquare scaled thickline;
  rectangle(omb_ht,omb_wd,-.5omb_ht,.5omb_wd);
  pickup pencircle scaled normalline;
  put_text("PM",0,.5omb_wd,90,2);
endchar;

"Optical Modulator Box horizontal";
beginchar(164,omb_wd#,.5omb_ht#,.5omb_ht#);
  pickup pensquare scaled thickline;
  rectangle(omb_wd,omb_ht,0,0);
  pickup pensquare scaled normalline;
  put_text("OM",.5omb_wd,0,0,2);
endchar;

"Optical Modulator Box vertical";
beginchar(165,omb_ht#,.5omb_wd#,.5omb_wd#);
  pickup pensquare scaled thickline;
  rectangle(omb_ht,omb_wd,0,0); %-.5omb_ht,.5omb_wd);
  pickup pensquare scaled normalline;
  put_text("OM",.5omb_ht,0,90,2);
endchar;

end;
%</optic>
%^^A last update: Tue  02-04-1997
%
%<*csym>
mode_setup;

% alle Symbole in einem 7pt Raster definieren
lLE#      :=7pt#;
define_whole_pixels(lLE);

% Liniest"arke und deren Variationen
linethickness#:= 0.45pt#;
thinline#     := 0.5linethickness#;
normalline#   := 1.0linethickness#;
thickline#    := 1.5linethickness#;
verythickline#:= 2.5linethickness#;
define_whole_blacker_pixels(normalline,thinline,thickline,verythickline);

fontdimen6: 1lLE#;

% *_ht  means the total height  !!! only <integer>*lLE#
% *_lt  means the total length  !!! only <integer>*lLE#

% *_spc means an inner  space
% *_spx means an inner  x-space
% *_spy means an inner  y-space
% *_wd  means an inner  width
% *_rad means a         radius
% *_dia means a         diameter
% *_phi means an        angle
% *_psi means an        angle

%box symbol
box_wd#  := 4lLE#;
define_pixels(box_wd);

%oscillograph
osc_dia# := 3lLE#;
osc_t    := .75;    % settings from Andreas Tille
osc_spc  := .5lLE;
define_pixels(osc_dia);

%wwire
ww_spc   := .25lLE;

darr_ht# := 1.3lLE#;
darr_lt# := 1lLE#;
darr_phi := 10;
darr_rad := 1lLE;
define_pixels(darr_ht,darr_lt);


bnd_lt# := 1lLE#;
bnd_phi := 60;
define_pixels(bnd_lt);

dsw_wd# := 4lLE#;
dsw_ht# := 2lLE#;
dsw_ov  := .2lLE;
dsw_t   := .2;
dsw_cc  := .35;
dsw_c   := .3;
dsw_phi := 12;
define_pixels(dsw_wd,dsw_ht);


tri_lt   := 0.8lLE;
tri_phi  := 18;

arr_lt   := 0.8lLE;
arr_phi  := 10;


%capacitor
cap_wd   :=  .4lLE;      %only for electrolytic capacitor
cap_spx  := .32lLE;      %only for electrolytic capacitor
cap_spy  :=  .5lLE;      %only for electrolytic capacitor
cap_rad  :=  .4lLE;
cap_spc  := .32lLE;
cap_ht#  :=   2lLE#;
cap_lt#  :=   2lLE#;
cap_phi  :=   45;
cap_ara  :=   1.4lLE;
cap_arb  :=   1.2lLE;
define_pixels(cap_lt,cap_ht);

%resistor
res_wd   :=   3lLE;
res_ht#  :=   1lLE#;
res_lt#  :=   4lLE#;
res_ara# :=  3.3lLE#;
res_phi  :=   45;
res_x#   :=   1lLE#;
res_y#   :=   1lLE#;
res_o#   :=   res_ara#*cosd(res_phi)-res_y#;
define_pixels(res_lt,res_ht,res_x,res_y,res_o,res_ara);

%diode
did_wd   :=   2lLE;
did_ht#  :=   2lLE#;
did_lt#  :=   4lLE#;
did_zlt  :=   .4lLE;
Dcap_ht  := .5lLE;
Dcap_spc := .15lLE;
Dcap_wd  := .35lLE;
define_pixels(did_lt,did_ht);

thy_ht# := 1lLE#;
define_pixels(thy_ht);

%led
% >wd ht lt< same as diode
% led_* means values for the arrows
led_lt   :=   2lLE;
led_wd   :=  .8lLE;
led_phi  :=  10;       %aperture-angle of arrows
led_psi  :=  50;       %angle of arrows from baseline
led_spc  := .5lLE;     %space between arrows
led_spx  := .3lLE;
led_spy  := .5lLE;

%transistor
pnp_dis  :=  0.18;
npn_dis  :=  (1-pnp_dis);
tst_fac  :=  0.23333;
tst_phi  :=  20;
tst_iht  :=  3lLE;
tst_wd#  :=  1lLE#;
tst_lt#  :=  2lLE#;
tst_ht#  :=  4lLE#;
define_pixels(tst_ht,tst_lt,tst_wd);

%crystal
cry_wd   :=  .8lLE;
cry_spc  := .32lLE;
cry_ht#  :=   2lLE#;
cry_lt#  :=   4lLE#;
define_pixels(cry_lt,cry_ht);

%input/output connection
ioc_dia  := .5lLE;
ioc_ht#  := .5lLE#;
ioc_lt#  :=   1lLE#;
ioc_arr  := 0.7lLE;
ioc_phi  :=  12;
define_pixels(ioc_ht,ioc_lt);

%connection dot
cdt_dia  := .4lLE;
cdt_ht#  := .4lLE#;
cdt_lt#  := .2lLE#;
define_pixels(cdt_ht,cdt_lt);

%GND
GND_wd#  := 1.4res_ht#;
gnd_wd#  := 1.8lLE#;
gnd_ht#  :=   1lLE#;
gnd_spc#  := .2lLE#;
gnd_q    := .7;
define_pixels(gnd_ht,gnd_spc,gnd_wd,GND_wd);

%gate
inv_rad  :=  .36lLE;
gat_ht#  :=   5lLE#;
gat_lt#  :=   7lLE#;
define_pixels(gat_lt,gat_ht);

bbd_wd# := 6lLE#;
bbd_ht# := 10lLE#;
bba_wd# := 8lLE#;
bba_ht# := 4lLE#;
define_pixels(bbd_wd,bbd_ht,bba_wd,bba_ht);

%big integrated circuits
pin_lt#  :=   2lLE#;  % pin length
ios_wd#  :=   2.5lLE#;  % in out space
mid_wd#  :=   0lLE#;  % middle width
pin_spc# :=   2lLE#;  % pin space
out_spc# :=   1lLE#;  % outer space between pin and box

define_pixels(pin_lt,ios_wd,mid_wd,pin_spc,pin_wht,out_spc);

%value
val_lt#  :=   2lLE#;
val_phi  :=   7;
val_lft  :=   0;
val_rht  :=   0.9;
val_ht#  :=   .2lLE#;
define_pixels(val_lt,val_ht);

%circle
cir_ht#  :=  1.2lLE#;
cir_lt#  :=  4lLE#;
cir_phi  :=  45;
cir_ara  :=  2.2lLE;
cir_arb  :=  1.8lLE;
define_pixels(cir_ht,cir_lt);

%usource
uso_ht#  :=  1.5lLE#;
uso_lt#  :=  4lLE#;
uso_min  :=  1lLE;
uso_pls  :=  3lLE;
uso_spc  := .5lLE;
uso_rad  :=  3lLE;
uso_dis  := 0.2;
uso_phi  := 45;
uso_ara  := 1.6lLE;
uso_arb  := .8lLE;
define_pixels(uso_ht,uso_lt);

%isource
iso_ht#  := 1.2lLE#;
iso_lt#  := 4lLE#;
iso_dis  := 0.7;
iso_rad  :=  .8lLE;
iso_phi  := 45;
iso_ara  := 2.2lLE;
iso_arb  := 1.8lLE;
define_pixels(iso_ht,iso_lt);

%coil
coi_ht#  :=  .35lLE#;
coi_lt#  :=    4lLE#;
define_pixels(coi_ht,coi_lt);
coi_rad  :=  coi_ht;
coi_num  :=    4;

%switch
swt_lt#  :=  4lLE#;
swt_phi  :=  30;
swt_dis  :=  0.3;
swt_ind  :=  0.8;
swt_slt  :=  0.4lLE;
swt_ht#  := (1-2swt_dis)*sind(swt_phi)*swt_lt#;
define_pixels(swt_ht,swt_lt);

%OPV
opv_ht#  := 4.5lLE#;
opv_lt#  := 14lLE#;
opv_dis#  := 3lLE#;
opv_frc  := 1.1;
define_pixels(opv_lt,opv_ht,opv_dis);

%FET
fet_SD#  :=  4lLE#;     % Source--Drain
fet_GSx# :=  2lLE#;     % Gate--Source, x
fet_GSy# :=  1lLE#;     % Gate--Source, y
fet_Gsub :=  1lLE;      % Gate--Substrat
fet_soSD :=  0.3lLE;    % Substrat "uber Source und Drain
fet_sarr :=  0.2lLE;    % Substrat--Pfeil
define_pixels(fet_SD,fet_GSx,fet_GSy);


%MOSFET
mos_SD#  := fet_SD#;
mos_GSx# := fet_GSx#;
mos_GSy# := fet_GSy#;

mos_sd   := 2.3lLE;
mos_Gsub := fet_Gsub;
mos_ox   := 0.3lLE;
mos_soSD := fet_soSD;
mos_rad  := 0.2lLE;
define_pixels(mos_SD,mos_GSx,mos_GSy);

sym# := 232/36pt#;
define_pixels(sym);

% ############
% definitions
% ############

% for proofing mark all points
extra_endchar:=extra_endchar & "labels(range 0 thru 30);";

def {{ =
   begingroup
   save T; transform T;
   T:=currenttransform;
   save currenttransform;
   transform currenttransform;
   currenttransform:=T;
enddef;

def }} = endgroup; enddef;

def noarrowTF =
  transform _aT;
  numeric _x[],_y[];
  _aT:=currenttransform;
  for $=1 upto 20 : _x[$]:=x[$]; _y[$]:=y[$]; endfor;
  endgroup;
  for $=1 upto 20 : x[$]:=_x[$]; y[$]:=_y[$]; endfor;
  {{
enddef;

def addTF(text t) = currenttransform:=currenttransform t; enddef;
def addxTF(text t) = currenttransform:=(identity t) transformed
                     currenttransform; enddef;

def triangle(expr p, l, alpha, phi) =
  pair iz[];
  iz0=(0,0);
  iz1=iz0+((l,0) rotated (alpha+phi));
  iz2=iz0+((l,0) rotated (-alpha+phi));
  fill ((iz0--iz1--iz2--cycle) shifted round(p));
enddef;

def arrow(expr p, a, b, phi, l, alpha)(text doother) =
  pair iz[];
  iz0=(0,0);
  iz1=iz0-((l,0) rotated (alpha+phi));
  iz2=iz0-((l,0) rotated (-alpha+phi));
  iz3=p transformed if known _aT : _aT; else: identity; fi;
  iz3-iz4=(b,0) rotated phi;
  iz5-iz3=(a,0) rotated phi;
  iz6-iz3=(a-3*rt(0),0) rotated phi;
  draw iz4--iz6;
  doother;
  draw ((iz1--iz0--iz2) shifted round(iz5));
  transform _aT; %Transformation l"oschen
enddef;

def fillarrow(expr p, a, b, phi, l, alpha)(text doother) =
  pair iz[];
  iz0=(0,0);
  iz1=iz0-((l,0) rotated (alpha+phi));
  iz2=iz0-((l,0) rotated (-alpha+phi));
  iz3=p transformed if known _aT : _aT; else: identity; fi;
  iz3-iz4=(b,0) rotated phi;
  iz5-iz3=(a,0) rotated phi;
  iz6-iz3=(a-3*rt(0),0) rotated phi;
  draw iz4--iz6;
  doother;
  fill ((iz1--iz0--iz2--cycle) shifted round(iz5));
  transform _aT; %Transformation l"oschen
enddef;

def eightchars(expr cfchar)   % erster Zeichenkode
              (text dochar)   % Zeichenkommandos
              (expr x, yf, ys, o) = % Abst"ande

  beginchar(cfchar,x,ys,yf); charic:=o;
    dochar;
  endchar;
  beginchar(cfchar+1,x,ys,yf); charic:=o;
    {{addTF(reflectedabout(up,down)); dochar;}}
  endchar;
  beginchar(cfchar+2,yf,x,o+x); charic:=ys;
    {{addTF(rotated 270); dochar;}}
  endchar;
  beginchar(cfchar+3,yf,x+o,x); charic:=ys;
    {{addTF(rotated 270); addTF(reflectedabout(left,right)); dochar;}}
  endchar;
  beginchar(cfchar+4,x,yf,ys); charic:=o;
    {{addTF(reflectedabout(left,right)); dochar;}}
  endchar;
  beginchar(cfchar+5,x,yf,ys); charic:=o;
    {{addTF(rotated 180); dochar;}}
  endchar;
  beginchar(cfchar+6,ys,x,x+o); charic:=yf;
    {{addTF(rotated 270); addTF(reflectedabout(up,down)); dochar;}}
  endchar;
  beginchar(cfchar+7,ys,x+o,x); charic:=yf;
    {{addTF(rotated 90); dochar;}}
  endchar;
enddef;

def twochars(expr cfchar)(text dochar)(expr ht, wd, dp) =
  beginchar(cfchar,wd,ht,dp);
    dochar;
  endchar;
  beginchar(cfchar+1,dp,wd,ht);
    {{addTF(rotated 90); dochar;}}
  endchar;
enddef;

def fourchars(expr cfchar)(text dochar)(text op)(expr ht, wd, dp) =
  beginchar(cfchar,wd,ht,dp);
    dochar;
  endchar;
  beginchar(cfchar+1,dp,wd,ht);
    {{addTF(rotated 90); dochar;}}
  endchar;
  beginchar(cfchar+2,wd,dp,ht);
    {{addTF(shifted -op rotated 180); dochar;}}
  endchar;
  beginchar(cfchar+3,ht,wd,dp);
    {{addTF(shifted -op rotated -90); dochar;}}
  endchar;
enddef;

def fourfourchars(expr cfchar)(text dochar)(text op)(expr ht, wd, dp) =
  beginchar(cfchar,wd,ht,dp);
    dochar;
  endchar;
  beginchar(cfchar+1,dp,wd,ht);
    {{addTF(rotated 90); dochar;}}
  endchar;
  beginchar(cfchar+2,wd,dp,ht);
    {{addTF(shifted -op rotated 180); dochar;}}
  endchar;
  beginchar(cfchar+3,ht,wd,dp);
    {{addTF(shifted -op rotated -90); dochar;}}
  endchar;
  beginchar(cfchar+4,wd,dp,ht);
    {{addTF(reflectedabout(left,right)); dochar;}}
  endchar;
  beginchar(cfchar+5,ht,wd,dp);
    {{addTF(reflectedabout(left,right) rotated 90); dochar;}}
  endchar;
  beginchar(cfchar+6,wd,ht,dp);
    {{addTF(reflectedabout (left,right) shifted -op rotated 180); dochar;}}
  endchar;
  beginchar(cfchar+7,dp,wd,ht);
    {{addTF(reflectedabout(left,right) shifted -op rotated -90); dochar;}}
  endchar;
enddef;

% small description of >hshade< and >vshade<
%
% The shade macros fill areas with a 'patternpath'.
%
% >vshade< expect that the area is bound left and right by vertical
% lines, the upper and lower boundary is build by the two pathes
% >pa< and >pb<.
%
% >hshade< expect it vice versa.
%
% The >patternpath< is used to draw it on invisible points of a grid.
% These gridpoints have a distance of 'di'.

primarydef x gridmod y = if x>0: (x mod y) else: -(-x mod y) fi enddef;

def vshade(suffix pa, pb)(expr di, patternpath) = begingroup
  path vl;
  boolean ifshift;

  if not cycle patternpath:
    errmessage "patternpath has to be a cyclic path!" fi;

  interim smoothing:=0;                  %change local only
  interim autorounding:=0;

  ifshift:=true;
  ydi:=round(1.41di);                    % round against pattern in
  xdi:=round(di);                        % pattern
  if xdi<2: errmessage "di to small! di>=2" fi;
  xs:=xpart(point 0 of pa);
  xe:=xpart(point infinity of pa);
  if xs>xe: ye:=xe; xe:=xs; xs:=ye; fi   %force xs<xe
  xs:=xs+((xe-xs) mod xdi) / 2;          %adjust grid horizontally
  vl:=(xs,infinity)--(xs,-infinity);
  oys:=ypart(pa intersectionpoint vl);
  oys:=oys-.5ydi;                        %adjust grid vertically
  for xs:=xs step xdi until xe:
    vl:=(xs,infinity)--(xs,-infinity);   % new cut line
    ys:=ypart(pa intersectionpoint vl);
    ye:=ypart(pb intersectionpoint vl);
    ifshift:=not(ifshift);               %shift periodically
    sy:=ydi-((ys-oys) gridmod ydi);
    ys:=ys+sy if ifshift: if sy-.5ydi<0:+else:-fi .5ydi fi;
    for ys:=ys step if ys>ye:-fi ydi until ye:
      fill patternpath shifted (xs,ys);
    endfor
  endfor;
  endgroup
enddef;

def hshade(suffix pa, pb)(expr di, patternpath) = begingroup
  path hl;
  boolean ifshift;

  if not cycle patternpath:
    errmessage "patternpath has to be a cyclic path!" fi;

  interim smoothing:=0;                  %change local only
  interim autorounding:=0;

  ifshift:=true;
  xdi:=round(1.41di);                    % round against pattern in
  ydi:=round(di);                        % pattern
  if ydi<2: errmessage "di to small! di>=2" fi;
  ys:=ypart(point 0 of pa);
  ye:=ypart(point infinity of pa);
  if ys>ye: xe:=ye; ye:=ys; ys:=xe; fi   %force ys<ye
  ys:=ys+((ye-ys) mod ydi) / 2;          %adjust grid vertically
  hl:=(infinity,ys)--(-infinity,ys);
  oxs:=xpart(pa intersectionpoint hl);
  oxs:=oxs-.5ydi;                        %adjust grid horizontally
  for ys:=ys step ydi until ye:
    hl:=(infinity,ys)--(-infinity,ys);   % new cut line
    xs:=xpart(pa intersectionpoint hl);
    xe:=xpart(pb intersectionpoint hl);
    ifshift:=not(ifshift);               %shift periodically
    sx:=xdi-((xs-oxs) gridmod xdi);
    xs:=xs+sx if ifshift: if sx-.5xdi<0:+else:-fi .5xdi fi;
    for xs:=xs step if xs>xe:-fi xdi until xe:
      fill patternpath shifted (xs,ys);
    endfor
  endfor;
  endgroup
enddef;


endinput;
%</csym>
%
%^^A last update: Tue  02-04-1997
%
%<*csybimos>
input csym;
designsize:=1lLE#;

def mosfet =  % ok
  z0=(0,0);
  x1=x2=x3=x4;
  y2-y1=mos_SD;
  y4-y3=mos_sd;
  .5[z2,z1]=.5[z4,z3];
  y6=y4; y7=y3;
  x4-x6=x3-x7;
  .5[z8,z9]=.5[z6,z7]=z5;
  x9=x8;
  y8-y6=mos_soSD;
  x10=x11;
  x0+mos_Gsub=x10+mos_ox=x7;
  x1-x0=mos_GSx;
  y0=y10=y1+mos_GSy;
  y6-y11=y10-y7;
  z12=.5[z1,z2];
  z6=.5[z13,z8];
  z7=.5[z14,z9];
  z15-z16=z8-z13;
  z5=.5[z15,z16];
  pickup pencircle scaled mos_rad;
  drawdot round(z3);
  pickup pensquare scaled normalline;
  draw z1--z3--z7;
  draw z2--z4--z6;
  draw z0--z10--z11;
  draw z5--z12--z3;
  pickup pensquare scaled thickline;
enddef;

def mosfet_V =  % ok
  mosfet;
  draw z8--z9;
enddef;

def mosfet_A =  % ok
  mosfet;
  draw z8--z13;
  draw z9--z14;
  draw z15--z16;
enddef;

def fet =  % ok
    z0=(0,0);
    z1=z0+(fet_Gsub,0);
    y2=y1;
    x2=x3=x4=x0+fet_GSx;
    y3=y2-fet_GSy;
    z2-z3=z4-z5;
    y4-y3=fet_SD;
    y6=y5;
    x1=x6;
    x8=x7;
    y8=y1-fet_soSD;
    .5[z4,z3]=.5[z5,z2];
    .5[z7,z8]=.5[z1,z6];
    z9=z1-(fet_sarr+tri_lt,0);
    pickup pensquare scaled normalline;
    draw z0--z1--z2--z3;
    draw z6--z5--z4;
    pickup pensquare scaled thickline;
    draw z7--z8;
enddef;

def transistor_without_basis =  % "uberarbeiten
  numeric pl;
  pl:=.5(tst_ht-tst_iht);
  z1-z2=(0,tst_iht);
  z0=.5[z1,z2];
  z3=tst_fac[z0,z1];
  z4=tst_fac[z0,z2];
  z5=z1+(tst_wd,0);
  z6=z2+(tst_wd,0);
  z7=z5+(0,pl);
  z8=z6+(0,-pl);
  z9=tst_dis[z4,z6];
  pickup pensquare scaled normalline;
  draw z1--z2;
  draw z3--z5--z7;
  draw z4--z6--z8;
  pickup pencircle scaled thinline;
  triangle(z9,tst_rad,tri_phi,angle(z6-z4));
enddef;

def npn_no_basis =  % "uberarbeiten
  numeric tst_rad,tst_dis;
  tst_rad:=-tri_lt;
  tst_dis:=npn_dis;
  z0=(0,0);
  transistor_without_basis;
enddef;

def pnp_no_basis =  % "uberarbeiten
  numeric tst_rad,tst_dis;
  tst_rad:=tri_lt;
  tst_dis:=pnp_dis;
  z0=(0,0);
  transistor_without_basis;
enddef;

def npn =  % "uberarbeiten
  numeric tst_rad,tst_dis;
  tst_rad:=-tri_lt;
  tst_dis:=npn_dis;
  z0=(tst_wd,0);
  z20=(0,0);
  transistor_without_basis;
  pickup pensquare scaled normalline;
  draw z20--z0;
enddef;

def pnp =  % "uberarbeiten
  numeric tst_rad,tst_dis;
  tst_rad:=tri_lt;
  tst_dis:=pnp_dis;
  z0=(tst_wd,0);
  z20=(0,0);
  transistor_without_basis;
  pickup pensquare scaled normalline;
  draw z20--z0;
enddef;


"Transistor NPN ohne Basis";
eightchars(0)
   (npn_no_basis)
   (tst_wd#,.5tst_ht#,.5tst_ht#,0);

"Transistor PNP ohne Basis";
eightchars(8)
   (pnp_no_basis)
   (tst_wd#,.5tst_ht#,.5tst_ht#,0);

"Transistor NPN";
eightchars(16)
   (npn)
   (tst_wd#+tst_wd#,.5tst_ht#,.5tst_ht#,0);

"Transistor PNP";
eightchars(24)
   (pnp)
   (tst_wd#+tst_wd#,.5tst_ht#,.5tst_ht#,0);

"FET n-Kanal";
eightchars(32)
   (fet;
    pickup pencircle scaled thinline;
    triangle(z1,tri_lt,tri_phi,180);
   )
   (fet_GSx#,fet_GSy#,fet_SD#-fet_GSy#,0);

"FET p-Kanal";
eightchars(40)
   (fet;
    pickup pencircle scaled thinline;
    triangle(z9,tri_lt,tri_phi,0);
   )
   (fet_GSx#,fet_GSy#,fet_SD#-fet_GSy#,0);

"MOSFET n-Kanal V";
eightchars(48)
   (mosfet_V;
    pickup pencircle scaled thinline;
    triangle(z5,tri_lt,tri_phi,0);
   )
   (mos_GSx#,mos_GSy#,mos_SD#-mos_GSy#,0);

"MOSFET p-Kanal V";
eightchars(56)
   (mosfet_V;
    pickup pencircle scaled thinline;
    triangle(z12,tri_lt,tri_phi,180);
   )
   (mos_GSx#,mos_GSy#,mos_SD#-mos_GSy#,0);

"MOSFET n-Kanal A";
eightchars(64)
   (mosfet_A;
    pickup pencircle scaled thinline;
    triangle(z5,tri_lt,tri_phi,0);
   )
   (mos_GSx#,mos_GSy#,mos_SD#-mos_GSy#,0);

"MOSFET p-Kanal A";
eightchars(72)
   (mosfet_A;
    pickup pencircle scaled thinline;
    triangle(z12,tri_lt,tri_phi,180);
   )
   (mos_GSx#,mos_GSy#,mos_SD#-mos_GSy#,0);

end;
%</csybimos>
%
%^^A last update: Tue  02-04-1997
%
%<*csywidko>
input csym;
designsize:=.5lLE#;

def resistor =
  numeric pl;
  pl:=.5(res_lt-res_wd);
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z1+(res_wd,0);
  z3=z2+(pl,0);
  z4-z5=z6-z7=(0,res_ht);
  z1=.5[z4,z5];
  z2=.5[z6,z7];
  z8=z0+(res_x,-res_y);
  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z2--z3;
  draw z4--z6--z7--z5--cycle;
enddef;

def resistor_var =
  {{
  addxTF(shifted -z8 rotated -90);
  resistor;
  pickup pensquare scaled normalline;
  arrow(z8,res_ara,0,res_phi,arr_lt,arr_phi)
    (pickup pencircle scaled normalline);
  }}
enddef;

def capacitor =
  pickup pensquare scaled normalline;
  numeric pl;
  pl:=.5(cap_lt-cap_spc);
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z1+(cap_spc,0);
  z3=z2+(pl,0);
  z4-z5=z6-z7=(0,cap_ht);
  z1=.5[z4,z5];
  z2=.5[z6,z7];
  draw z0--z1;
  draw z2--z3;
  draw z4--z5;
  draw z6--z7;
enddef;

def capacitor_var =
  capacitor;
  noarrowTF;
  pickup pencircle scaled thinline;
  arrow(.5[z1,z2],cap_ara,cap_arb,cap_phi,arr_lt,arr_phi)();
enddef;

def electrolytic_capacitor =
  pickup pensquare scaled normalline;
  numeric pl;
  pl:=.5(cap_lt-cap_spc-cap_wd);
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z1+(cap_spc,0);
  z3=z2+(cap_wd,0);
  z4=z3+(pl,0);
  z5-z6=z7-z8=z9-z10=(0,cap_ht);
  z1=.5[z5,z6];
  z2=.5[z7,z8];
  z3=.5[z9,z10];
  draw z0--z1;
  draw z3--z4;
  draw z5--z6;
  draw z7--z9--z10--z8--cycle;
enddef;


"Widerstand";
twochars(0)(resistor)(.5res_ht#,res_lt#,.5res_ht#);

"Widerstand variabel";
eightchars(8)(resistor_var)(res_y#,res_lt#-res_x#,res_x#,res_o#);

"Kondensator";
twochars(128)(capacitor)(.5cap_ht#,cap_lt#,.5cap_ht#);

"Kondensator variabel";
twochars(130)(capacitor_var)(.5cap_ht#,cap_lt#,.5cap_ht#);

"Elektrolyt-Kondensator";
fourchars(136)(electrolytic_capacitor)(z4)(.5cap_ht#,cap_lt#,.5cap_ht#);

end;
%</csywidko>
%
%^^A last update: Tue  02-04-1997
%
%<*csysym>
input csym;
designsize:=.5lLE#;

def eqtriangle(expr l)=
  x1=x2=x0=x3-l;
  y3=y0;
  z1-z2=(z3-z2) rotated 60;
enddef;

def sinus(expr A, k, s) =
  j:=0;
  for i:=0 step s until 360:
    z[j]=(k*i,A*sind(i));
    j:=j+1;
  endfor
  draw for i:=0 upto floor(360/s)-1: z[i].. endfor z[floor(360/s)];
enddef;

def disarrow =
  z0=(0,0);
  x0=x1=x2;
  y1-y2=darr_ht;
  .5[z1,z2]=z0;
  y0=y3;
  x3-x0=darr_lt;
  pickup pensquare scaled normalline;
  draw z0--z3;
  draw z1--z2;
  triangle(z0,darr_rad,darr_phi,0);
enddef;

def trigger =
  z0=(0,0);
  x1=x2; x3=x4;
  y2=y4=y5; y0=y1=y3;
  x3-x1=.17sym;
  x1-x0=x5-x4=.3sym;
  y2-y1=sym;
enddef;

def impuls =
  z0=(0,0);
  y0=y1=y4=y5=y7=y8=y9;
  x1-x0=x3-x2=x5-x4=x8-x7=.6sym;
  x9-x0=x6-x2=.2sym;
  x1=x2; x3=x4;  x6=x7;
  y2-y1=y3-y4=y6-y7=sym;
  x10=x0; y11=y10=y2;
  x11=x8;
enddef;



 "Rechteckimpuls";
   beginchar(1,1.9sym#,sym#,0);
     impuls
     pickup pensquare scaled normalline;
     draw z0--z1--z2--z3--z4--z5;
   endchar;

 "positive Flanke";
   beginchar(2,1.3sym#,sym#,0);
     impuls
     pickup pensquare scaled normalline;
     draw z0--z1--z2--z3;
   endchar;

 "negative Flanke";
   beginchar(3,1.3sym#,sym#,0);
     impuls
     pickup pensquare scaled normalline;
     draw (z2--z3--z4--z5) shifted (x0-x1,0);
   endchar;

 "Nadelimpuls";
   beginchar(4,1.5sym#,sym#,0);
     impuls
     pickup pensquare scaled normalline;
     draw (z0--z1--z2--z6--z7--z8);
   endchar;

  "inverser Nadelimpuls";
   beginchar(12,1.5sym#,sym#,0);
     impuls
     pickup pensquare scaled normalline;
     draw (z10--z2--z1--z7--z6--z11);
   endchar;

 "Rechteckspannung";
   beginchar(5,3.1sym#,sym#,0);
     impuls
     pickup pensquare scaled normalline;
     draw z0--z1--z2--z3--z4--z5;
     draw (z0--z1--z2--z3--z4--z5) shifted z4;
   endchar;

 "S"&ditto&"agezahn";
   beginchar(6,1.9sym#,sym#,0);
     impuls
     pickup pensquare scaled normalline;
     draw z0--z9--z3--z4--z5;
   endchar;

 "Trigger";
   beginchar(7,.87sym#,sym#,0);
     trigger
     pickup pensquare scaled normalline;
     draw z0--z1--z2--z5;
     draw z1--z3--z4;
   endchar;

 "Abstandsst"&ditto&"uck";
 fourchars(8)(disarrow)(z0)(.5darr_ht#,darr_lt#,.5darr_ht#);

"sinus wave";
beginchar(16,1.6sym#,9/35*sym#,9/35*sym#);
  pickup pencircle scaled normalline;
  sinus(9/35*sym,1.6sym/360,45);
endchar;

"variable sinus wave";
beginchar(17,1.6sym#,9/35*sym#,9/35*sym#);
  pickup pencircle scaled normalline;
  sinus(9/35*sym,1.6sym/360,45);
  fillarrow((.8*sym,0),20/35*sym,15/35*sym,45,15/35*sym,15)();
endchar;

"symbol of amplifier";
beginchar(24,cosd(30)*1.9sym#,.95sym#,.95sym#);
  z0=(0,0);
  eqtriangle(1.9sym);
  pickup pencircle scaled normalline;
  draw z1--z2--z3--cycle;
endchar;

"symbol of buffer";
beginchar(25,cosd(30)*1sym#,.5sym#,.5sym#);
  z0=(0,0);
  eqtriangle(1sym);
  pickup pencircle scaled normalline;
  draw z1--z2--z3--cycle;
endchar;

bye;
%</csysym>
%
%^^A last update: Tue  02-04-1997
%
%<*csyrest>
input csym;
designsize:=.5lLE#;

def switch =  %"uberarbeiten
  numeric pl;
  pl:=swt_lt*swt_dis;
  sl:=(1-2swt_dis)*swt_lt;
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z1+((sl,0) rotated swt_phi);
  z3=z1+(swt_ind*sl,0);
  z4=z0+(swt_lt,0);
  z5=z3+(0,swt_slt);
  pickup pensquare scaled normalline;
  draw z0--z1--z2;
  draw z3--z4;
  draw z3--z5;
enddef;


def dswitch =
  z0=(0,0);
  z1=dsw_t[z0,z0+(dsw_wd,0)];
  x2=x3=x4=x5=x0+((1-dsw_c)*dsw_wd);
  y0=.5[y2,y3]=.5[y4,y5];
  y2-y3=dsw_ht;
  y2-y4=dsw_cc*dsw_ht;
  y2=y6; y3=y7;
  x6-x3=x7-x3=dsw_c*dsw_wd;
  x8=x1+dsw_ov+((1-dsw_c-dsw_t)*dsw_wd);
  y8=sind(dsw_phi)*x8/cosd(dsw_phi);
  pickup pensquare scaled normalline;
  draw z0--z1--z8;
  draw z4--z2--z6;
  draw z5--z3--z7;
enddef;

def circle =  % "uberarbeiten
  numeric pl;
  pl:=.5cir_lt-cir_ht;
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z0+(.5cir_lt,0);
  z3=z1+(2cir_ht,0);
  z4=z3+(pl,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z3--z4;
  pickup pencircle scaled thickline;
  draw fullcircle scaled 2cir_ht shifted z2;
enddef;

def lamp =
  circle
  z10-z11=(2cir_ht,0) rotated 45;
  z12-z13=(2cir_ht,0) rotated -45;
  .5[z10,z11]=z2=.5[z12,z13];
  pickup pencircle scaled normalline;
  draw z10--z11;
  draw z12--z13;
enddef;

def circle_var =
  circle;
  pickup pencircle scaled thinline;
  noarrowTF;
  arrow(z2,cir_ara,cir_arb,cir_phi,arr_lt,arr_phi)();
enddef;

def usource =  %"uberarbeiten
  numeric pl;
  pl:=.5(uso_lt-uso_spc);
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z1+(uso_spc,0);
  z3=z2+(pl,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z2--z3;
  z1=.5[z4,z5]; x4-x5=0; y5-y4=uso_pls;
  z2=.5[z6,z7]; x6-x7=0; y7-y6=uso_min;
  pickup pensquare scaled thickline;
  draw z4--z5;
  draw z6--z7;
enddef;

def usource_var =
  usource;
  noarrowTF;
  pickup pencircle scaled thinline;
  arrow(.5[z1,z2],uso_ara,cir_arb,uso_phi,arr_lt,arr_phi)();
enddef;


def isource =  %"uberarbeiten
  numeric pl;
  pl:=.5(iso_lt-(4-iso_dis)*iso_rad);
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z1+(iso_rad,0);
  z3=z2+((2-iso_dis)*iso_rad,0);
  z4=z3+(iso_rad,0);
  z5=z4+(pl,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z4--z5;
  pickup pencircle scaled thickline;
  draw fullcircle scaled (2*iso_rad) shifted z2;
  draw fullcircle scaled (2*iso_rad) shifted z3;
enddef;

def isource_var =
  isource;
  noarrowTF;
  pickup pencircle scaled thinline;
  arrow(.5[z2,z3],iso_ara,iso_arb,iso_phi,arr_lt,arr_phi)();
enddef;

def value = % "uberarbeiten
  z0=(0,0);
  z1=z0+(val_lt,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
  z2=val_lft[z0,z1];
  z3=val_rht[z0,z1];
  triangle(z2,abs(z3-z2),val_phi,0);
enddef;

def coil =  %"uberarbeiten
  numeric pl;
  pl:=.5(coi_lt-2coi_num*coi_rad);
  z0=(0,0);
  z1=z0+(pl,0);
  z2=z1+(coi_rad,0);
  for m=1 upto coi_num-1: z[m+2]=z[m+1]+(2coi_rad,0); endfor;
  z[2+coi_num]=z[1+coi_num]+(coi_rad,0);
  z[3+coi_num]=z[2+coi_num]+(pl,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z[2+coi_num]--z[3+coi_num];
  pickup pencircle scaled normalline;
  for m=1 upto coi_num: draw halfcircle scaled 2coi_rad shifted z[m+1]; endfor;
enddef;

def crystal =  %"uberarbeiten
  pickup pensquare scaled normalline;
  numeric pl;
  pl:=.5(cry_lt-2cry_spc-cry_wd);
  z0=(0,0); z1=z0+(pl,0);
  z2=z1+(cry_spc,0);
  z3=z2+(cry_wd,0);
  z4=z3+(cry_spc,0);
  z5=z4+(pl,0);
  z6-z7=z8-z9=z10-z11=z12-z13=(0,cry_ht);
  z2=.5[z6,z7]; z3=.5[z8,z9]; z1=.5[z10,z11]; z4=.5[z12,z13];
  draw z0--z1; draw z4--z5; draw z10--z11; draw z12--z13;
  draw z7--z9--z8--z6--cycle;
enddef;

def inout =  % "uberarbeiten
    z0=(0,0);
    pickup pensquare scaled normalline;
    z2=z0+(ioc_lt,0);
    lft(z1)=z0+(.5ioc_dia,0);
    draw z1--z2;
enddef;

def minout =
  z0=(0,0);
  z1=z0+(ioc_lt,0);
  pickup pensquare scaled normalline;
  arrow(z0,0,ioc_lt,180,ioc_arr,ioc_phi)(pickup pencircle scaled normalline);
enddef;

def ground =                     % Masse z0 z11
  z0=(0,0); x1=x0=x2=x3;
  y0-y1=gnd_ht;
  y1-y2=y2-y3=gnd_spc;
  y4=y1=y10; y2=y6; y3=y8;
  z1=.5[z4,z5];     x5-x4=gnd_wd;
  z1=.5[z10,z11]; x11-x10=GND_wd;
  z2=.5[z6,z7]; x7-x6=gnd_wd*gnd_q;
  z3=.5[z8,z9]; x9-x8=gnd_wd*gnd_q*gnd_q*gnd_q;
enddef;

"Spule";
fourchars(0)(coil)(z[3+coi_num])(coi_ht#,coi_lt#,0);

"Quarz";
twochars(4)(crystal)(.5cry_ht#,cry_lt#,.5cry_ht#);

"Lampe";
twochars(6)(lamp)(cir_ht#,cir_lt#,cir_ht#);

"Kreise mit Anschl"&ditto&"ussen";
twochars(8)(circle)(cir_ht#,cir_lt#,cir_ht#);

"Kreise mit Anschl"&ditto&"ussen variabel";
twochars(10)(circle_var)(cir_ht#,cir_lt#,cir_ht#);

"Stromquelle";
twochars(12)(isource)(iso_ht#,iso_lt#,iso_ht#);

"Stromquelle variabel";
twochars(14)(isource_var)(iso_ht#,iso_lt#,iso_ht#);

"Spannungsquelle";
fourchars(16)(usource)(z3)(uso_ht#,uso_lt#,uso_ht#);

"Spannungsquelle variabel";
fourchars(20)(usource_var)(z3)(uso_ht#,uso_lt#,uso_ht#);

"Schalter";
twochars(24)(switch)(swt_ht#,swt_lt#,0);

"Umschalter";
eightchars(32)(dswitch)(dsw_wd#,.5dsw_ht#,.5dsw_ht#,0);

"Anschl"&ditto&"usse Pfeil";
fourchars(232)
         (minout;)(z1)(.5ioc_ht#,ioc_lt#,.5ioc_ht#);

"Anschl"&ditto&"usse leer";
fourchars(240)
         (inout;
          pickup pencircle scaled thinline;
          draw fullcircle scaled ioc_dia shifted z0;
         )(z2)(.5ioc_ht#,ioc_lt#,.5ioc_ht#);

"Anschl"&ditto&"usse voll";
fourchars(244)
         (inout;
          pickup pencircle scaled ioc_dia;
          draw z0;
         )(z2)(.5ioc_ht#,ioc_lt#,.5ioc_ht#);

"Str"&ditto&"ome";
fourchars(248)(value;)(z1)(val_ht#,val_lt#,val_ht#);

"wwire half R";
beginchar(112,.5lLE#,0pt,0pt);
  z0=(0,0);
  y4-y3=y2-y1=ww_spc;
  x3-x1=.5lLE;
  x0=x1=x2;
  x3=x4;
  y0=.5[y1,y2]=.5[y3,y4];
  pickup pensquare scaled normalline;
  draw z1--z3;
  draw z2--z4;
endchar;

"wwire R";
beginchar(113,1lLE#,0pt,0pt);
  z0=(0,0);
  y4-y3=y2-y1=ww_spc;
  x3-x1=1lLE;
  x0=x1=x2;
  x3=x4;
  y0=.5[y1,y2]=.5[y3,y4];
  pickup pensquare scaled normalline;
  draw z1--z3;
  draw z2--z4;
endchar;

"wwire half L";
beginchar(114,.5lLE#,0pt,0pt);
  z0=(0,0);
  y4-y3=y2-y1=ww_spc;
  x3-x1=.5lLE;
  x0=x3=x4;
  x1=x2;
  y0=.5[y1,y2]=.5[y3,y4];
  pickup pensquare scaled normalline;
  draw z1--z3;
  draw z2--z4;
endchar;

"wwire half U";
beginchar(115,0pt,.5lLE#,0pt);
  z0=(0,0);
  x4-x3=x2-x1=ww_spc;
  y3-y1=.5lLE;
  y0=y1=y2;
  y3=y4;
  x0=.5[x1,x2]=.5[x3,x4];
  pickup pensquare scaled normalline;
  draw z1--z3;
  draw z2--z4;
endchar;

"wwire U";
beginchar(116,0pt,1lLE#,0pt);
  z0=(0,0);
  x4-x3=x2-x1=ww_spc;
  y3-y1=1lLE;
  y0=y1=y2;
  y3=y4;
  x0=.5[x1,x2]=.5[x3,x4];
  pickup pensquare scaled normalline;
  draw z1--z3;
  draw z2--z4;
endchar;

"wwire half D";
beginchar(117,0pt,0pt,.5lLE#);
  z0=(0,0);
  x4-x3=x2-x1=ww_spc;
  y3-y1=.5lLE;
  y0=y3=y4;
  y1=y2;
  x0=.5[x1,x2]=.5[x3,x4];
  pickup pensquare scaled normalline;
  draw z1--z3;
  draw z2--z4;
endchar;


"dashed halfline R";
beginchar(120,.5lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0+(.25lLE,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"dashed line R";
beginchar(121,1lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0+(1lLE,0);
  z2=.25[z0,z1];
  z3=.75[z0,z1];
  pickup pensquare scaled normalline;
  draw z2--z3;
endchar;

"dashed halfline L";
beginchar(122,.5lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0-(.25lLE,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"dashed halfline U";
beginchar(123,0pt,.5lLE#,0pt);
  z0=(0,0);
  z1=z0+(0,.25lLE);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"dashed line U";
beginchar(124,0pt,1lLE#,0pt);
  z0=(0,0);
  z1=z0+(0,1lLE);
  z2=.25[z0,z1];
  z3=.75[z0,z1];
  pickup pensquare scaled normalline;
  draw z2--z3;
endchar;

"dashed halfline D";
beginchar(125,0pt,0pt,.5lLE#);
  z0=(0,0);
  z1=z0-(0,.25lLE);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"Linie horizontal halb R";
beginchar(128,.5lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0+(.5lLE,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"Linie horizontal R";
beginchar(129,1lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0+(1lLE,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"Linie horizontal halb L";
beginchar(130,.5lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0-(.5lLE,0);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"Linie vertikal halb U";
beginchar(131,0pt,.5lLE#,0pt);
  z0=(0,0);
  z1=z0+(0,.5lLE);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"Linie vertikal U";
beginchar(132,0pt,1lLE#,0pt);
  z0=(0,0);
  z1=z0+(0,1lLE);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"Linie vertikal halb D";
beginchar(133,0pt,0pt,.5lLE#);
  z0=(0,0);
  z1=z0-(0,.5lLE);
  pickup pensquare scaled normalline;
  draw z0--z1;
endchar;

"B"&ditto&"undel horizontal";
beginchar(134,0,.8bnd_lt#,0pt);
  z0=(0,0);
  z0=.5[z2,z3];
  z3-z2=(bnd_lt,0) rotated bnd_phi;
  pickup pencircle scaled thinline;
  draw z2--z3;
endchar;

"B"&ditto&"undel vertikal";
beginchar(135,.8bnd_lt#,0pt,0pt);
  z0=(0,0);
  z0=.5[z2,z3];
  z3-z2=(bnd_lt,0) rotated (90-bnd_phi);
  pickup pencircle scaled thinline;
  draw z2--z3;
endchar;

"Linie fett horizontal R";
beginchar(136,.5lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0+(.5lLE,0);
  pickup pensquare scaled 2normalline;
  draw z0--z1;
endchar;

"Linie fett horizontal R";
beginchar(137,1lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0+(1lLE,0);
  pickup pensquare scaled 2normalline;
  draw z0--z1;
endchar;

"Linie fett horizontal halb L";
beginchar(138,.5lLE#,0pt,0pt);
  z0=(0,0);
  z1=z0-(.5lLE,0);
  pickup pensquare scaled 2normalline;
  draw z0--z1;
endchar;

"Linie fett vertikal halb U";
beginchar(139,0pt,.5lLE#,0pt);
  z0=(0,0);
  z1=z0+(0,.5lLE);
  pickup pensquare scaled 2normalline;
  draw z0--z1;
endchar;

"Linie fett vertikal U";
beginchar(140,0pt,1lLE#,0pt);
  z0=(0,0);
  z1=z0+(0,1lLE);
  pickup pensquare scaled 2normalline;
  draw z0--z1;
endchar;

"Linie fett vertikal halb D";
beginchar(141,0pt,0pt,.5lLE#);
  z0=(0,0);
  z1=z0-(0,.5lLE);
  pickup pensquare scaled 2normalline;
  draw z0--z1;
endchar;

"Oscillograph";
beginchar(142,osc_dia#,.5osc_dia#,.5osc_dia#);
  z0=(0,0);
  z1=z0;
  z5=.5[z1,z3]=.5[z2,z4];
  x2=x4;
  y1=y3;
  x3-x1=y4-y2=osc_dia;
  .5osc_gt+osc_spc+osc_stm=.5osc_dia;
  osc_stm=osc_t*osc_gt;
  z6=z1+(osc_stm,0);
  z7=z2+(0,osc_stm);
  z8=z3+(-osc_stm,0);
  z9=z4+(0,-osc_stm);
  z6=.5[z10,z11]; x10=x11; x16-x17=y14-y15=x12-x13=y11-y10=osc_gt;
  z7=.5[z12,z13]; y12=y13;
  z8=.5[z14,z15]; x14=x15;
  z9=.5[z16,z17]; y16=y17;
  pickup pensquare scaled normalline; %drawing style by Andreas Tille
  draw z1--z6;                        %code rewritten by SeTa
  draw z2--z7;
  draw z3--z8;
  draw z4--z9;
  pickup pencircle scaled normalline;
  draw fullcircle scaled osc_dia shifted z5;
  pickup pensquare scaled thickline;
  draw z10--z11;
  draw z12--z13;
  draw z14--z15;
  draw z16--z17;
endchar;

"a small grey elephant: Thanks to Andreas Tille.";
%
% The code is a little bit crazy.
%
LE#:=.03mm#;
define_pixels(LE);
numeric nPnt;
def p(expr px,py) = x[nPnt]:=px*LE; y[nPnt]:=py*LE; nPnt:=nPnt+1 enddef;

beginchar(252,540LE#,265LE#,274LE#);
  pickup pencircle scaled 0.4pt;
  path a, b;
  picture cutpic;
  nPnt:=0;

p(  0,  0);   % copyright by Sebastian Tannert
p(  0, 18);   % Please think of the hard work!
%
p( -2, 46);p( -3, 92);p(  8,117);p( 28,152);
p( 38,171);p( 71,195);p(107,218);p(138,240);p(159,255);p(181,261);
p(193,264);p(211,268);p(231,263);p(249,264);p(273,259);p(292,255);
p(311,249);p(336,240);p(380,222);p(414,208);p(437,198);p(449,193);
p(461,190);p(473,185);p(490,173);p(506,157);p(519,125);p(526, 91);
p(530, 56);p(530, 35);p(523, 17);p(518,  1);p(509,-22);p(511,-46);
p(515,-71);p(514,-96);p(512,-112);p(511,-135);p(507,-150);p(498,-171);
p(485,-184);p(465,-197);p(448,-200);p(429,-194);p(418,-177);p(414,-168);
p(420,-159);p(427,-157);p(435,-163);p(439,-171);p(449,-164);p(461,-165);
p(470,-152);p(476,-139);p(476,-118);p(475,-97);p(465,-76);p(450,-62);
p(442,-50);p(427,-36);p(417,-29);p(409,-27);p(392,-12);p(383,-10);
p(374,-18);p(370,-34);p(363,-58);p(347,-92);p(343,-106);p(341,-126);
p(330,-162);p(323,-196);p(322,-210);p(317,-237);p(327,-257);p(325,-268);
p(310,-270);p(301,-272);p(284,-266);p(269,-258);p(268,-236);p(270,-210);
p(282,-185);p(300,-151);p(315,-119);p(322,-93);p(325,-79);p(326,-63);
p(315,-75);p(303,-101);p(292,-134);p(281,-164);p(269,-189);p(258,-220);
p(259,-250);p(260,-266);p(252,-269);p(235,-260);p(221,-266);p(203,-261);
p(194,-242);p(201,-227);p(206,-213);p(207,-190);p(215,-162);p(222,-147);
p(225,-123);p(229,-96);p(234,-77);p(234,-65);p(236,-47);p(236,-30);
p(236,-12);p(240,6);p(248,19);p(264,37);p(146,41);p(158,24);
p(176,-3);p(188,-29);p(193,-53);p(185,-80);p(175,-106);p(165,-137);
p(152,-173);p(143,-202);p(142,-222);p(136,-232);p(141,-253);p(132,-255);
p(125,-255);p(105,-240);p(91,-239);p(75,-228);p(68,-205);p(70,-178);
p(85,-156);p(96,-127);p(100,-112);p(95,-88);p(79,-62);p(60,-38);
p(48,-16);p(36,18);p(28,63);p(24,41);p(28,17);p(29,-6);p(31,-32);
p(26,-43);p(17,-65);p(15,-83);p(12,-106);p(7,-126);p(0,-141);
p(-9,-147);p(-16,-131);p(-24,-110);p(-22,-94);p(-17,-75);p(-6,-55);
p(-2,-34);p(2,-19);p(190,-63);p(209,-75);p(234,-69);p(31,-32);
p(31,-44);p(26,-67);p(37,-95);p(45,-117);p(43,-158);p(38,-193);
p(25,-224);p(29,-249);p(52,-266);p(71,-264);p(88,-266);p(113,-273);
p(133,-273);p(138,-268);p(132,-255);p(457,48);p(462,30);p(481,21);
p(477,40);p(449,32);p(456,11);p(478,5);p(464,60);p(486,61);
p(499,37);p(363,93);p(352,110);p(348,129);p(358,149);p(386,162);
p(414,173);p(427,178);p(443,167);p(456,157);p(461,142);p(450,126);
p(436,110);p(419,74);p(409,53);p(396,40);p(372,51);p(365,67);
p(358,148);p(375,139);p(387,124);p(401,128);p(411,146);p(418,163);
p(427,168);p(443,167);p(444,161);p(434,152);p(432,135);p(440,124);
p(451,128);p(460,141);p(455,157);p(350,138);p(459,138);p(-30,276);
p(539,-283);p(539,276);p(-30,-283);p(427,-41);p(436,-54);

draw for i:=0 upto 109: z[i]..endfor
z110{up}..z167{curl.7}..z166..z165{curl.7}..z123{down}..
for i:=124 upto 144: z[i]..endfor z145---z146..z147{down}..
for i:=148 upto 164: z[i]..endfor z0;

draw for i:=110 upto 116: z[i].. endfor z117;
draw for i:=118   upto 122: z[i].. endfor z123{down};

draw for i:=168 upto 182: z[i].. endfor z183;


draw for i:=194 upto 210: z[i].. endfor cycle;

draw for i:=211 upto 217: z[i].. endfor z218;

a:= z226..z197..z198..z199..z200..z201..z202..z203..z227;
b:= z226--z227;
vshade(b,a,4,unitsquare scaled 1.8);

a:= z227..z206..z207..z208..z209..z210..z194..
    z195..z196..z226;
b:= z227--z226;
vshade(b,a,4,unitsquare scaled 1.8);

a:= z228--z230;
b:= z231--z229;
vshade(a,b,4,unitsquare);

cutpic=nullpicture;

addto cutpic contour(z228+(0,10)--z230+(10,10)--z229--z231--cycle);

pickup pencircle scaled 0.7pt

addto cutpic contour (for i:=0 upto 109: z[i].. endfor
     z110{up}..z167{curl.7}..z166..z165{curl.7}..z123{down}..
     for i:=124 upto 144: z[i].. endfor z145---z146..z147{down}..
     for i:=148 upto 164: z[i].. endfor cycle) withweight -1;

addto cutpic doublepath
     (for i:=0   upto 109: z[i].. endfor
     z110{up}..z167{curl.7}..z166..z165{curl.7}..z123{down}..
     for i:=124 upto 144: z[i].. endfor z145---z146..z147{down}..
     for i:=148 upto 164: z[i].. endfor z0) withpen currentpen
     withweight -1;

addto cutpic doublepath z232..z233 withpen currentpen withweight -1;

addto cutpic contour (for i:=168 upto 182: z[i].. endfor z183..z146..cycle)
  withpen currentpen withweight -1;

cull cutpic keeping (1,infinity) withweight -3;

addto currentpicture also cutpic;

pickup pencircle scaled .7pt;
draw z184..z185{z186-z184}..z186;
draw z186..z187{z184-z186}..z184;

draw z188..z189..z190;
draw z191..z192..z193;
draw z232..z233;

endchar;


"Masse";
beginchar(253,.5gnd_wd#,0,gnd_ht#+gnd_spc#+gnd_spc#);
  ground
  pickup pensquare scaled normalline;
  draw z0--z1;
  draw z4--z5;
  draw z6--z7;
  draw z8--z9;
endchar;

"MASSE";
beginchar(254,.5GND_wd#,0,gnd_ht#);
  ground
  pickup pensquare scaled normalline;
  draw z0--z1;
  pickup pensquare scaled verythickline;
  draw z10--z11;
endchar;

"Verbindungspunkt";
beginchar(255,cdt_lt#,.5cdt_ht#,.5cdt_ht#);
    pickup pencircle scaled cdt_dia;
    z0=(0,0);
    drawdot z0;
endchar;

end;
%</csyrest>
%
%^^A last update: Tue  02-04-1997
%<*ist>
delim_0 "\\hfill "
delim_t "\\hbox to 7mm{\\hss}"
%</ist>
%<*mfj>
def s=[s0 s2];
    {
    base=plain;
    fonts= csybimos csycirc csydiod csyrest csywidko csysym optic;
    mags=s;
    mode=localfont[300];
    output=pk[@Rr\@f];
    output=tfm[tfm\@f];
    }
%</mfj>
%<*indexhlp>
If you want to generate an index for the circ-package please
run "makeindex" with the style-file "circ.ist" on "circ.idx".

Using EM-TeX the command line is: makeindx -s circ.ist circ.idx

To get the right pagenumbers in the index and the table of
contents, run LaTeX on "circ.drv" and makeindex in the following
way:

latex circ.drv
makeindx -s circ.ist circ.idx
latex circ.drv
makeindx -s circ.ist circ.idx
latex circ.drv
%</indexhlp>
