Debian Codegraph @

texmf-dist/tex/latex/swimgraf/swimgraf.sty

raw
1 % swimgraf.sty
2 % To produce graphs of swim times using PSTricks tools
3 % Martin J. Osborne 2002/5 Version 1.0
4 % http://www.economics.utoronto.ca/osborne
5 % For documentation and files of records, see
6 % http://www.economics.utoronto.ca/osborne/latex
7 % This material is subject to the LaTeX Project Public License. See
8 % http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html
9 % for details.
10
11 \RequirePackage{mathpazo}
12 \RequirePackage{pstricks}
13 \RequirePackage{pstcol,pst-plot}
14 \RequirePackage{keyval}
15
16 \newif\ifswg@eventmismatch
17 \newif\ifswg@continue
18 \newif\ifswg@plotlabel\swg@plotlabeltrue
19 \newif\ifswg@a\swg@afalse
20 \newif\ifswg@b\swg@bfalse
21 \newif\ifswg@c\swg@cfalse
22 \newif\ifswg@d\swg@dfalse
23 \newif\ifswg@e\swg@efalse
24 \newif\ifswg@f\swg@ffalse
25 \newif\ifswg@j\swg@jfalse
26 \newif\ifswg@n\swg@nfalse
27 \newif\ifswg@w\swg@wfalse
28 \newif\ifswg@x\swg@xfalse
29 \newif\ifswg@y\swg@yfalse
30 \newif\ifswg@z\swg@zfalse
31 \newif\ifswg@agerec\swg@agerecfalse
32 \newif\ifswg@screcinrange\swg@screcinrangefalse
33 \newif\ifswg@lcrecinrange\swg@lcrecinrangefalse
34 \newif\ifswg@continue\swg@continuetrue
35 \newif\ifswg@star
36 \newif\ifswg@hyphen
37 \newif\ifswg@qm
38 \newif\ifswg@colon
39 \newif\ifswg@period
40 \newif\ifswg@plus
41 \newif\ifswg@matchfound
42 \newif\ifswg@nmn
43 \newif\ifswg@nmd
44 \newif\ifswg@eventfound
45 \newif\ifswg@inrange
46 \newif\ifswg@indescription\swg@indescriptionfalse
47 \newif\ifswg@putyr\swg@putyrfalse
48
49 \newdimen\swg@monthbaseh
50 \newdimen\swg@titlebaseh
51 \newdimen\swg@tempdima
52 \newdimen\swg@tempdimb
53 \newdimen\swg@tempdimh
54 \newdimen\swg@tempdiml
55 \newdimen\swg@avgw
56 \newdimen\swg@avgh
57 \newdimen\swg@top
58 \newdimen\swg@bottom
59 \newdimen\swg@labelh
60 \newdimen\swg@lpos
61 \newdimen\swg@keyh
62
63 \newcount\swg@htime
64 \newcount\swg@ltime
65 \newcount\swg@lhvytime
66 \newcount\swg@age
67 \newcount\swg@endage
68 \newcount\swg@hvylines
69 \newcount\swg@lghlines
70 \newcount\swg@midy
71 \newcount\swg@day
72 \newcount\swg@month
73 \newcount\swg@year
74 \newcount\swg@daycount
75 \newcount\swg@diycount
76 \newcount\swg@startday
77 \newcount\swg@startyear
78 \newcount\swg@startdiy
79 \newcount\swg@endday
80 \newcount\swg@enddaycount
81 \newcount\swg@enddiy
82 \newcount\swg@bdaydiy
83 \newcount\swg@mid
84 \newcount\swg@i
85 \newcount\swg@recsday
86 \newcount\swg@receday
87 \newcount\swg@agecount
88 \newcount\swg@vlabelsecs
89 \newcount\swg@vlabelmins
90 \newcount\@tempcntc
91 \newcount\@tempcntd
92 \newcount\@tempcntx
93 \newcount\@tempcnty
94 \newcount\@tempcntz
95 \newcount\@tempcntyr
96
97 % If you use the landscape option of the article style and
98 % 'lettersize' paper, the landgraph option for swimgraf defines
99 % margins etc. that seem to allow you to use the whole page
100 % (I don't understand the logic of the topmargin)
101
102 \DeclareOption{landgraph}{\textwidth 11in\textheight 8.5in
103 \oddsidemargin -1in\evensidemargin -1in\topmargin -1.5in}
104
105 % Age-specific standards/records
106 \DeclareOption{a}{\swg@atrue}
107 \DeclareOption{b}{\swg@btrue}
108 \DeclareOption{c}{\swg@ctrue}
109 \DeclareOption{d}{\swg@dtrue}
110 \DeclareOption{e}{\swg@etrue}
111 \DeclareOption{f}{\swg@ftrue}
112 % Age-open standards/records
113 \DeclareOption{j}{\swg@jtrue}
114 \DeclareOption{n}{\swg@ntrue}
115 \DeclareOption{w}{\swg@wtrue}
116 \DeclareOption{x}{\swg@xtrue}
117 \DeclareOption{y}{\swg@ytrue}
118 \DeclareOption{z}{\swg@ztrue}
119
120 \input swimgraf.cfg
121
122 \ProcessOptions
123
124 %---------------------------------------%
125 % LABELS ON VERTICAL AXIS %
126 %---------------------------------------%
127 % Modify PSTricks labels on vertical axis
128 % to convert seconds into minutes and seconds
129
130 \def\psvlabel#1{%
131 \swg@tominssecso#1\relax
132 \swg@timeresult}
133
134 %-------------------------------------%
135 % ERRORS %
136 %-------------------------------------%
137
138 % Following modeled on PSTricks error messages
139 \def\swg@err#1#2{%
140 \begingroup
141 \newlinechar`\^^J
142 \edef\swg@tempc{#2}%
143 \expandafter\errhelp\expandafter{\swg@tempc}%
144 \typeout{^^JSwimgraph error: type \space H <return> \space for immediate help.}%
145 \errmessage{#1}%
146 \endgroup}
147
148 \def\swg@ehpa{%
149 This result will be ignored.^^J
150 Type \space <return> \space to proceed or \space X <return> \space to quit.}
151 \def\swg@ehpb{%
152 Your command was ignored. Will recover best I can.^^J
153 Type \space <return> \space to proceed or \space X <return> \space to quit.}
154 \def\swg@ehpc{%
155 You need to fix this error before proceding.^^J
156 Type \space X <return> \space to quit.}
157
158 %-------------------------------------%
159 % DATE UTILITY %
160 %-------------------------------------%
161 % \swg@date year-month-day defines \swg@year, \swg@month, \swg@day,
162 % \swg@diycount (day in year), and \swg@daycount (index of day since 2000/1/1)
163 % Doesn't account for leap years
164
165 \def\swg@date#1-#2-#3 {%
166 \swg@year=#1
167 \swg@month=#2
168 \swg@day=#3
169 \ifnum\swg@month=1
170 \else\ifnum\swg@month=2
171 \advance\swg@day by31
172 \else\ifnum\swg@month=3
173 \advance\swg@day by59
174 \else\ifnum\swg@month=4
175 \advance\swg@day by90
176 \else\ifnum\swg@month=5
177 \advance\swg@day by120
178 \else\ifnum\swg@month=6
179 \advance\swg@day by151
180 \else\ifnum\swg@month=7
181 \advance\swg@day by181
182 \else\ifnum\swg@month=8
183 \advance\swg@day by212
184 \else\ifnum\swg@month=9
185 \advance\swg@day by243
186 \else\ifnum\swg@month=10
187 \advance\swg@day by273
188 \else\ifnum\swg@month=11
189 \advance\swg@day by304
190 \else\ifnum\swg@month=12
191 \advance\swg@day by334
192 \else
193 \swg@err{The month \the\swg@month\space (in the date #1-#2-#3) does not exist}\swg@ehpc
194 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
195 \swg@diycount=\swg@day
196 % \swg@daycount is index of day since 2000/1/1
197 \swg@daycount=\swg@year
198 \advance\swg@daycount by-2000
199 % doesn't account for leap years
200 \multiply\swg@daycount by365
201 \advance\swg@daycount by\swg@diycount
202 }
203
204 %-------------------------------------%
205 % TIME UTILITIES %
206 %-------------------------------------%
207 % Test time format
208
209 % The function \in@ is in LaTeX
210 % \in@{x}{y} sets \ifin@ true if the string y contains the string x
211 % and false otherwise
212 % Here it is in case it disappears:
213 %\def\in@#1#2{%
214 % \def\in@@##1#1##2##3\in@@{%
215 % \ifx\in@##2\in@false\else\in@true\fi}%
216 % \in@@#2#1\in@\in@@}
217 %\newif\ifin@
218
219 % Given time in various formats, define \swg@mins, \swg@secs, and \swg@msecs.
220 % Formats accepted: m:s.x (put m in \swg@mins, s in \swg@secs, x in \swg@msecs)
221 % m:s (put m in \swg@mins, s in \swg@secs, and 0 in \swg@msecs)
222 % s.x (put s in \swg@secs and x in \swg@msecs)
223 % s (put s in \swg@secs and 0 in \swg@msecs)
224 \def\swg@parsetime#1{%
225 \in@{:}{#1}%
226 \ifin@%
227 \in@{.}{#1}%
228 \ifin@%
229 \swg@t@msm#1\relax%
230 \else%
231 \swg@t@ms#1\relax%
232 \fi%
233 \else%
234 \in@{.}{#1}%
235 \ifin@%
236 \swg@t@sm#1\relax%
237 \else%
238 \swg@t@s#1\relax%
239 \fi%
240 \fi%
241 }
242
243 \def\swg@t@msm#1:#2.#3\relax{%
244 \def\swg@mins{#1}\def\swg@secs{#2}\def\swg@msecs{#3}}
245 \def\swg@t@ms#1:#2\relax{%
246 \def\swg@mins{#1}\def\swg@secs{#2}\def\swg@msecs{0}}
247 \def\swg@t@sm#1.#2\relax{%
248 \def\swg@mins{0}\def\swg@secs{#1}\def\swg@msecs{#2}}
249 \def\swg@t@s#1\relax{%
250 \def\swg@mins{0}\def\swg@secs{#1}\def\swg@msecs{0}}
251
252 % Convert time to seconds.milliseconds (OK for argument to be in this format)
253 % Puts result in \swg@timeresult
254 % Use syntax \expandafter\swg@tosecs\yourtime\relax
255 % Result is in \swg@timeresult
256 \def\swg@tosecs#1\relax{%
257 \swg@parsetime{#1}%
258 \@tempcnta=\swg@mins%
259 \multiply\@tempcnta by60%
260 \advance\@tempcnta by\swg@secs\relax%
261 \edef\swg@timeresult{\the\@tempcnta.\swg@msecs}%
262 }
263
264 % Same, but ignore any milliseconds
265 \def\swg@tosecso#1\relax{%
266 \swg@parsetime{#1}%
267 \@tempcnta=\swg@mins%
268 \multiply\@tempcnta by60%
269 \advance\@tempcnta by\swg@secs\relax%
270 \edef\swg@timeresult{\the\@tempcnta}%
271 }
272
273 % Convert time to minutes:seconds.msecs if minutes > 0, else seconds.msecs
274 % (OK for argument to already be in this format)
275 % Puts result in \swg@timeresult
276 % Use syntax \expandafter\swg@tominssecs\yourtime\relax
277 \def\swg@tominssecs#1\relax{%
278 \swg@parsetime{#1}%
279 \@tempcnta=\swg@secs%
280 \divide\@tempcnta by60%
281 \@tempcntc=\@tempcnta%
282 \advance\@tempcntc by\swg@mins%
283 \multiply\@tempcnta by60%
284 \@tempcntb=\swg@secs%
285 \advance\@tempcntb by-\@tempcnta%
286 \ifnum\@tempcntc=0%
287 \edef\swg@timeresult{\the\@tempcntb.\swg@msecs}%
288 \else\ifnum\@tempcntb<10%
289 \edef\swg@timeresult{\the\@tempcntc:0\the\@tempcntb.\swg@msecs}%
290 \else%
291 \edef\swg@timeresult{\the\@tempcntc:\the\@tempcntb.\swg@msecs}%
292 \fi\fi%
293 }
294
295 % Convert time to minutes:seconds (with minutes = 0 for times less than
296 % a minute)
297 % (OK for argument to already be in this format)
298 % Puts result in \swg@timeresult
299 % Use syntax \expandafter\swg@tominssecso\yourtime\relax
300 \def\swg@tominssecso#1\relax{%
301 \swg@parsetime{#1}%
302 \@tempcnta=\swg@secs%
303 \divide\@tempcnta by60%
304 \@tempcntc=\@tempcnta%
305 \advance\@tempcntc by\swg@mins%
306 \multiply\@tempcnta by60%
307 \@tempcntb=\swg@secs%
308 \advance\@tempcntb by-\@tempcnta%
309 \ifnum\@tempcntb<10%
310 \edef\swg@timeresult{\the\@tempcntc:0\the\@tempcntb}%
311 \else%
312 \edef\swg@timeresult{\the\@tempcntc:\the\@tempcntb}%
313 \fi%
314 }
315
316 %-------------------------------------%
317 % RECORDS %
318 %-------------------------------------%
319 %
320 % \swg@readrec#1#2: read records from file
321 % #1: record type (w, n, ...)
322 % #2: event name [e.g. "50 free"]
323 % Defines
324 % \swg@reclabel (label for record as it appears on graph)
325 % \swg@screc (short course record)
326 % \swg@lcrec (long course record)
327 \def\swg@readrec#1#2
328 {
329 % need \edef here: if #2 is a macro, which it is in this application, it
330 % needs to be expanded when \swg@event is defined
331 \edef\swg@event{#2}
332 % to get rid of CR, which is converted to space, at end of line that is read
333 \endlinechar=-1
334 \openin1=\swg@recfile
335 % first line of file is comment
336 % second line is label (as it appears on graph)
337 \read1 to\@templine
338 \read1 to\swg@reclabel
339 \loop
340 \read1 to\@templine
341 \ifx\@templine\swg@event\swg@eventmismatchfalse
342 \else\swg@eventmismatchtrue\fi
343 \ifeof1\relax\swg@eventmismatchfalse\else\fi
344 \ifswg@eventmismatch
345 \repeat
346 \ifeof1
347 \def\swg@screc{0}
348 \def\swg@lcrec{0}
349 \else
350 \read1 to \swg@sc
351 \read1 to \swg@lc
352 \typeout{\swg@reclabel: \swg@sc\space(SC), \swg@lc\space(LC)}
353 \expandafter\swg@tosecs\swg@sc\relax
354 \edef\swg@screc{\swg@timeresult}
355 \expandafter\swg@tosecs\swg@lc\relax
356 \edef\swg@lcrec{\swg@timeresult}
357 \fi
358 \endlinechar=13
359 \closein1
360 }
361
362 % Draw line, given record type and times, and start and end days.
363 % #1: type of record: w, n, ... (needed to determine color)
364 % #2: SC record time
365 % #3: LC record time
366 % #4: start day
367 % #5: end day
368 \def\swg@xrecline#1#2#3#4#5{%
369 \def\swg@recsccolor{\csname swg@#1sccolor\endcsname}
370 \def\swg@reclccolor{\csname swg@#1lccolor\endcsname}
371 % if no record on file, or if above htime, don't draw any line
372 \edef\@argii{#2}\edef\@argiii{#3}\def\@zero{0}
373 \swg@screcinrangefalse
374 \swg@lcrecinrangefalse
375 \swg@tempdima=\@argii mm
376 \swg@tempdimb=\@argiii mm
377 \swg@tempdimh=\the\swg@htime mm
378 \swg@tempdiml=\the\swg@ltime mm
379 \ifx\@argii\@zero
380 \else
381 \ifdim\swg@tempdima<\swg@tempdimh
382 \ifdim\swg@tempdima>\swg@tempdiml
383 \swg@screcinrangetrue
384 \psline[linecolor=\swg@recsccolor,linewidth=\swg@reclinewidth]%
385 (#4,#2)(#5,#2)
386 \fi
387 \else
388 \ifswg@screcinrange\else\typeout{Note: SC record is out of range.}
389 \fi
390 \fi
391 \ifswg@screcinrange\else\typeout{Note: SC record is out of range.}\fi
392 \fi
393 \ifx\@argiii\@zero
394 \else
395 \ifdim\swg@tempdimb<\swg@tempdimh
396 \ifdim\swg@tempdimb>\swg@tempdiml
397 \swg@lcrecinrangetrue
398 \psline[linecolor=\swg@reclccolor,linewidth=\swg@reclinewidth]%
399 (#4,#3)(#5,#3)
400 \fi
401 \else
402 \ifswg@lcrecinrange\else\typeout{Note: LC record is out of range.}
403 \fi
404 \fi
405 \ifswg@lcrecinrange\else\typeout{Note: LC record is out of range.}
406 \fi
407 \fi
408 \let\psunit=\psxunit
409 \pssetlength{\swg@avgw}{#4}
410 \psaddtolength{\swg@avgw}{#5}
411 \divide\swg@avgw by2
412 \let\psunit=\psyunit
413 % If there is no short course record
414 \ifx\@argii\@zero
415 % then if there is no long course record, do nothing
416 \ifx\@argiii\@zero
417 % and if there is a long course record and it is in the range, label it
418 \else
419 \ifswg@lcrecinrange
420 \def\swg@avghh{#3}
421 \rput*[framesep=0pt](\swg@avgw,\swg@avghh)%
422 {\color{\swg@recsccolor}\swg@reclabel}
423 \fi
424 \fi
425 % If there is a short course record
426 \else
427 % but no long course record, just label the short course record
428 \ifx\@argiii\@zero
429 \ifswg@screcinrange
430 \def\swg@avghh{#2}
431 \rput*(\swg@avgw,\swg@avghh){\color{\swg@recsccolor}\swg@reclabel}
432 \fi
433 % and if there are both long course and short course records, label them
434 \else
435 \ifswg@lcrecinrange
436 \ifswg@screcinrange
437 \pssetlength{\swg@avgh}{#2}
438 \psaddtolength{\swg@avgh}{#3}
439 \divide\swg@avgh by2
440 \rput*(\swg@avgw,\swg@avgh){\color{\swg@recsccolor}\swg@reclabel}
441 \else
442 \def\swg@avghh{#3}
443 \rput*(\swg@avgw,\swg@avghh){\color{\swg@recsccolor}\swg@reclabel}
444 \fi
445 \else
446 \ifswg@screcinrange
447 \def\swg@avghh{#2}
448 \rput*(\swg@avgw,\swg@avghh){\color{\swg@recsccolor}\swg@reclabel}
449 \fi
450 \fi
451 \fi
452 \fi
453 }
454
455 % Read record from file and pass appropriate parameters to \swg@xrecline
456 % #1: record type (w, n, ...)
457 % #2: event name (e.g. "50 free")
458 % #3: start day
459 % #4: end day
460 \def\swg@recline#1#2#3#4{
461 % name of record file: like fw.dat (female), mw.dat (male) for age-open
462 % and fw11.dat (female), mw11.dat (male) for age-specific (age 11)
463 \def\swg@recfile{%
464 \swg@filepath\swg@sex #1\ifswg@agerec\the\swg@agecount\fi.dat}
465 \IfFileExists{\swg@recfile}{
466 \swg@readrec{#1}{#2}
467 \swg@xrecline{#1}{\swg@screc}{\swg@lcrec}{#3}{#4}
468 }{\typeout{FYI: file \swg@recfile\space does not exist.}}
469 }
470 %
471 % Line for age-specific record, series #1 (a, b, ...)
472 % Calls \swg@recline
473 \def\swg@agerecline#1{%
474 \swg@recsday=0
475 \swg@receday=\swg@bdaydiy
476 \advance\swg@receday by-\swg@startdiy
477 \ifnum\swg@startdiy>\swg@bdaydiy\advance\swg@receday by365\fi
478 \swg@agecount=\swg@age
479 \loop
480 \ifnum\swg@agecount=\swg@endage\swg@receday=\swg@endday\fi
481 % \typeout{Swimmer's age: \the\swg@agecount}
482 % \typeout{sday: \the\swg@recsday. eday: \the\swg@receday}
483 % braces enclosing next two lines are essential, because \swg@recline
484 % includes a \loop
485 {\swg@recline{#1}{\swg@dist\swg@strokex}%
486 {\the\swg@recsday}{\the\swg@receday}}
487 \ifnum\swg@agecount<\swg@endage\advance\swg@agecount by1
488 \swg@recsday=\swg@receday
489 \advance\swg@receday by365
490 \repeat
491 }
492
493 %-------------------------------------%
494 % PUTMONTH %
495 %-------------------------------------%
496 % Put month labels on graph
497 % Draws a vertical line at the beginning of the month
498 % and puts the month name.
499 % \@tempcntb counts day in year. Is set to #3 by \swg@putmonth.
500 % \@tempcntd counts day since base date.
501 % \@tempcntc is x-coordinate of vertical line for month
502 % It is initialized at 0; upon entering the macro, its value is the
503 % x-coordinate for the line for the (start of the) previous month. The
504 % macro increases its value to the x-coordinate for the start of the
505 % current month, by
506 % increasing it by #3 - \@tempcntb to a maximum of \swg@endday
507 % #1: month name
508 % #2: # of days in month
509 % #3: # of days in year till 1st of month
510
511 \def\swg@putmonth#1#2#3{
512 \@tempcnta=#3%
513 \advance\@tempcntd by-\@tempcntc
514 \advance\@tempcntc by#3\advance\@tempcntc by-\@tempcntb
515 \advance\@tempcntd by\@tempcntc
516 \ifnum\@tempcntd<\swg@enddaycount
517 % don't put vertical line if first day is first of month
518 \ifnum\@tempcntc>0
519 \ifnum\@tempcnta=0% at start of new year
520 \def\swg@linecolor{\swg@yearlinecolor}%
521 \else
522 \def\swg@linecolor{\swg@monthlinecolor}%
523 \fi
524 \psline[linecolor=\swg@linecolor]%
525 (\the\@tempcntc.5,\swg@ltime)(\the\@tempcntc.5,\swg@htime)%
526 \fi
527 \else\@tempcntc=\swg@endday % \@tempcntc gets stuck at \swg@endday
528 \fi
529 \advance\@tempcntc by#2
530 \ifnum\@tempcntc<\swg@endday
531 \@tempcnta=#2\divide\@tempcnta by2
532 \advance\@tempcntc by-\@tempcnta
533 \rput[B](\@tempcntc,\swg@monthbaseh){#1}
534 \advance\@tempcntc by\@tempcnta
535 \fi
536 \advance\@tempcntc by-#2
537 \@tempcntb=#3}
538
539 %-------------------------------------%
540 % UTILITIES %
541 %-------------------------------------%
542 %
543 % \end is a terminator
544 % Macro checks if second character of line is =. Line must contain at least
545 % 3 characters, else macro will bomb
546 \def\swg@parsedataline#1#2#3\end{
547 \ifx#2=
548 \def\swg@switch{#1}
549 \def\swg@content{#3}
550 \else\swg@err{Bad syntax in file '\swg@datafile' on line '\swg@fileline':^^J\space\space second character is not '='}\swg@ehpc
551 \fi
552 }
553
554 % Parser for line of swimmer's data file giving times
555 \def\swg@parseresultline#1 #2 #3\end{
556 \def\swg@fdist{#1}
557 \def\swg@fstroke{#2}
558 \def\swg@ftime{#3}}
559
560 \def\swg@parsedatline#1 #2\end{
561 \def\swg@datargi{#1}
562 \def\swg@datargii{#2}}
563
564 % Read data from \swg@datafile and transfer appropriate parts of it to
565 % swgs1.tmp (short course times), swgs1d.tmp (corresponding meet names),
566 % swgl1.tmp (long course times), swgl1d.tmp (corresponding meet names),
567 % and also similar files with 2 suffixes [for second series; not yet
568 % implemented]. The time files are in the format to be read by PSTricks'
569 % \readdata, and the meet name files are used by \swg@plotlabel.
570 % #1: event distance. #2: stroke.
571 \def\swg@readdata#1#2
572 {
573 \swg@matchfoundfalse
574 \edef\swg@argi{#1}
575 \edef\swg@argii{#2}
576 % to get rid of CR, which is converted to space, at end of line that is read
577 \endlinechar=-1
578 \openin0=\swg@datafile
579 \immediate\openout1=swgs1.tmp % short course times, series 1
580 \immediate\openout2=swgs1d.tmp % short course descriptions, series 1
581 \immediate\openout3=swgl1.tmp % long course times, series 1
582 \immediate\openout4=swgl1d.tmp % short course descriptions, series 1
583 % first three lines are ignored (name and birthdate have already been read)
584 \read0 to\swg@fileline
585 \read0 to\swg@fileline
586 \read0 to\swg@fileline
587 \read0 to\swg@fileline
588 \loop
589 \read0 to\swg@fileline
590 % Next line necessary because blank line is read at end of file, before
591 % \ifeof0 is true. It also allows all lines starting % to be ignored.
592 \ifx\swg@fileline\@empty
593 \else
594 \expandafter\swg@parsedataline\swg@fileline\end
595 \if\swg@switch m
596 \ifswg@eventfound\swg@txdata\fi
597 \let\swg@meetname=\swg@content
598 %\typeout{Meet: \swg@meetname}
599 \else\if\swg@switch d
600 \ifswg@eventfound\swg@txdata\fi
601 \let\swg@meetdate=\swg@content
602 %\typeout{Date: \swg@meetdate}
603 \else\if\swg@switch c
604 \global\let\swg@fcourse=\swg@content
605 \else\if\swg@switch n
606 \global\let\swg@s@graphnote=\swg@content
607 \else\if\swg@switch r
608 \ifswg@eventfound\swg@txdata\fi
609 \global\let\swg@descmod=\swg@switch
610 \swg@checkdata
611 \else\if\swg@switch u
612 \ifswg@eventfound\swg@txdata\fi
613 \global\let\swg@descmod=\swg@switch
614 \swg@checkdata
615 \else\if\swg@switch R
616 \ifswg@eventfound\swg@txdata\fi
617 \global\let\swg@descmod=\swg@switch
618 \swg@checkdata
619 \fi\fi\fi\fi\fi\fi\fi
620 \fi
621 \ifeof0\relax\swg@continuefalse\else\swg@continuetrue\fi
622 \ifswg@continue
623 \repeat
624 \endlinechar=13
625 \ifswg@eventfound\swg@txdata\fi
626 \closein0
627 \immediate\closeout1
628 \immediate\closeout2
629 \immediate\closeout3
630 \immediate\closeout4
631 \ifswg@matchfound\else
632 \swg@err{No data for event '#1 #2' in date range requested}\swg@ehpc
633 \fi
634 }
635
636 % Check if result is for right event and within date range, in which case
637 % extract variables and set \swg@eventfound true.
638 % Called by \swg@readdata, which defines relevant variables.
639 \def\swg@checkdata{%
640 \expandafter\swg@parseresultline\swg@content\end
641 %\typeout{Event \swg@fdist\space\swg@fstroke\space\swg@fcourse\space\swg@ftime}
642 \ifx\swg@argi\swg@fdist
643 \ifx\swg@argii\swg@fstroke
644 % Check if date is in right range, and if so create right variables
645 % to write to swgsi.tmp or swgli.tmp (using \swg@txdata)
646 \expandafter\swg@date \swg@meetdate {}
647 \ifnum\swg@daycount>\swg@startday
648 \ifnum\swg@daycount<\swg@enddaycount
649 \swg@matchfoundtrue
650 \advance\swg@daycount by-\swg@startday
651 \advance\swg@daycount by1%
652 \expandafter\swg@tosecs\swg@ftime\relax%
653 % CANNOT write \let\swg@ftime=\swg@timeresult on next line (why not??)
654 \global\let\swg@xtime=\swg@timeresult
655 \global\swg@eventfoundtrue
656 % Reset switches that do not persist between events
657 \gdef\swg@s@graphnote{}
658 \fi
659 \fi
660 \fi
661 \fi
662 }
663
664 % Transfer data to files to be read by PSTricks macro.
665 % Called by \swg@readdata, which defines relevant variables
666 \def\swg@txdata{%
667 \if\swg@fcourse s
668 \immediate\write1{\the\swg@daycount\space\swg@xtime}
669 \ifx\swg@s@graphnote\@empty
670 \immediate\write2{\swg@descmod\space\swg@meetname}
671 \else
672 \immediate\write2{%
673 \swg@descmod\space\swg@meetname\space(\swg@s@graphnote)}
674 \fi
675 \else\if\swg@fcourse l
676 \immediate\write3{\the\swg@daycount\space\swg@xtime}
677 \ifx\swg@s@graphnote\@empty
678 \immediate\write4{\swg@descmod\space\swg@meetname}
679 \else
680 \immediate\write4{%
681 \swg@descmod\space\swg@meetname\space(\swg@s@graphnote)}
682 \fi
683 \else
684 \swg@err{'\swg@fcourse' is not a legal course length for the event '\swg@fdist\space\swg@fstroke'^^J
685 \space at the meet '\swg@meetname' (must be 's' or 'l')}\swg@ehpa
686 \fi\fi
687 \global\swg@eventfoundfalse
688 }
689
690 % If file #1.tmp exists, transfer appropriate data from it to swgtime.tmp,
691 % read it into \swg@times, and plot it and label points if requested
692 \def\swg@readplot#1#2{
693 \IfFileExists{#1.tmp}{
694 \readdata{\swg@times}{#1.tmp}
695 \dataplot[plotstyle=line,linecolor=#2,linewidth=\swg@linewidth]%
696 {\swg@times}
697 \dataplot[plotstyle=dots,dotstyle=square*,linecolor=#2,%
698 linewidth=\swg@linewidth]{\swg@times}
699 \ifswg@plotlabel\swg@plotlabel{#1}\fi
700 }{}
701 }
702
703 % Puts labels (vertically) on swimmer's graph, getting them from file
704 % created by \swg@readdata
705 \def\swg@plotlabel#1{
706 \endlinechar=-1
707 \openin1=#1.tmp
708 \openin2=#1d.tmp
709 \loop
710 \read1 to\@templine
711 \read2 to\swg@desc
712 \ifx\@templine\@empty
713 \else
714 \expandafter\swg@parsedatline\swg@desc\end
715 \edef\swg@desc{\swg@datargii}
716 \if\swg@datargi u
717 \gdef\swg@labelpos{r}
718 \gdef\swg@sign{-}
719 \else\if\swg@datargi R
720 \gdef\swg@labelpos{0}
721 \gdef\swg@sign{}
722 \else\if\swg@datargi r
723 \gdef\swg@labelpos{l}
724 \gdef\swg@sign{}
725 \fi\fi\fi
726 % labelpos 0 means no label
727 \if\swg@labelpos 0
728 \else
729 \expandafter\swg@parsedatline\@templine\end
730 \pssetlength{\swg@lpos}{\swg@datargii}
731 \psaddtolength{\swg@lpos}{\swg@sign\swg@labelvsep}
732 \rput[\swg@labelpos]{90}(\swg@datargi,\swg@lpos)%
733 {\color{\swg@labelcolor}\swg@labelfontsize\swg@desc}
734 \fi
735 \fi
736 \ifeof1\relax\swg@continuefalse\else\swg@continuetrue\fi
737 \ifswg@continue
738 \repeat
739 \closein1
740 \closein2
741 \endlinechar=13
742 }
743
744 \def\swg@back{back}
745 \def\swg@breast{breast}
746 \def\swg@fly{fly}
747 \def\swg@free{free}
748 \def\swg@IM{IM}
749 \def\swg@FR{FR} % free relay
750 \def\swg@MR{MR} % medley relay
751
752 %-------------------------------------%
753 % SWIMGRAPH %
754 %-------------------------------------%
755 %
756 % \swimgraph[options]{distance stroke}{startdate}{enddate}{lowtime}{hightime}%
757 % #1 #2 #3 #4 #5
758 % options: any legal arguments for \psset
759 % distance: 50, 100, 200, 400, 800, 1500, 4x50, 4x100
760 % stroke: breast, fly, free, back, IM, FR, MR
761 % startdate: year-month-day
762 % enddate: year-month-day
763 % lowtime: lowest time for y axis, in seconds or minutes:seconds
764 % hightime: highest time for y axis, in seconds or minutes:seconds
765
766 \define@key{swimgraph}{xunit}{\psset{xunit=#1}}
767 \define@key{swimgraph}{yunit}{\psset{yunit=#1}}
768 \define@key{swimgraph}{framesep}{\psset{framesep=#1}}
769 \define@key{swimgraph}{nolabels}[true]{\swg@plotlabelfalse}
770 \define@key{swimgraph}{datafile}{\def\swg@datafile{#1}}
771 \define@key{swimgraph}{recordpath}{\def\swg@filepath{#1}}
772 \define@key{swimgraph}{wsccolor}{\def\swg@wsccolor{#1}}
773 \define@key{swimgraph}{wlccolor}{\def\swg@wlccolor{#1}}
774 \define@key{swimgraph}{xsccolor}{\def\swg@xsccolor{#1}}
775 \define@key{swimgraph}{xlccolor}{\def\swg@xlccolor{#1}}
776 \define@key{swimgraph}{ysccolor}{\def\swg@ysccolor{#1}}
777 \define@key{swimgraph}{ylccolor}{\def\swg@ylccolor{#1}}
778 \define@key{swimgraph}{zsccolor}{\def\swg@zsccolor{#1}}
779 \define@key{swimgraph}{zlccolor}{\def\swg@zlccolor{#1}}
780 \define@key{swimgraph}{jsccolor}{\def\swg@jsccolor{#1}}
781 \define@key{swimgraph}{jlccolor}{\def\swg@jlccolor{#1}}
782 \define@key{swimgraph}{nsccolor}{\def\swg@nsccolor{#1}}
783 \define@key{swimgraph}{nlccolor}{\def\swg@nlccolor{#1}}
784 \define@key{swimgraph}{asccolor}{\def\swg@asccolor{#1}}
785 \define@key{swimgraph}{alccolor}{\def\swg@alccolor{#1}}
786 \define@key{swimgraph}{bsccolor}{\def\swg@bsccolor{#1}}
787 \define@key{swimgraph}{blccolor}{\def\swg@blccolor{#1}}
788 \define@key{swimgraph}{csccolor}{\def\swg@csccolor{#1}}
789 \define@key{swimgraph}{clccolor}{\def\swg@clccolor{#1}}
790 \define@key{swimgraph}{dsccolor}{\def\swg@dsccolor{#1}}
791 \define@key{swimgraph}{dlccolor}{\def\swg@dlccolor{#1}}
792 \define@key{swimgraph}{esccolor}{\def\swg@esccolor{#1}}
793 \define@key{swimgraph}{elccolor}{\def\swg@elccolor{#1}}
794 \define@key{swimgraph}{fsccolor}{\def\swg@rsccolor{#1}}
795 \define@key{swimgraph}{flccolor}{\def\swg@flccolor{#1}}
796 \define@key{swimgraph}{sccolor}{\def\swg@sccolor{#1}}
797 \define@key{swimgraph}{lccolor}{\def\swg@lccolor{#1}}
798 \define@key{swimgraph}{labelcolor}{\def\swg@labelcolor{#1}}
799 \define@key{swimgraph}{monthlinecolor}{\def\swg@monthlinecolor{#1}}
800 \define@key{swimgraph}{yearlinecolor}{\def\swg@yearlinecolor{#1}}
801 \define@key{swimgraph}{oneseclinecolor}{\def\swg@oneseclinecolor{#1}}
802 \define@key{swimgraph}{fiveseclinecolor}{\def\swg@fiveseclinecolor{#1}}
803 \define@key{swimgraph}{labelfontsize}{\def\swg@labelfontsize{#1}}
804 \define@key{swimgraph}{keyvsep}{\def\swg@keyvsep{#1}}
805 \define@key{swimgraph}{monthvsep}{\def\swg@monthvsep{#1}}
806 \define@key{swimgraph}{yearvsep}{\def\swg@yearvsep{#1}}
807 \define@key{swimgraph}{titlevsep}{\def\swg@titlevsep{#1}}
808 \define@key{swimgraph}{labelvsep}{\def\swg@labelvsep{#1}}
809 \define@key{swimgraph}{tlabelpos}{\def\swg@tlabelpos{#1}}
810 \define@key{swimgraph}{linewidth}{\def\swg@linewidth{#1}}
811 \define@key{swimgraph}{reclinewidth}{\def\swg@reclinewidth{#1}}
812
813 \pagestyle{empty}
814
815 \def\swimgraph{%
816 \@ifnextchar[{\swg@opt}{\swg@noopt}}
817
818 \def\swg@opt[#1]#2#3#4#5#6{%
819 % \psset{#1}
820 \setkeys{swimgraph}{#1}
821 % set unit equal to yunit (so that \pssetlength uses psyunit---used to
822 % position labels and titles).
823 \let\psunit=\psyunit
824 \swg@main{#2}{#3}{#4}{#5}{#6}}
825
826 \def\swg@noopt#1#2#3#4#5{\swg@main{#1}{#2}{#3}{#4}{#5}}
827
828 \def\swg@main#1#2#3#4#5{%
829 % default: short course
830 \def\swg@fcourse{s}
831 \def\swg@s@graphnote{}
832 %
833 %.....................................%
834 % Basic set up %
835 %.....................................%
836 %
837 % start date
838 \swg@date #2
839 \swg@age=\swg@year
840 \swg@startday=\swg@daycount
841 \swg@startdiy=\swg@diycount
842 \swg@startyear=\swg@year
843 %
844 % end date
845 \swg@date #3
846 \swg@endage=\swg@year
847 \swg@endday=\swg@daycount
848 \swg@enddaycount=\swg@daycount
849 \swg@enddiy=\swg@diycount
850 \advance\swg@endday by-\swg@startday
851
852 %\typeout{Endday: \the\swg@endday}
853 %
854 \ifnum\swg@startday>\swg@enddaycount
855 \swg@err{Starting date is after ending date}\swg@ehpc
856 \fi
857
858 % open data file and get swimmer's name and date of birth
859 % (for use with records)
860 \openin1=\swg@datafile
861 \endlinechar=-1
862 % first line is comment---ignored
863 \read1 to\swg@fileline
864 % second line is swimmer's name
865 \read1 to\swg@name
866 % third line is swimmer's name
867 \read1 to\swg@sex
868 % fourth line is swimmer's date of birth
869 \read1 to\swg@dob
870 \endlinechar=13
871 \closein1
872
873 \typeout{Swimmer's name: \swg@name. Date of birth: \swg@dob.}
874
875 % swimmer's birthdate
876 \expandafter\swg@date \swg@dob {}
877 \swg@bdaydiy=\swg@diycount
878 \def\swg@bday{\the\swg@diycount}
879 \advance\swg@age by-\swg@year
880 \ifnum\swg@startdiy<\swg@diycount\advance\swg@age by-1\fi
881 \advance\swg@endage by-\swg@year
882 \ifnum\swg@enddiy<\swg@diycount\advance\swg@endage by-1\fi
883
884 \swg@parsedatline#1\end
885 \let\swg@dist=\swg@datargi
886 \let\@@swimstroke=\swg@datargii
887
888 \ifx\@@swimstroke\swg@breast\def\swg@stroke{breast stroke}%
889 \def\swg@strokex{ breast}
890 \else\ifx\@@swimstroke\swg@fly\def\swg@stroke{butterfly}%
891 \def\swg@strokex{ fly}
892 \else\ifx\@@swimstroke\swg@free\def\swg@stroke{freestyle}%
893 \def\swg@strokex{ free}
894 \else\ifx\@@swimstroke\swg@back\def\swg@stroke{backstroke}%
895 \def\swg@strokex{ back}
896 \else\ifx\@@swimstroke\swg@IM\def\swg@stroke{IM}%
897 \def\swg@strokex{ IM}
898 \else\ifx\@@swimstroke\swg@FR\def\swg@stroke{Free Relay}%
899 \def\swg@strokex{ FR}
900 \else\ifx\@@swimstroke\swg@MR\def\swg@stroke{Medley Relay}%
901 \def\swg@strokex{ MR}
902 \else
903 \swg@err{What stroke is '\@@swimstroke'?\space\space I don't know it}\swg@ehpc
904 \fi\fi\fi\fi\fi\fi\fi
905
906 \def\swg@t{#4}
907 \expandafter\swg@tosecso\swg@t\relax
908 \swg@ltime=\swg@timeresult
909
910 \def\swg@t{#5}
911 \expandafter\swg@tosecso\swg@t\relax
912 \swg@htime=\swg@timeresult
913
914 \pssetlength{\swg@monthbaseh}{\the\swg@ltime\psyunit}
915 \psaddtolength{\swg@monthbaseh}{-\swg@monthvsep}
916
917 % number of light lines
918 \swg@lghlines=\swg@htime
919 \advance\swg@lghlines by-\swg@ltime
920
921 % number of heavy lines (5 second intervals)
922 \swg@hvylines=\swg@lghlines
923 \divide\swg@hvylines by5
924
925 \swg@midy=\swg@htime
926 \advance\swg@midy by\swg@ltime
927 \divide\swg@midy by2
928
929 %.....................................%
930 % Beginning of \pspicture %
931 %.....................................%
932 \pssetlength{\swg@top}{\swg@htime}
933 \psaddtolength{\swg@top}{\swg@keyvsep}
934 % \swg@top isn't quite right---equal to middle height of key, so add a bit
935 \psaddtolength{\swg@top}{1.6mm}
936 \pssetlength{\swg@bottom}{\swg@ltime}
937 \psaddtolength{\swg@bottom}{-\swg@monthvsep}
938 \psaddtolength{\swg@bottom}{-\swg@yearvsep}
939 \psaddtolength{\swg@bottom}{-\swg@titlevsep}
940
941 \vspace*{\fill}
942
943 \begin{center}
944 % \fbox for debugging size of picture
945 % \fboxsep 0pt
946 % \fbox{
947 \begin{pspicture}(-\swg@tlabelpos,\swg@bottom)(\swg@endday,\swg@top)
948 %.....................................%
949 % Horizontal lines on graph and axes %
950 %.....................................%
951 % Lines every second
952 \multido{\i=\swg@ltime+1}{\swg@lghlines}%
953 {\psline[linecolor=\swg@oneseclinecolor,linewidth=0.4pt]%
954 (0,\i)(\swg@endday,\i)}
955 % Lines at multiples of 5 second
956 \swg@lhvytime=\swg@ltime
957 \divide\swg@lhvytime by 5
958 \multiply\swg@lhvytime by 5
959 \advance\swg@lhvytime by 5
960 \multido{\i=\swg@lhvytime+5}{\swg@hvylines}%
961 {\psline[linecolor=\swg@fiveseclinecolor]%
962 (0,\i)(\swg@endday,\i)}
963 % Axes
964 \psaxes[axesstyle=frame,Dx=50,Oy=\the\swg@lhvytime,Dy=5,%
965 tickstyle=bottom,labels=y,ticks=y]%
966 (0.5,\swg@lhvytime)(0.5,\swg@ltime)(\swg@endday,\swg@htime)
967 % Because of the offset in \psaxes, so that it starts numbering at the
968 % right point, we won't get a line at the lowest time, so put one
969 \psline(\swg@endday,\swg@htime)(\swg@endday,\swg@ltime)%
970 (0.5,\swg@ltime)(0.5,\swg@htime)
971
972 %...................................................................%
973 % Vertical lines indicating month divisions; month and year labels %
974 %...................................................................%
975 % Arguments of \swg@putmonth: month name, # of days in month,
976 % # of days in year to 1st day of month.
977 % Goes through loop till December, but \swg@putmonth does something only
978 % if endday hasn't been reached.
979 \@tempcntb=\swg@startdiy
980 \@tempcntc=0 % x-coordinate
981 \@tempcntx=0 % x-coordinate of beginning of year
982 \@tempcntd=\swg@startday
983 \@tempcntyr=\swg@startyear
984 % If startdiy > 335, no month label (not even Dec) will be printed, so first
985 % year printed will be next year
986 \ifnum\@tempcntb>335\advance\@tempcntyr by1\fi
987 \loop
988 \ifnum\@tempcntb<2\swg@putmonth{Jan}{31}{0}\fi
989 \ifnum\@tempcntb<33\swg@putmonth{Feb}{28}{31}\fi
990 \ifnum\@tempcntb<61\swg@putmonth{Mar}{31}{59}\fi
991 \ifnum\@tempcntb<92\swg@putmonth{Apr}{30}{90}\fi
992 \ifnum\@tempcntb<122\swg@putmonth{May}{31}{120}\fi
993 \ifnum\@tempcntb<153\swg@putmonth{Jun}{30}{151}\fi
994 \ifnum\@tempcntb<183\swg@putmonth{Jul}{31}{181}\fi
995 \ifnum\@tempcntb<214\swg@putmonth{Aug}{31}{212}\fi
996 \ifnum\@tempcntb<245\swg@putmonth{Sep}{30}{243}\fi
997 \ifnum\@tempcntb<275\swg@putmonth{Oct}{31}{273}\fi
998 \ifnum\@tempcntb<306\swg@putmonth{Nov}{30}{304}\fi
999 \ifnum\@tempcntb<336\swg@putmonth{Dec}{31}{334}\fi
1000 \ifnum\@tempcntb<367\swg@putmonth{}{31}{365}
1001 % Year label
1002 \@tempcnty=\@tempcntc
1003 \swg@mid=\@tempcnty\advance\swg@mid by\@tempcntx
1004 \divide\swg@mid by2
1005 \@tempcntz=\@tempcnty\advance\@tempcntz by-\@tempcntx
1006 % put yr label only if at least 30 days of yr present and x=0 or at least
1007 % 32 days of year present (case of Jan at end of plot)
1008 \ifnum\@tempcntz>29\ifnum\@tempcntx=0\relax\swg@putyrtrue\fi\fi
1009 \ifnum\@tempcntz>31\relax\swg@putyrtrue\fi
1010 \ifswg@putyr
1011 \pssetlength{\swg@labelh}{\swg@monthbaseh}
1012 \psaddtolength{\swg@labelh}{-\swg@yearvsep}
1013 \rput[B](\swg@mid,\swg@labelh){\textbf{\the\@tempcntyr}}
1014 \fi
1015 \swg@putyrfalse
1016 \advance\@tempcntyr by 1\fi
1017 \ifnum\@tempcntd<\swg@enddaycount
1018 \@tempcntx=\@tempcnty
1019 \advance\@tempcntb by-365
1020 \repeat
1021
1022 %..........%
1023 % Records %
1024 %..........%
1025 \typeout{Event: \swg@dist\swg@strokex}
1026 % Age-independent standards/records
1027 % National record
1028 \ifswg@n\swg@recline{n}{\swg@dist\swg@strokex}{0}{\the\swg@endday}\fi
1029 % World record
1030 \ifswg@w\swg@recline{w}{\swg@dist\swg@strokex}{0}{\the\swg@endday}\fi
1031 % Other records
1032 \ifswg@j\swg@recline{j}{\swg@dist\swg@strokex}{0}{\the\swg@endday}\fi
1033 \ifswg@x\swg@recline{x}{\swg@dist\swg@strokex}{0}{\the\swg@endday}\fi
1034 \ifswg@y\swg@recline{y}{\swg@dist\swg@strokex}{0}{\the\swg@endday}\fi
1035 \ifswg@z\swg@recline{z}{\swg@dist\swg@strokex}{0}{\the\swg@endday}\fi
1036
1037 % Age-dependent standards/records
1038 \ifswg@a\swg@agerectrue\swg@agerecline{a}\fi
1039 \ifswg@b\swg@agerectrue\swg@agerecline{b}\fi
1040 \ifswg@c\swg@agerectrue\swg@agerecline{c}\fi
1041 \ifswg@d\swg@agerectrue\swg@agerecline{d}\fi
1042 \ifswg@e\swg@agerectrue\swg@agerecline{e}\fi
1043 \ifswg@f\swg@agerectrue\swg@agerecline{f}\fi
1044
1045 \swg@agerecfalse
1046
1047 %...........................%
1048 % Graph of swimmer's times %
1049 %...........................%
1050 % Read swimmer's times from file
1051 \swg@readdata{\swg@dist}{\@@swimstroke}
1052
1053 % Plot times
1054 \swg@i=1
1055 \loop
1056 \swg@readplot{swgs\the\swg@i}{\swg@sccolor}
1057 \swg@readplot{swgl\the\swg@i}{\swg@lccolor}
1058 \ifnum\swg@i<4\advance\swg@i by1
1059 \repeat
1060
1061 %..........................................%
1062 % Key at top and labels at side and bottom %
1063 %..........................................%
1064 \divide\swg@endday by2
1065 \pssetlength{\swg@keyh}{\the\swg@htime\psyunit}
1066 \addtolength{\swg@keyh}{\swg@keyvsep}
1067
1068 % key giving SC and LC colors---on top of graph
1069 \def\swg@key{
1070 \psline[linecolor=\swg@sccolor,linewidth=\swg@linewidth](-45,0)(-25,0)
1071 \rput*[l](-23,0){SC}
1072 \psline[linecolor=\swg@lccolor,linewidth=\swg@linewidth](7,0)(27,0)
1073 \rput*[l](29,0){LC}
1074 }
1075
1076 \rput(\swg@endday,\swg@keyh){\swg@key}
1077
1078 % label at side
1079 \rput{90}(-\swg@tlabelpos,\swg@midy){time}
1080
1081 % label at bottom
1082 \psaddtolength{\swg@labelh}{-\swg@titlevsep}
1083 \rput[B](\the\swg@endday,\swg@labelh)%
1084 {\large\textbf{\swg@name's times for {\swg@dist}m \swg@stroke}}
1085
1086 \end{pspicture}
1087 % } % end of \fbox
1088 \end{center}
1089
1090 \vspace*{\fill}
1091
1092 }
1093
1094 %-------------------------------------%
1095 % SWIMTEXT %
1096 %-------------------------------------%
1097
1098 % Formats details of result (giving winning time, winner, etc. as specified
1099 % in data file
1100 \def\swg@makeresult{
1101 % convert times to mins:secs.msecs.
1102 \expandafter\swg@tominssecs\swg@ftime\relax
1103 % CANNOT write \let\swg@ftime=\swg@timeresult on next line (why not??)
1104 \let\swg@xtime=\swg@timeresult
1105 % start of item
1106 \item[\swg@fdist m \swg@fstroke
1107 \ifx\swg@s@age\@empty\else\ (\swg@s@age)\fi
1108 \if\swg@fcourse s
1109 (S):
1110 \else\if\swg@fcourse l
1111 (L):
1112 \else
1113 \typeout{Note: '\swg@fcourse' is unknown course length (must be 's' or 'l'}
1114 \fi\fi
1115 ] \swg@xtime
1116 \ifx\swg@s@place\@empty
1117 \else
1118 \ \ -\ \ \swg@s@place
1119 \fi
1120 \ifx\swg@s@ageplace\@empty
1121 \else
1122 \ (\swg@s@ageplace)
1123 \fi
1124 \ifx\swg@s@type\@empty
1125 \else
1126 \par \swg@s@type
1127 \fi
1128 \ifx\swg@s@wintime\@empty
1129 \else
1130 \par Winning time: \swg@s@wintime.
1131 \fi
1132 \ifx\swg@s@first\@empty
1133 \else
1134 \par First: \swg@s@first.
1135 \fi
1136 \ifx\swg@s@second\@empty
1137 \else
1138 \ifx\swg@s@first\@empty
1139 \par
1140 \fi
1141 Second: \swg@s@second.
1142 \fi
1143 \ifx\swg@s@third\@empty
1144 \else
1145 \ifx\swg@s@first\@empty
1146 \ifx\swg@s@second\@empty
1147 \par
1148 \fi\fi
1149 Third: \swg@s@third.
1150 \fi
1151 \ifx\swg@s@fourth\@empty
1152 \else
1153 \ifx\swg@s@first\@empty
1154 \ifx\swg@s@second\@empty
1155 \ifx\swg@s@third\@empty
1156 \par
1157 \fi\fi\fi
1158 Fourth: \swg@s@fourth.
1159 \fi
1160 \ifx\swg@s@other\@empty
1161 \else
1162 \par \swg@s@other
1163 \fi%
1164 \global\swg@eventfoundfalse
1165 }
1166
1167 % Output any pending result and get new result details.
1168 % Called by \swimtext.
1169 \def\swg@eventx{%
1170 % Output any accumulated result
1171 \ifswg@eventfound\swg@makeresult\fi
1172 \expandafter\swg@parseresultline\swg@content\end
1173 \global\swg@eventfoundtrue
1174 \gdef\swg@s@place{}
1175 \gdef\swg@s@ageplace{}
1176 \gdef\swg@s@wintime{}
1177 \gdef\swg@s@first{}
1178 \gdef\swg@s@second{}
1179 \gdef\swg@s@third{}
1180 \gdef\swg@s@fourth{}
1181 \gdef\swg@s@type{}
1182 \gdef\swg@s@other{}
1183 }
1184
1185 \define@key{swimtext}{datafile}{\def\swg@datafile{#1}}
1186
1187 % Main text macro, which produces a document using the information in the
1188 % data file.
1189
1190 \def\swimtext{%
1191 \@ifnextchar[{\swg@textopt}{\swg@textnoopt}}
1192
1193 \def\swg@textopt[#1]#2#3{%
1194 \setkeys{swimtext}{#1}
1195 \swg@textmain{#2}{#3}}
1196
1197 \def\swg@textnoopt#1#2{\swg@textmain{#1}{#2}}
1198
1199 \def\swg@textmain#1#2{%
1200 % default: short course
1201 \def\swg@fcourse{s}
1202 \def\swg@s@age{}
1203
1204 % start date
1205 \swg@date #1
1206 \swg@age=\swg@year
1207 \swg@startday=\swg@daycount
1208 \swg@startdiy=\swg@diycount
1209 \swg@startyear=\swg@year
1210
1211 % end date
1212 \swg@date #2
1213 \swg@endage=\swg@year
1214 \swg@endday=\swg@daycount
1215 \swg@enddaycount=\swg@daycount
1216 \swg@enddiy=\swg@diycount
1217 \advance\swg@endday by-\swg@startday
1218
1219 \ifnum\swg@startday>\swg@enddaycount
1220 \swg@err{Starting date is after ending date}\swg@ehpc
1221 \fi
1222
1223 \endlinechar=-1
1224 \openin0=\swg@datafile
1225 % first line is comment
1226 \read0 to\swg@fileline
1227 \read0 to\swg@name
1228 \read0 to\swg@sex
1229 \read0 to\swg@dob
1230
1231 \begin{center}\large\textbf{\swg@name's times at meets between\\#1 and #2}\end{center}
1232
1233 \global\swg@eventfoundfalse
1234 \loop
1235 \read0 to\swg@fileline
1236 % Next line necessary because blank line is read at end of file, before
1237 % \ifeof0 is true. It also allows all lines starting % to be ignored.
1238 \ifx\swg@fileline\@empty
1239 \else
1240 \expandafter\swg@parsedataline\swg@fileline\end
1241 \if\swg@switch m
1242 % Get meet name and store it. Don't output anything yet, because don't
1243 % know if date is in range---output occurs after date is read.
1244 \global\let\swg@meetname=\swg@content
1245 \global\swg@nmntrue
1246 \else\if\swg@switch M
1247 \global\let\swg@meetname=\swg@content
1248 \else\if\swg@switch d
1249 \global\let\swg@meetdate=\swg@content
1250 %\typeout{Date: \swg@meetdate}
1251 \expandafter\swg@date \swg@meetdate {}
1252 \swg@inrangefalse % till proved otherwise
1253 \global\swg@nmdtrue
1254 % If date is in right range, continue
1255 \ifnum\swg@daycount>\swg@startday
1256 \ifnum\swg@daycount<\swg@enddaycount
1257 \global\swg@inrangetrue
1258 \ifswg@nmn
1259 % Output any accumulated result
1260 \ifswg@eventfound\swg@makeresult\fi
1261 \ifswg@indescription
1262 \end{swgdescription}
1263 \global\swg@indescriptionfalse
1264 \fi
1265 \section*{\swg@meetname}\swg@nmnfalse
1266 \fi
1267 \ifswg@nmd
1268 \ifswg@eventfound\swg@makeresult\fi
1269 \ifswg@indescription
1270 \end{swgdescription}
1271 \global\swg@indescriptionfalse
1272 \fi
1273 \subsection*{\swg@meetdate}\swg@nmdfalse
1274 \fi
1275 \begin{swgdescription}
1276 \global\swg@indescriptiontrue
1277 \fi
1278 \else\typeout{Date \swg@meetdate\space ignored because out of requested range}
1279 \fi
1280 \else\if\swg@switch r
1281 \ifswg@inrange\swg@eventx\fi
1282 \else\if\swg@switch u
1283 \ifswg@inrange\swg@eventx\fi
1284 \else\if\swg@switch R
1285 \ifswg@inrange\swg@eventx\fi
1286 \else\if\swg@switch x
1287 \ifswg@inrange\swg@eventx\fi
1288 \else\if\swg@switch a
1289 \global\let\swg@s@age=\swg@content
1290 \else\if\swg@switch c
1291 \global\let\swg@fcourse=\swg@content
1292 \else\if\swg@switch o
1293 \let\swg@s@other=\swg@content
1294 \else\if\swg@switch t
1295 \let\swg@s@type=\swg@content
1296 \else\if\swg@switch p
1297 \let\swg@s@place=\swg@content
1298 \else\if\swg@switch P
1299 \let\swg@s@ageplace=\swg@content
1300 \else\if\swg@switch w
1301 \let\swg@s@wintime=\swg@content
1302 \else\if\swg@switch 1
1303 \let\swg@s@first=\swg@content
1304 \else\if\swg@switch 2
1305 \let\swg@s@second=\swg@content
1306 \else\if\swg@switch 3
1307 \let\swg@s@third=\swg@content
1308 \else\if\swg@switch 4
1309 \let\swg@s@fourth=\swg@content
1310 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
1311 \fi
1312 \ifeof0\relax\swg@continuefalse\else\swg@continuetrue\fi
1313 \ifswg@continue%
1314 \repeat%
1315 % Output any accumulated result
1316 \ifswg@eventfound\swg@makeresult\fi
1317 \ifswg@indescription
1318 \end{swgdescription}
1319 \fi
1320 \endlinechar=13
1321 \closein0
1322
1323 }
1324
1325