1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of printlattice</title> |
---|
6 | <meta name="keywords" content="printlattice"> |
---|
7 | <meta name="description" content="PRINTLATTICE - Simple printout of the elements of the model"> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../index.html">Home</a> > <a href="index.html">at</a> > printlattice.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for at <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>printlattice |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
24 | <div class="box"><strong>PRINTLATTICE - Simple printout of the elements of the model</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function varargout = printlattice(varargin) </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">PRINTLATTICE - Simple printout of the elements of the model |
---|
31 | printlattice(THERING,[format,index,'filename']) |
---|
32 | |
---|
33 | Reads THERING and give a simple printout of the elements to standard out |
---|
34 | (screen). If INDEX is specified only those elements in the INDEX will be |
---|
35 | printed out and if FILENAME is specified the output will also be printed |
---|
36 | to file and not printed to standard out (screen). Nothing is returned by |
---|
37 | PRINTLATTICE. |
---|
38 | |
---|
39 | FORMAT determines how the output should look. |
---|
40 | 'element' - element by element simple output (default) |
---|
41 | 'input' - list of unique elements followed by element position |
---|
42 | |
---|
43 | Written by Eugene Tan</pre></div> |
---|
44 | |
---|
45 | <!-- crossreference --> |
---|
46 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
47 | This function calls: |
---|
48 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
49 | </ul> |
---|
50 | This function is called by: |
---|
51 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
52 | </ul> |
---|
53 | <!-- crossreference --> |
---|
54 | |
---|
55 | |
---|
56 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
57 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function varargout = printlattice(varargin)</a> |
---|
58 | 0002 <span class="comment">%PRINTLATTICE - Simple printout of the elements of the model</span> |
---|
59 | 0003 <span class="comment">% printlattice(THERING,[format,index,'filename'])</span> |
---|
60 | 0004 <span class="comment">%</span> |
---|
61 | 0005 <span class="comment">% Reads THERING and give a simple printout of the elements to standard out</span> |
---|
62 | 0006 <span class="comment">% (screen). If INDEX is specified only those elements in the INDEX will be</span> |
---|
63 | 0007 <span class="comment">% printed out and if FILENAME is specified the output will also be printed</span> |
---|
64 | 0008 <span class="comment">% to file and not printed to standard out (screen). Nothing is returned by</span> |
---|
65 | 0009 <span class="comment">% PRINTLATTICE.</span> |
---|
66 | 0010 <span class="comment">%</span> |
---|
67 | 0011 <span class="comment">% FORMAT determines how the output should look.</span> |
---|
68 | 0012 <span class="comment">% 'element' - element by element simple output (default)</span> |
---|
69 | 0013 <span class="comment">% 'input' - list of unique elements followed by element position</span> |
---|
70 | 0014 <span class="comment">%</span> |
---|
71 | 0015 <span class="comment">% Written by Eugene Tan</span> |
---|
72 | 0016 |
---|
73 | 0017 |
---|
74 | 0018 <span class="comment">% parse headers</span> |
---|
75 | 0019 THERING = {}; |
---|
76 | 0020 index = []; |
---|
77 | 0021 filename = <span class="string">''</span>; |
---|
78 | 0022 element = 1; |
---|
79 | 0023 input = 0; |
---|
80 | 0024 <span class="keyword">for</span> i=nargin:-1:1 |
---|
81 | 0025 <span class="keyword">if</span> iscell(varargin{i}) |
---|
82 | 0026 THERING = varargin{i}; |
---|
83 | 0027 <span class="keyword">elseif</span> ischar(varargin{i}) |
---|
84 | 0028 <span class="keyword">switch</span> varargin{i} |
---|
85 | 0029 <span class="keyword">case</span> <span class="string">'element'</span> |
---|
86 | 0030 element = 1; |
---|
87 | 0031 <span class="keyword">case</span> <span class="string">'input'</span> |
---|
88 | 0032 input = 1; |
---|
89 | 0033 <span class="keyword">otherwise</span> |
---|
90 | 0034 filename = varargin{i}; |
---|
91 | 0035 <span class="keyword">end</span> |
---|
92 | 0036 <span class="keyword">elseif</span> isnumeric(varargin{i}) |
---|
93 | 0037 index = varargin{i}; |
---|
94 | 0038 <span class="keyword">else</span> |
---|
95 | 0039 fprintf(<span class="string">'Input parameter number %d ignored\n'</span>,i); |
---|
96 | 0040 <span class="keyword">end</span> |
---|
97 | 0041 <span class="keyword">end</span> |
---|
98 | 0042 |
---|
99 | 0043 |
---|
100 | 0044 <span class="comment">% need to specify thering to use</span> |
---|
101 | 0045 <span class="keyword">if</span> isempty(THERING) |
---|
102 | 0046 <span class="keyword">global</span> THERING |
---|
103 | 0047 <span class="comment">%error('Please specity THERING to use');</span> |
---|
104 | 0048 <span class="keyword">end</span> |
---|
105 | 0049 |
---|
106 | 0050 <span class="comment">% if index is not specified by the user then print all the elements</span> |
---|
107 | 0051 <span class="keyword">if</span> isempty(index) |
---|
108 | 0052 index = 1:length(THERING); |
---|
109 | 0053 <span class="keyword">end</span> |
---|
110 | 0054 |
---|
111 | 0055 <span class="keyword">if</span> isempty(filename) |
---|
112 | 0056 <span class="comment">% standard output</span> |
---|
113 | 0057 fid = 1; |
---|
114 | 0058 <span class="keyword">else</span> |
---|
115 | 0059 <span class="comment">% open file and write to it</span> |
---|
116 | 0060 fid = fopen(filename,<span class="string">'w'</span>); |
---|
117 | 0061 <span class="keyword">end</span> |
---|
118 | 0062 |
---|
119 | 0063 |
---|
120 | 0064 <span class="keyword">if</span> input |
---|
121 | 0065 <span class="comment">% cycle through index and determine unique elements</span> |
---|
122 | 0066 famnames = {}; |
---|
123 | 0067 uniqueindex = []; |
---|
124 | 0068 elementline = {}; |
---|
125 | 0069 <span class="keyword">for</span> i=index |
---|
126 | 0070 elementline{end+1} = THERING{i}.FamName; |
---|
127 | 0071 <span class="keyword">if</span> isempty(strmatch(THERING{i}.FamName,strvcat(famnames))) |
---|
128 | 0072 famnames{end+1,1} = THERING{i}.FamName; |
---|
129 | 0073 uniqueindex(end+1) = i; |
---|
130 | 0074 <span class="keyword">end</span> |
---|
131 | 0075 <span class="keyword">end</span> |
---|
132 | 0076 index = uniqueindex; |
---|
133 | 0077 <span class="keyword">end</span> |
---|
134 | 0078 |
---|
135 | 0079 <span class="comment">% Information header</span> |
---|
136 | 0080 fprintf(fid,<span class="string">'=== Element Definitions ===\n\n'</span>); |
---|
137 | 0081 fprintf(fid,<span class="string">'DRIFT LENGTH\n'</span>); |
---|
138 | 0082 fprintf(fid,<span class="string">'MARKER LENGTH\n'</span>); |
---|
139 | 0083 fprintf(fid,<span class="string">'QUAD LENGTH K\n'</span>); |
---|
140 | 0084 fprintf(fid,<span class="string">'MULTIPOLE LENGTH NORMAL_POLY\n'</span>); |
---|
141 | 0085 fprintf(fid,<span class="string">'BEND LENGTH ANGLE ENTRANCE EXIT NORMAL_POLY\n'</span>); |
---|
142 | 0086 fprintf(fid,<span class="string">'\n\n'</span>); |
---|
143 | 0087 |
---|
144 | 0088 |
---|
145 | 0089 <span class="keyword">for</span> i=index |
---|
146 | 0090 elstring = [sprintf(<span class="string">'%10s '</span>,THERING{i}.FamName) <span class="string">' '</span>]; |
---|
147 | 0091 <span class="keyword">switch</span> THERING{i}.PassMethod |
---|
148 | 0092 <span class="keyword">case</span> {<span class="string">'DriftPass'</span>} |
---|
149 | 0093 elstring = [elstring sprintf(<span class="string">'%10s %10.7f\n'</span>,<span class="string">'DRIFT'</span>,THERING{i}.Length)]; |
---|
150 | 0094 <span class="keyword">case</span> {<span class="string">'IdentityPass'</span>} |
---|
151 | 0095 elstring = [elstring sprintf(<span class="string">'%10s %10.7f\n'</span>,<span class="string">'MARKER'</span>,THERING{i}.Length)]; |
---|
152 | 0096 <span class="keyword">case</span> {<span class="string">'QuadLinearPass'</span>} |
---|
153 | 0097 elstring = [elstring sprintf(<span class="string">'%10s %10.7f %10.7f\n'</span>,<span class="keyword">...</span> |
---|
154 | 0098 <span class="string">'QUAD'</span>,THERING{i}.Length,THERING{i}.PolynomB(2))]; |
---|
155 | 0099 <span class="keyword">case</span> {<span class="string">'StrMPoleSymplectic4Pass'</span> <span class="string">'StrMPoleSymplectic4RadPass'</span>} |
---|
156 | 0100 elstring = [elstring sprintf(<span class="string">'%10s %10.7f '</span>,<span class="string">'MULTIPOLE'</span>,THERING{i}.Length) <span class="keyword">...</span> |
---|
157 | 0101 sprintf(<span class="string">'%10.7f '</span>,THERING{i}.PolynomB) sprintf(<span class="string">'\n'</span>)]; |
---|
158 | 0102 <span class="keyword">case</span> {<span class="string">'BendLinearPass'</span> <span class="string">'BndMPoleSymplectic4Pass'</span>,<span class="string">'BndMPoleSymplectic4RadPass'</span>} |
---|
159 | 0103 elstring = [elstring sprintf(<span class="string">'%10s %10.7f %10.7f %10.7f %10.7f '</span>,<span class="keyword">...</span> |
---|
160 | 0104 <span class="string">'BEND'</span>,THERING{i}.Length,THERING{i}.BendingAngle,THERING{i}.EntranceAngle,THERING{i}.ExitAngle) <span class="keyword">...</span> |
---|
161 | 0105 sprintf(<span class="string">'%10.7f '</span>,THERING{i}.PolynomB) sprintf(<span class="string">'\n'</span>)]; |
---|
162 | 0106 <span class="keyword">otherwise</span> |
---|
163 | 0107 disp([<span class="string">'UNKNOWN ELEMENT'</span> i]) |
---|
164 | 0108 <span class="keyword">end</span> |
---|
165 | 0109 fprintf(fid,<span class="string">'%s'</span>,elstring); |
---|
166 | 0110 <span class="keyword">end</span> |
---|
167 | 0111 |
---|
168 | 0112 <span class="keyword">if</span> input |
---|
169 | 0113 fprintf(fid,<span class="string">'\n\n === Element Arrangement === \n\n'</span>); |
---|
170 | 0114 elstring = <span class="string">''</span>; |
---|
171 | 0115 <span class="keyword">for</span> i=1:length(elementline) |
---|
172 | 0116 elstring = [elstring sprintf(<span class="string">'%10s '</span>,elementline{i})]; |
---|
173 | 0117 <span class="keyword">if</span> mod(i,5) == 0 |
---|
174 | 0118 fprintf(fid,<span class="string">'%s\n'</span>,elstring); |
---|
175 | 0119 elstring = <span class="string">''</span>; |
---|
176 | 0120 <span class="keyword">end</span> |
---|
177 | 0121 <span class="keyword">end</span> |
---|
178 | 0122 fprintf(fid,<span class="string">'%s\n'</span>,elstring); |
---|
179 | 0123 <span class="keyword">end</span> |
---|
180 | 0124 |
---|
181 | 0125 <span class="keyword">if</span> fid ~= 1 |
---|
182 | 0126 fclose(fid); |
---|
183 | 0127 <span class="keyword">end</span></pre></div> |
---|
184 | <hr><address>Generated on Fri 18-May-2007 17:13:39 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
185 | </body> |
---|
186 | </html> |
---|