tomwalters@0
|
1 /*
|
tomwalters@0
|
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
|
tomwalters@0
|
3 ===========================================================================
|
tomwalters@0
|
4
|
tomwalters@0
|
5 Permission to use, copy, modify, and distribute this software without fee
|
tomwalters@0
|
6 is hereby granted for research purposes, provided that this copyright
|
tomwalters@0
|
7 notice appears in all copies and in all supporting documentation, and that
|
tomwalters@0
|
8 the software is not redistributed for any fee (except for a nominal shipping
|
tomwalters@0
|
9 charge). Anyone wanting to incorporate all or part of this software in a
|
tomwalters@0
|
10 commercial product must obtain a license from the Medical Research Council.
|
tomwalters@0
|
11
|
tomwalters@0
|
12 The MRC makes no representations about the suitability of this
|
tomwalters@0
|
13 software for any purpose. It is provided "as is" without express or implied
|
tomwalters@0
|
14 warranty.
|
tomwalters@0
|
15
|
tomwalters@0
|
16 */
|
tomwalters@0
|
17
|
tomwalters@0
|
18 /*
|
tomwalters@0
|
19 gen.c
|
tomwalters@0
|
20 =====
|
tomwalters@0
|
21
|
tomwalters@0
|
22 APU, ASP model demonstration program.
|
tomwalters@0
|
23
|
tomwalters@0
|
24
|
tomwalters@0
|
25 Copyright (c), 1989 The Medical Research Council, Applied Psychology Unit.
|
tomwalters@0
|
26
|
tomwalters@0
|
27
|
tomwalters@0
|
28 Authors : John Holdsworth (1989), Mike Allerhand (1990)
|
tomwalters@0
|
29
|
tomwalters@0
|
30
|
tomwalters@0
|
31 Edited : M.Akeroyd 22-1-1993
|
tomwalters@0
|
32 Removed the conditional of `if (centering) Clear (w)'
|
tomwalters@0
|
33 (in plot_frame), so that Clear may be called for
|
tomwalters@0
|
34 PostScriptWindows that AREN'T centered, so allowing
|
tomwalters@0
|
35 showpages to be generated.
|
tomwalters@0
|
36 See also edit to ps.c
|
tomwalters@0
|
37
|
tomwalters@0
|
38 : M Akeroyd 3-8-1993
|
tomwalters@0
|
39 Added new options:
|
tomwalters@0
|
40 erbscale_efb (InputOption) mono_ctn (SilentOption)
|
tomwalters@0
|
41 colour_ctn (SilentOption) planemask_ctn (SilentOption)
|
tomwalters@0
|
42 Allowed "bitmap=stdout".
|
tomwalters@0
|
43
|
tomwalters@0
|
44 : MAA 3rd August 1993
|
tomwalters@0
|
45 Extra options
|
tomwalters@0
|
46 framenumber (SilentOption), review (SilentOption)
|
tomwalters@0
|
47
|
tomwalters@0
|
48 : MAA 22nd July 1994.
|
tomwalters@0
|
49 Extra postscript options ALl silent
|
tomwalters@0
|
50 xstart_ps xend_ps ystart_ps yend_ps
|
tomwalters@0
|
51 xtitle_ps ytitle_ps
|
tomwalters@0
|
52 Extra X options
|
tomwalters@0
|
53 fg_col bg_col
|
tomwalters@0
|
54
|
tomwalters@0
|
55 : MAA Summer 1984. Lots of postscript options. All silent
|
tomwalters@0
|
56 portraitstr, landscapestr;
|
tomwalters@0
|
57 fontnamestr, fontsizestr;
|
tomwalters@0
|
58 xmajorticksstr, xminorticksstr, ymajorticksstr, yminorticksstr;
|
tomwalters@0
|
59 axistop, axisbottom, axisleft, axisright;
|
tomwalters@0
|
60
|
tomwalters@0
|
61 : AJD Spring 1995.
|
tomwalters@0
|
62 Added a new argument 'nwid' to the function SourceDraw, so that genspl
|
tomwalters@0
|
63 can have the necessary information.
|
tomwalters@0
|
64
|
tomwalters@0
|
65 : AJD May, 1995.
|
tomwalters@0
|
66 Made options overlap, headroom, perspective, bytemax and type silent.
|
tomwalters@0
|
67 */
|
tomwalters@0
|
68
|
tomwalters@0
|
69
|
tomwalters@0
|
70 #ifndef lint
|
tomwalters@0
|
71 static char *sccs_id = "@(#)gen.c 1.66 John Holdsworth, Mike Allerhand, Roy Patterson, Paul Manson (MRC-APU) 6/6/91" ;
|
tomwalters@0
|
72 #endif
|
tomwalters@0
|
73
|
tomwalters@0
|
74
|
tomwalters@0
|
75 /****************************************************************************
|
tomwalters@0
|
76 * This module contains:
|
tomwalters@0
|
77 * Display option parameter strings.
|
tomwalters@0
|
78 * Model option parameter strings.
|
tomwalters@0
|
79 * File-format strings.
|
tomwalters@0
|
80 * X windows interface, (included from windows.h).
|
tomwalters@0
|
81 * Options handler routines, (included from options.h).
|
tomwalters@0
|
82 * Option defaults, (application specific).
|
tomwalters@0
|
83 * Strings for generic option types, (OnOption etc).
|
tomwalters@0
|
84 * Display options table, (displayopts[]).
|
tomwalters@0
|
85 * Model option tables, (included from table.c).
|
tomwalters@0
|
86 * Model entry-point functions, (included from model.c).
|
tomwalters@0
|
87 * Display drawing routines, (included from draw.h and fill.h).
|
tomwalters@0
|
88 * Options table construction, (constructOptions(), and mapOptions()).
|
tomwalters@0
|
89 * Main.
|
tomwalters@0
|
90 ****************************************************************************/
|
tomwalters@0
|
91
|
tomwalters@0
|
92 #include <string.h>
|
tomwalters@0
|
93 #include <ctype.h>
|
tomwalters@0
|
94 #include <stdio.h>
|
tomwalters@0
|
95 #include <math.h>
|
tomwalters@0
|
96
|
tomwalters@0
|
97 #if defined(THINK_C) || defined(NeXT)
|
tomwalters@0
|
98 #include <stdlib.h>
|
tomwalters@0
|
99 #endif
|
tomwalters@0
|
100
|
tomwalters@0
|
101 /********************* Display option parameter strings *********************
|
tomwalters@0
|
102 * The strings defined here are pointers referenced by the "value" field in
|
tomwalters@0
|
103 * the display options table, displayopts. They are assigned to space which
|
tomwalters@0
|
104 * initially contains defaults in the "defaultValue" field of the display
|
tomwalters@0
|
105 * options table.
|
tomwalters@0
|
106 ****************************************************************************/
|
tomwalters@0
|
107
|
tomwalters@0
|
108 static char *bmaxstr, *topstr, *botstr, *overstr ;
|
tomwalters@0
|
109 static char *headstr, *downcstr, *heightstr, *helpstr ;
|
tomwalters@0
|
110 static char *invertstr, *lengthstr, *linstr, *outstr ;
|
tomwalters@0
|
111 static char *reusestr, *startstr, *envstr, *typestr ;
|
tomwalters@0
|
112 #ifdef X11
|
tomwalters@0
|
113 static char *dispstr, *erasestr, *hiddenstr, *bitmapstr ;
|
tomwalters@0
|
114 static char *kludgestr, *magstr, *penstr, *psfilestr ;
|
tomwalters@0
|
115 static char *psstr, *animstr, *titlestr, *viewstr ;
|
tomwalters@0
|
116 static char *widthstr, *xstr, *ystr ;
|
tomwalters@0
|
117 /* All these MAA. */
|
tomwalters@0
|
118 char *monostr, *colourstr, *planemaskstr, *rotateaxesstr;
|
tomwalters@0
|
119 char *fgcolourstr, *bgcolourstr;
|
tomwalters@0
|
120 char *xstartstr, *ystartstr, *xendstr, *yendstr;
|
tomwalters@0
|
121 char *xnewtitlestr, *ynewtitlestr;
|
tomwalters@0
|
122 char *portraitstr, *landscapestr;
|
tomwalters@0
|
123 char *fontnamestr, *fontsizestr, *titlesizestr;
|
tomwalters@0
|
124 char *xticksstr, *yticksstr, *outsidestr;
|
tomwalters@0
|
125 char *axistopstr, *axisbottomstr, *axisleftstr, *axisrightstr;
|
tomwalters@0
|
126 char *xmajorticksstr, *xminorticksstr, *ymajorticksstr, *yminorticksstr;
|
tomwalters@0
|
127 char *axislinewidthstr, *figurelinewidthstr;
|
tomwalters@0
|
128 char *boxstr;
|
tomwalters@0
|
129 #endif /* X11 */
|
tomwalters@0
|
130
|
tomwalters@0
|
131 char *framenumberstr, *reviewstr; /* MAA: 3-8-1993 */
|
tomwalters@0
|
132
|
tomwalters@0
|
133 static char *test1str, *test2str, *test3str, *test4str ;
|
tomwalters@0
|
134
|
tomwalters@0
|
135 char headerstr[64] ;
|
tomwalters@0
|
136
|
tomwalters@0
|
137 char *filestr ;
|
tomwalters@0
|
138
|
tomwalters@0
|
139 /* application display parameters */
|
tomwalters@0
|
140
|
tomwalters@0
|
141 #ifdef X11
|
tomwalters@0
|
142 static char *tiltstr = "0." ;
|
tomwalters@0
|
143 static char *diststr = "0.5" ;
|
tomwalters@0
|
144 static char *roomstr = "0%" ;
|
tomwalters@0
|
145 #endif /* X11 */
|
tomwalters@0
|
146
|
tomwalters@0
|
147 /*************** Included from glib (graphics library) directory ***********/
|
tomwalters@0
|
148
|
tomwalters@0
|
149 #include "options.h"
|
tomwalters@0
|
150 #include "defaults.h"
|
tomwalters@0
|
151
|
tomwalters@0
|
152 #ifdef X11
|
tomwalters@0
|
153 #include "windows.h"
|
tomwalters@0
|
154 #endif /* X11 */
|
tomwalters@0
|
155
|
tomwalters@0
|
156 /******************* Strings for generic option values **********************
|
tomwalters@0
|
157 * Generic option values, (ON_OPTION etc), are defined in options.h.
|
tomwalters@0
|
158 * Convenience routines used to test or convert option values are:
|
tomwalters@0
|
159 * OptionStringsEqual( str1, str2 ) -(defined in options.c).
|
tomwalters@0
|
160 * isON( str ) -(defined in options.h).
|
tomwalters@0
|
161 * isOFF( str ) -(defined in options.c).
|
tomwalters@0
|
162 * isNULL( str ) -(defined in options.c).
|
tomwalters@0
|
163 * OptionInt( str ) -(defined in model.c).
|
tomwalters@0
|
164 * OptionDouble( str ) -(defined in model.c).
|
tomwalters@0
|
165 * Samples( str ) -(defined in model.c).
|
tomwalters@0
|
166 * Cycles( str, cfreq ) -(defined in model.c).
|
tomwalters@0
|
167 * Scalar( str ) -(defined in model.c).
|
tomwalters@0
|
168 * Freq( str ) -(defined in model.c).
|
tomwalters@0
|
169 *
|
tomwalters@0
|
170 ****************************************************************************/
|
tomwalters@0
|
171
|
tomwalters@0
|
172
|
tomwalters@0
|
173 static char helpstring[200] = "no help initially" ;
|
tomwalters@0
|
174 static char OnOption[] = ON_OPTION ; /* "on" */
|
tomwalters@0
|
175 static char OffOption[] = OFF_OPTION ; /* "off" */
|
tomwalters@0
|
176 static char NullOption[] = NULL_OPTION ; /* "none" */
|
tomwalters@0
|
177 static char CenterStr[] = "center" ;
|
tomwalters@0
|
178 static char LengthStr[] = "remainder" ;
|
tomwalters@0
|
179 static char LandStr[] = "landscape" ;
|
tomwalters@0
|
180
|
tomwalters@0
|
181 static int isEXCITE( str )
|
tomwalters@0
|
182 char *str ;
|
tomwalters@0
|
183 {
|
tomwalters@0
|
184 return ( strncmp( str, "excitation", strlen( str ) ) == 0 ) ;
|
tomwalters@0
|
185 }
|
tomwalters@0
|
186
|
tomwalters@0
|
187 static int isWATERFALL( str )
|
tomwalters@0
|
188 char *str ;
|
tomwalters@0
|
189 {
|
tomwalters@0
|
190 return ( strncmp( str, "waterfall", strlen( str ) ) == 0 ) ;
|
tomwalters@0
|
191 }
|
tomwalters@0
|
192
|
tomwalters@0
|
193 static int isGREYSCALE( str )
|
tomwalters@0
|
194 char *str ;
|
tomwalters@0
|
195 {
|
tomwalters@0
|
196 return ( strncmp( str, "greyscale", strlen( str ) ) == 0 ||
|
tomwalters@0
|
197 strncmp( str, "grayscale", strlen( str ) ) == 0 ) ;
|
tomwalters@0
|
198 }
|
tomwalters@0
|
199
|
tomwalters@0
|
200
|
tomwalters@0
|
201
|
tomwalters@0
|
202 /************************* Options table ***********************************
|
tomwalters@0
|
203 * The complete options table is built by constructOptions() according to the
|
tomwalters@0
|
204 * application. It is composed of the display options, (displayopts[], below),
|
tomwalters@0
|
205 * and the model option tables (from table.c) which are appropriate for the
|
tomwalters@0
|
206 * application. The sequence of processing stages, (and hence model option
|
tomwalters@0
|
207 * tables), for an application is determined by FindStage() in model.c.
|
tomwalters@0
|
208 *
|
tomwalters@0
|
209 * The complete options table is an array of Option structs.
|
tomwalters@0
|
210 * The Option struct is defined in options.h as:
|
tomwalters@0
|
211 *
|
tomwalters@0
|
212 * typedef struct {
|
tomwalters@0
|
213 * char *name ; The name of the option.
|
tomwalters@0
|
214 * char *defaultValue ; Default value.
|
tomwalters@0
|
215 * char **value ; Address of current value.
|
tomwalters@0
|
216 * char *comment ; Something to print when the user types "-help".
|
tomwalters@0
|
217 * short classification ; Type of option it is.
|
tomwalters@0
|
218 * } Option;
|
tomwalters@0
|
219 *
|
tomwalters@0
|
220 * The classification of options uses names defined in options.h:
|
tomwalters@0
|
221 * InputOption
|
tomwalters@0
|
222 * OutputOption
|
tomwalters@0
|
223 * InOutOption
|
tomwalters@0
|
224 * SilentOption
|
tomwalters@0
|
225 *
|
tomwalters@0
|
226 * Routines which access the option table:
|
tomwalters@0
|
227 * Note: Some routines are called to supply arguments to other routines.
|
tomwalters@0
|
228 * Routines which access the option table in some way are denoted (*).
|
tomwalters@0
|
229 * Most of these routines are defined in options.c.
|
tomwalters@0
|
230 *
|
tomwalters@0
|
231 * main()
|
tomwalters@0
|
232 * |
|
tomwalters@0
|
233 * +-----------------+-----------+----+-------+-----------------+
|
tomwalters@0
|
234 * | | | | |
|
tomwalters@0
|
235 * | | | ModeledSource() |
|
tomwalters@0
|
236 * | | | | |
|
tomwalters@0
|
237 * | | | checkForFile() |
|
tomwalters@0
|
238 * helpopts() | | | |
|
tomwalters@0
|
239 * | | +---+---+ |
|
tomwalters@0
|
240 * | | | |
|
tomwalters@0
|
241 * | getopts() readopts() writeopts()
|
tomwalters@0
|
242 * | | | |
|
tomwalters@0
|
243 * | getnopts(*) readnopts() writenopts(*)
|
tomwalters@0
|
244 * | [arg countOptions(*)] [arg countOptions(*)] [arg countOptions(*)]
|
tomwalters@0
|
245 * | | | |
|
tomwalters@0
|
246 * | +-------+------+ | countBytesToWrite(*)
|
tomwalters@0
|
247 * | | | | |
|
tomwalters@0
|
248 * | | | +------+------+
|
tomwalters@0
|
249 * | | | |
|
tomwalters@0
|
250 * | | | processOptionFile()
|
tomwalters@0
|
251 * | | | |
|
tomwalters@0
|
252 * | | +------+------+
|
tomwalters@0
|
253 * | | |
|
tomwalters@0
|
254 * | | LookUpAndStore(*)
|
tomwalters@0
|
255 * | | |
|
tomwalters@0
|
256 * | | +---+---+----------+
|
tomwalters@0
|
257 * | | | | |
|
tomwalters@0
|
258 * | +-----+----+ LookUp(*) Ambiguity(*)
|
tomwalters@0
|
259 * | | |
|
tomwalters@0
|
260 * +----+----+ updateOptionsFile(*)
|
tomwalters@0
|
261 * |
|
tomwalters@0
|
262 * defaultHelpHandler(*)
|
tomwalters@0
|
263 *
|
tomwalters@0
|
264 *
|
tomwalters@0
|
265 * getopts()
|
tomwalters@0
|
266 * Operates on the options table given to it as an argument.
|
tomwalters@0
|
267 * a) Each "value" field is initialized to its "defaultValue" field.
|
tomwalters@0
|
268 * b) The "value" fields are re-initialized by any corresponding values found
|
tomwalters@0
|
269 * in the options ("rc") file, (overriding the "defaultValue").
|
tomwalters@0
|
270 * c) The "value" fields are re-initialized again by any corresponding values
|
tomwalters@0
|
271 * found in command-line arguments.
|
tomwalters@0
|
272 * d) Special arguments are dealt with:
|
tomwalters@0
|
273 * "help" calls the onLineHelpHandler() routine, (see below).
|
tomwalters@0
|
274 * "update" calls the updateOptionsFile() routine.
|
tomwalters@0
|
275 * e) Return the remainder of the command-line (argc and argv) for use in
|
tomwalters@0
|
276 * main().
|
tomwalters@0
|
277 *
|
tomwalters@0
|
278 * helpopts()
|
tomwalters@0
|
279 * Is called to print the help menu if no input file has been found by
|
tomwalters@0
|
280 * getopts(), (in the "rc" file), and none remains on the command-line.
|
tomwalters@0
|
281 * An alias for the onLineHelpHandler() function, which is in turn an
|
tomwalters@0
|
282 * alias for the defaultHelpHandler() routine, (see options.c).
|
tomwalters@0
|
283 *
|
tomwalters@0
|
284 * readopts()
|
tomwalters@0
|
285 * Read any options header which may be at the start of the input file.
|
tomwalters@0
|
286 * Interpret the header like an options ("rc") file, and re-initialize any
|
tomwalters@0
|
287 * corresponding "value" fields in the given options table, (as in getopts()).
|
tomwalters@0
|
288 * Skip to the start of the input data, allowing for any offset (ie startstr).
|
tomwalters@0
|
289 *
|
tomwalters@0
|
290 * writeopts()
|
tomwalters@0
|
291 * Write the given options table as an options header at the start of an o/p
|
tomwalters@0
|
292 * file, if the "header" option is "on".
|
tomwalters@0
|
293 *
|
tomwalters@0
|
294 ****************************************************************************/
|
tomwalters@0
|
295
|
tomwalters@0
|
296 static Option *options;
|
tomwalters@0
|
297
|
tomwalters@0
|
298 /******************** Display options table ********************************
|
tomwalters@0
|
299 * Options table for application display parameters.
|
tomwalters@0
|
300 ****************************************************************************/
|
tomwalters@0
|
301
|
tomwalters@0
|
302 static Option displayopts[] = {
|
tomwalters@0
|
303
|
tomwalters@0
|
304 /* Miscellaneous Silent Parameters (hidden from users) */
|
tomwalters@0
|
305
|
tomwalters@0
|
306
|
tomwalters@0
|
307 { "Version", headerstr, &versionstr, "Version number and date", OutputOption},
|
tomwalters@0
|
308
|
tomwalters@0
|
309 { "test1", "0", &test1str, "Dummy option for test and development", SilentOption},
|
tomwalters@0
|
310 { "test2", "0", &test2str, "Dummy option for test and development", SilentOption},
|
tomwalters@0
|
311 { "test3", "0", &test3str, "Dummy option for test and development", SilentOption},
|
tomwalters@0
|
312 { "test4", "0", &test4str, "Dummy option for test and development", SilentOption},
|
tomwalters@0
|
313
|
tomwalters@0
|
314 { "linear_sgm", OffOption, &linstr, "Linear frequency axis for spectrograms",SilentOption},
|
tomwalters@0
|
315 { "useprevious", OffOption, &reusestr, "Use previously stored output", SilentOption},
|
tomwalters@0
|
316
|
tomwalters@0
|
317 /* MAA: 21-8-1993
|
tomwalters@0
|
318 * These next two options are here, because otherwise "gensgm -use ..." (at least) core dumps.
|
tomwalters@0
|
319 */
|
tomwalters@0
|
320 { "framenumber", OffOption, &framenumberstr, "Index of current frame (to stderr)\n", SilentOption},
|
tomwalters@0
|
321 { "review", OffOption, &reviewstr, "Wait for keyboard <return> between frames",SilentOption},
|
tomwalters@0
|
322
|
tomwalters@0
|
323 #ifdef X11
|
tomwalters@0
|
324 { "pstofile", OffOption, &psfilestr, "Send PostScript output to .ps file", SilentOption},
|
tomwalters@0
|
325 { "invert", OffOption, &invertstr, "Invert axis of sai image", SilentOption},
|
tomwalters@0
|
326 { "fast", OffOption, &kludgestr, "Speed up image generation", SilentOption},
|
tomwalters@0
|
327 #endif /* X11 */
|
tomwalters@0
|
328
|
tomwalters@0
|
329 /* ( The order of the "help" option members is strange due to the way */
|
tomwalters@0
|
330 /* it was originally used. See options.c: defaultHelpHandler() and */
|
tomwalters@0
|
331 /* updateOptionsFile() ). */
|
tomwalters@0
|
332
|
tomwalters@0
|
333 /* Input Parameters */
|
tomwalters@0
|
334
|
tomwalters@0
|
335 { "envelope", OffOption, &envstr, "Type of model to use required", SilentOption},
|
tomwalters@0
|
336 { "help", "not used", &helpstr, helpstring, SilentOption},
|
tomwalters@0
|
337
|
tomwalters@0
|
338 #ifdef X11
|
tomwalters@0
|
339
|
tomwalters@0
|
340 /* Screen Output Parameters */
|
tomwalters@0
|
341
|
tomwalters@0
|
342 { "title", "filename", &titlestr, "Title of picture, or input filename", InputOption},
|
tomwalters@0
|
343 #ifdef THINK_C
|
tomwalters@0
|
344 { "x0_win", "10", &xstr, "Left edge of window (pixels)", InOutOption},
|
tomwalters@0
|
345 { "y0_win", "50", &ystr, "Lower edge of window (pixels)", InOutOption},
|
tomwalters@0
|
346 #else
|
tomwalters@0
|
347 { "x0_win", CenterStr, &xstr, "Left edge of window (pixels)", InOutOption},
|
tomwalters@0
|
348 { "y0_win", CenterStr, &ystr, "Lower edge of window (pixels)", InOutOption},
|
tomwalters@0
|
349 #endif
|
tomwalters@0
|
350 #ifdef PC
|
tomwalters@0
|
351 { "width_win", "400", &widthstr, "Window width (pixels)", InOutOption},
|
tomwalters@0
|
352 { "height_win", "300", &heightstr, "Window height (pixels)\n", InOutOption},
|
tomwalters@0
|
353 #else /* UNIX */
|
tomwalters@0
|
354 { "width_win", "540", &widthstr, "Window width (pixels)", InOutOption},
|
tomwalters@0
|
355 { "height_win", "400", &heightstr, "Window height (pixels)\n", InOutOption},
|
tomwalters@0
|
356 #endif
|
tomwalters@0
|
357 { "display", OnOption, &dispstr, "Select display of output image", InOutOption},
|
tomwalters@0
|
358 { "view", LandStr, &viewstr, "Select display format", InOutOption},
|
tomwalters@0
|
359 { "top", "1024", &topstr, "Maximum of plotted range", InputOption},
|
tomwalters@0
|
360 { "bottom", "-1024", &botstr, "Minimum of plotted range", InputOption},
|
tomwalters@0
|
361 { "overlap", "50%", &overstr, "Overlap between channels", SilentOption}, /* AJD 16-5-95 */
|
tomwalters@0
|
362 { "headroom", "0%", &roomstr, "Headroom at top of picture", SilentOption}, /* AJD 16-5-95 */
|
tomwalters@0
|
363 { "magnification", "1", &magstr, "Magnification of image in display", InputOption},
|
tomwalters@0
|
364 { "pensize", "1", &penstr, "Size of plotted lines and dots", InputOption},
|
tomwalters@0
|
365 { "hiddenline", OnOption, &hiddenstr, "Hidden line removal\n", InputOption},
|
tomwalters@0
|
366 { "perspective", "0", &tiltstr, "Perspective view of display (degrees)\n", SilentOption}, /* AJD 16-5-95 */
|
tomwalters@0
|
367 #endif /* X11 */
|
tomwalters@0
|
368
|
tomwalters@0
|
369 { "downchannel", OffOption, &downcstr, "Average adjacent frequency channels\n", InOutOption},
|
tomwalters@0
|
370
|
tomwalters@0
|
371 #ifdef X11
|
tomwalters@0
|
372
|
tomwalters@0
|
373 /* Auditory image cartoon parameters */
|
tomwalters@0
|
374
|
tomwalters@0
|
375 { "erase_ctn", OnOption, &erasestr, "Erase display between cartoon frames", InOutOption},
|
tomwalters@0
|
376 { "animate_ctn", OffOption, &animstr, "Animate cartoon", InOutOption},
|
tomwalters@0
|
377 { "bitmap_ctn", OffOption, &bitmapstr, "Produce cartoon output (.ctn)\n", InputOption},
|
tomwalters@0
|
378 { "mono_ctn", OnOption, &monostr, "Force monochrome (single plane) cartoons.", SilentOption},
|
tomwalters@0
|
379 { "colour_ctn", OffOption, &colourstr, "Force colour (multi-plane) cartoons.", SilentOption},
|
tomwalters@0
|
380 {"planemask_ctn", "1", &planemaskstr, "Planemask for creating cartoons.\n", SilentOption},
|
tomwalters@0
|
381 {"fg_col", "black", &fgcolourstr, "Foreground Colour.\n", SilentOption},
|
tomwalters@0
|
382 {"bg_col", "white", &bgcolourstr, "Background Colour.\n", SilentOption},
|
tomwalters@0
|
383
|
tomwalters@0
|
384
|
tomwalters@0
|
385 /* Postscript options */
|
tomwalters@0
|
386
|
tomwalters@0
|
387 { "postscript", OffOption, &psstr, "Produce postscript output", InputOption},
|
tomwalters@0
|
388 { "rotateaxes", OffOption, &rotateaxesstr, "Rotate the axes labels in .ps output", SilentOption},
|
tomwalters@0
|
389 { "xstart_ps", "", &xstartstr, "Postscript x-axis: start point.", SilentOption},
|
tomwalters@0
|
390 { "xend_ps", "", &xendstr, "Postscript x-axis: end point.", SilentOption},
|
tomwalters@0
|
391 { "ystart_ps", "", &ystartstr, "Postscript y-axis: start point.", SilentOption},
|
tomwalters@0
|
392 { "yend_ps", "", ¥dstr, "Postscript y-axis: end point.", SilentOption},
|
tomwalters@0
|
393 { "xtitle_ps", "", &xnewtitlestr, "Postscript x-axis: title.", SilentOption},
|
tomwalters@0
|
394 { "ytitle_ps", "", &ynewtitlestr, "Postscript x-axis: title.", SilentOption},
|
tomwalters@0
|
395 { "portrait_ps", "", &portraitstr, "Use 'portrait' page format", SilentOption},
|
tomwalters@0
|
396 { "landscape_ps", "", &landscapestr, "Use 'landscape' page format (overrides 'portriat)", SilentOption},
|
tomwalters@0
|
397 { "fontname_ps", "Helvetica", &fontnamestr, "Define font", SilentOption},
|
tomwalters@0
|
398 { "fontsize_ps", "12", &fontsizestr, "Define fontsize (points)", SilentOption},
|
tomwalters@0
|
399 { "fonttitlesize_ps", "0", &titlesizestr, "Define fontsize for title (points)", SilentOption},
|
tomwalters@0
|
400 { "axislinewidth_ps", "1", &axislinewidthstr, "Linewidth for axes & tickmarks (points)", SilentOption},
|
tomwalters@0
|
401 { "figurelinewidth_ps", "1", &figurelinewidthstr, "Linewidth for figures (points)", SilentOption},
|
tomwalters@0
|
402 { "xticks_ps", "6", &xticksstr, "Define size of x-axis (big) ticks (points)", SilentOption},
|
tomwalters@0
|
403 { "yticks_ps", "6", &yticksstr, "Define size of y-axis (big) ticks' (points)", SilentOption},
|
tomwalters@0
|
404 { "outsideticks_ps",OnOption, &outsidestr, "Print tick-marks 'outside' figure", SilentOption},
|
tomwalters@0
|
405 { "axistop_ps", OnOption, &axistopstr, "Print tick-marks on top side", SilentOption},
|
tomwalters@0
|
406 { "axisbottom_ps", OnOption, &axisbottomstr, "Print tick-marks on bottom side", SilentOption},
|
tomwalters@0
|
407 { "axisleft_ps", OnOption, &axisleftstr, "Print tick-marks on left side", SilentOption},
|
tomwalters@0
|
408 { "axisright_ps", OnOption, &axisrightstr, "Print tick-marks on right side", SilentOption},
|
tomwalters@0
|
409 { "xmajorticks_ps", "1", &xmajorticksstr, "Relative *spacing* of ticks", SilentOption},
|
tomwalters@0
|
410 { "xminorticks_ps", "1", &xminorticksstr, "Relative *spacing* of ticks", SilentOption},
|
tomwalters@0
|
411 { "ymajorticks_ps", "1", &ymajorticksstr, "Relative *spacing* of ticks", SilentOption},
|
tomwalters@0
|
412 { "yminorticks_ps", "1", &yminorticksstr, "Relative *spacing* of ticks", SilentOption},
|
tomwalters@0
|
413 { "box_ps", OnOption, &boxstr, "Plot a box", SilentOption},
|
tomwalters@0
|
414 #endif /* X11 */
|
tomwalters@0
|
415
|
tomwalters@0
|
416 /* File Output Parameters */
|
tomwalters@0
|
417 { "output", OffOption, &outstr, "Produce output file", InputOption},
|
tomwalters@0
|
418 { "header", OnOption, &headstr, "Add a header to the output file\n", InOutOption},
|
tomwalters@0
|
419 { "bytemax", "255", &bmaxstr, "Maximum value in byte output", SilentOption}, /* AJD 16-5-95 */
|
tomwalters@0
|
420 { "type", "short", &typestr, "Output data type\n", SilentOption}, /* AJD 16-5-95 */
|
tomwalters@0
|
421
|
tomwalters@0
|
422 { "input_wave", NullOption, &filestr, "Default input file name", InputOption},
|
tomwalters@0
|
423 { "start_wave", "0ms", &startstr, "Start point in wave (ms)", InputOption},
|
tomwalters@0
|
424 { "length_wave", LengthStr, &lengthstr, "Length of wave to process (ms)", InputOption},
|
tomwalters@0
|
425
|
tomwalters@0
|
426 ( char * ) 0 } ;
|
tomwalters@0
|
427
|
tomwalters@0
|
428
|
tomwalters@0
|
429 /*********************** Included from stitch directory ********************/
|
tomwalters@0
|
430
|
tomwalters@0
|
431 /* interfaces to stitch system */
|
tomwalters@0
|
432
|
tomwalters@0
|
433 #include "stitch.h"
|
tomwalters@0
|
434 #include "source.h"
|
tomwalters@0
|
435 #include "spiral.h"
|
tomwalters@0
|
436 #include "image.h"
|
tomwalters@0
|
437 #include "model.h"
|
tomwalters@0
|
438 #include "units.h"
|
tomwalters@0
|
439 #include "calc.h"
|
tomwalters@0
|
440 #include "ops.h"
|
tomwalters@0
|
441 #include "io.h"
|
tomwalters@0
|
442
|
tomwalters@0
|
443
|
tomwalters@0
|
444 #ifdef X11
|
tomwalters@0
|
445 #include "draw.h"
|
tomwalters@0
|
446 #include "fill.h"
|
tomwalters@0
|
447 #endif /* X11 */
|
tomwalters@0
|
448
|
tomwalters@0
|
449 /**************************************************************************/
|
tomwalters@0
|
450
|
tomwalters@0
|
451 char *AlterSuffix() ; /* alter suffix of file name. */
|
tomwalters@0
|
452 #ifdef X11
|
tomwalters@0
|
453 void save_frame(), plot_frame() ; /* draw callbacks. */
|
tomwalters@0
|
454 void fast_frame() ;
|
tomwalters@0
|
455 #endif /* X11 */
|
tomwalters@0
|
456
|
tomwalters@0
|
457 extern char *genstate() ;
|
tomwalters@0
|
458 static char *gen_state ;
|
tomwalters@0
|
459
|
tomwalters@0
|
460 Source DownChannel() ; /* reduce channels by averaging. */
|
tomwalters@0
|
461 #ifdef X11
|
tomwalters@0
|
462 Source PackShorts() ; /* pack output into one byte. */
|
tomwalters@0
|
463 #endif /* X11 */
|
tomwalters@0
|
464 Source checkForFile() ; /* create source from file if present. */
|
tomwalters@0
|
465
|
tomwalters@0
|
466 #define POSTSCRIPT_FILE_SUFFIX ".ps"
|
tomwalters@0
|
467 #define CARTOON_FILE_SUFFIX ".ctn"
|
tomwalters@0
|
468
|
tomwalters@0
|
469 #ifdef X11
|
tomwalters@0
|
470 static WindowObject display = 0 ;
|
tomwalters@0
|
471 #endif /* X11 */
|
tomwalters@0
|
472
|
tomwalters@0
|
473 /***************************************************************************/
|
tomwalters@0
|
474
|
tomwalters@0
|
475 /* Return length of the file in bytes */
|
tomwalters@0
|
476 static long fileLength( fp )
|
tomwalters@0
|
477 FILE *fp ;
|
tomwalters@0
|
478 {
|
tomwalters@0
|
479 long posn = ftell( fp ) ;
|
tomwalters@0
|
480 long length = 0 ;
|
tomwalters@0
|
481
|
tomwalters@0
|
482 if( fseek( fp, 0l, 2 ) == 0 ) {
|
tomwalters@0
|
483
|
tomwalters@0
|
484 length = ftell( fp ) ;
|
tomwalters@0
|
485
|
tomwalters@0
|
486 (void) fseek( fp, posn, 0 ) ;
|
tomwalters@0
|
487 }
|
tomwalters@0
|
488
|
tomwalters@0
|
489 return ( length ) ;
|
tomwalters@0
|
490 }
|
tomwalters@0
|
491
|
tomwalters@0
|
492 /* per frame image handling */
|
tomwalters@0
|
493
|
tomwalters@0
|
494 static FILE *inputFilePointer = ( FILE * ) 0 ;
|
tomwalters@0
|
495
|
tomwalters@0
|
496 #ifdef X11
|
tomwalters@0
|
497
|
tomwalters@0
|
498 static FILE *imageFilePointer = ( FILE * ) 0 ;
|
tomwalters@0
|
499 static int images = 0 ;
|
tomwalters@0
|
500 static void (*frame_drawer)() ;
|
tomwalters@0
|
501
|
tomwalters@0
|
502 /***** axis information *****/
|
tomwalters@0
|
503 /*
|
tomwalters@0
|
504 "Axis" is defined in windows.h:143
|
tomwalters@0
|
505 The postscript program for drawing axis stuff is in axis.h
|
tomwalters@0
|
506 */
|
tomwalters@0
|
507
|
tomwalters@0
|
508 static int Top()
|
tomwalters@0
|
509 {
|
tomwalters@0
|
510 return ( atof( topstr ) / atof( magstr ) + 0.5 ) ;
|
tomwalters@0
|
511 }
|
tomwalters@0
|
512
|
tomwalters@0
|
513 static int Bot()
|
tomwalters@0
|
514 {
|
tomwalters@0
|
515 if( atof( botstr ) < 0 )
|
tomwalters@0
|
516 return ( atof( botstr ) / atof( magstr ) - 0.5 ) ;
|
tomwalters@0
|
517 else
|
tomwalters@0
|
518 return ( atof( botstr ) / atof( magstr ) + 0.5 ) ;
|
tomwalters@0
|
519 }
|
tomwalters@0
|
520
|
tomwalters@0
|
521 static struct {
|
tomwalters@0
|
522 double min, max ;
|
tomwalters@0
|
523 char *label ;
|
tomwalters@0
|
524 } xaxis, yaxis ;
|
tomwalters@0
|
525
|
tomwalters@0
|
526
|
tomwalters@0
|
527
|
tomwalters@0
|
528 TimeAxis( min, max, label )
|
tomwalters@0
|
529 double *min, *max ;
|
tomwalters@0
|
530 char **label ;
|
tomwalters@0
|
531 {
|
tomwalters@0
|
532 *min = Samples( startstr, Samplerate() ) / Samplerate() ;
|
tomwalters@0
|
533 *max = Samples( startstr, Samplerate() ) / Samplerate() + Frames() * Framestep() / Samplerate() ;
|
tomwalters@0
|
534
|
tomwalters@0
|
535 if( *max > 1. )
|
tomwalters@0
|
536 *label = "Time [s]" ;
|
tomwalters@0
|
537 else {
|
tomwalters@0
|
538 *label = "Time [ms]" ;
|
tomwalters@0
|
539
|
tomwalters@0
|
540 *min *= 1000. ;
|
tomwalters@0
|
541 *max *= 1000. ;
|
tomwalters@0
|
542 }
|
tomwalters@0
|
543 }
|
tomwalters@0
|
544
|
tomwalters@0
|
545 MagnitudeAxis( min, max, label )
|
tomwalters@0
|
546 double *min, *max ;
|
tomwalters@0
|
547 char **label ;
|
tomwalters@0
|
548 {
|
tomwalters@0
|
549 *min = Bot() ;
|
tomwalters@0
|
550 *max = Top() / ( 1. - atof( headstr ) / 100. ) ;
|
tomwalters@0
|
551
|
tomwalters@0
|
552 *label = "Magnitude" ;
|
tomwalters@0
|
553 }
|
tomwalters@0
|
554
|
tomwalters@0
|
555
|
tomwalters@0
|
556 static void DrawAxes( win )
|
tomwalters@0
|
557 WindowObject win ;
|
tomwalters@0
|
558 {
|
tomwalters@0
|
559 /* frame window with axes */
|
tomwalters@0
|
560
|
tomwalters@0
|
561 Axes( win, titlestr, xaxis.min, xaxis.max, xaxis.label,
|
tomwalters@0
|
562 yaxis.min, yaxis.max, yaxis.label ) ;
|
tomwalters@0
|
563 return ;
|
tomwalters@0
|
564 }
|
tomwalters@0
|
565
|
tomwalters@0
|
566 #endif /* X11 */
|
tomwalters@0
|
567
|
tomwalters@0
|
568 /******************************* main **************************************
|
tomwalters@0
|
569 * The following tables are used extensively:
|
tomwalters@0
|
570 * stage table Arrays of _stage structs, ("envelope", "fine", etc.), defined
|
tomwalters@0
|
571 * in routine FindStage() in model.c.
|
tomwalters@0
|
572 * option table Array of Option structs built at run-time by
|
tomwalters@0
|
573 * constructOptions() from displayopts, (in gen.c), and tables of
|
tomwalters@0
|
574 * model options included from table.c.
|
tomwalters@0
|
575 *
|
tomwalters@0
|
576 * Compiler switches for model versions are:
|
tomwalters@0
|
577 * FLOAT For floating point version, (default uses integer arithmetic).
|
tomwalters@0
|
578 * Defined in calc.h.
|
tomwalters@0
|
579 *
|
tomwalters@0
|
580 * The model version number is the sccs <release-number>.<level-number> of
|
tomwalters@0
|
581 * the file version.c. Refer to that file for incrementing the version number.
|
tomwalters@0
|
582 * The version number is stored in versionstr in routine getversion().
|
tomwalters@0
|
583 ****************************************************************************/
|
tomwalters@0
|
584
|
tomwalters@0
|
585 int argc_save ;
|
tomwalters@0
|
586 char **argv_save ;
|
tomwalters@0
|
587
|
tomwalters@0
|
588 main( argc, argv )
|
tomwalters@0
|
589 int argc ;
|
tomwalters@0
|
590 char *argv[] ;
|
tomwalters@0
|
591 #ifdef THINK_C
|
tomwalters@0
|
592 {
|
tomwalters@0
|
593 static char *realargv[] = { "prog", "", 0 };
|
tomwalters@0
|
594 static char *progs = { "\pgenwav;-;\
|
tomwalters@0
|
595 genfbm;genfbr;genfbc;genfbt;genfbd;gensai;genspl;gensas;-;\
|
tomwalters@0
|
596 genbmm;gennap;gensai;-;gensgm;gencgm;gensas;-;genasa;genepn;gensep;-;Quit/Q" } ;
|
tomwalters@0
|
597
|
tomwalters@0
|
598 extern char *MacMenu(), *MacFile() ;
|
tomwalters@0
|
599
|
tomwalters@0
|
600 MacInit() ;
|
tomwalters@0
|
601
|
tomwalters@0
|
602 realargv[0] = MacMenu(progs) ;
|
tomwalters@0
|
603 realargv[1] = MacFile() ;
|
tomwalters@0
|
604
|
tomwalters@0
|
605 return ( real_main( sizeof( realargv ) / sizeof (*realargv) - 1, realargv ) ) ;
|
tomwalters@0
|
606 }
|
tomwalters@0
|
607
|
tomwalters@0
|
608 real_main( argc, argv )
|
tomwalters@0
|
609 int argc ;
|
tomwalters@0
|
610 char *argv[] ;
|
tomwalters@0
|
611 #endif
|
tomwalters@0
|
612 {
|
tomwalters@0
|
613 int i ;
|
tomwalters@0
|
614 FILE *ofp = 0 ;
|
tomwalters@0
|
615 Source source ;
|
tomwalters@0
|
616 char *which, *psfilename ;
|
tomwalters@0
|
617 char title[256] ;
|
tomwalters@0
|
618 char *programName ;
|
tomwalters@0
|
619 int x, y, pixels, image, time ;
|
tomwalters@0
|
620 long headerSize, fileFramebytes ;
|
tomwalters@0
|
621 double *frequency_scale ;
|
tomwalters@0
|
622 #ifdef X11
|
tomwalters@0
|
623 WindowObject psw = 0 ;
|
tomwalters@0
|
624 char *imageFileName ;
|
tomwalters@0
|
625 #endif /* X11 */
|
tomwalters@0
|
626
|
tomwalters@0
|
627 /**************************************************************************
|
tomwalters@0
|
628 * Determine which version of the model is required.
|
tomwalters@0
|
629 * Set "which" to the last three chars of the program name, (allowing for
|
tomwalters@0
|
630 * a ".exe" extension in the case of a PC version).
|
tomwalters@0
|
631 **************************************************************************/
|
tomwalters@0
|
632
|
tomwalters@0
|
633
|
tomwalters@0
|
634 programName = argv[0] ;
|
tomwalters@0
|
635
|
tomwalters@0
|
636 which = programName + strlen( programName ) - strlen( "xxx" ) ;
|
tomwalters@0
|
637
|
tomwalters@0
|
638 #ifdef PC
|
tomwalters@0
|
639 lowerArgs( argv, argc ) ;
|
tomwalters@0
|
640
|
tomwalters@0
|
641 which -= strlen( ".exe" ) ;
|
tomwalters@0
|
642 #endif
|
tomwalters@0
|
643
|
tomwalters@0
|
644
|
tomwalters@0
|
645 /***************************************************************************
|
tomwalters@0
|
646 * Process arguments, (the model options):
|
tomwalters@0
|
647 * Set option defaults (from option table in model.c).
|
tomwalters@0
|
648 * Then override these by any options in the options file,
|
tomwalters@0
|
649 * (the resource control file, eg .gensairc).
|
tomwalters@0
|
650 * Finally, override these by any options given as command-line arguments.
|
tomwalters@0
|
651 *
|
tomwalters@0
|
652 * offsetOptions() finds the first option, (a ptr to one line of the "res"
|
tomwalters@0
|
653 * array), required by the program. This gives a place mark in the options
|
tomwalters@0
|
654 * table. (Note that the bottom of the options table, a null, corresponds with
|
tomwalters@0
|
655 * the top of the help menu).
|
tomwalters@0
|
656 * This first option appropriate to the program is found by looking it up in
|
tomwalters@0
|
657 * the stage table (in model.c), and then cross-referencing the option name
|
tomwalters@0
|
658 * with the names in the options table.
|
tomwalters@0
|
659 *
|
tomwalters@0
|
660 * Here is an example of an option, showing the members of the Options struct:
|
tomwalters@0
|
661 * name: defaultValue: value: comment: classification:
|
tomwalters@0
|
662 * {"length_wave", LengthStr, &lengthstr, "Length of wave", InputOption},
|
tomwalters@0
|
663 *
|
tomwalters@0
|
664 * getopts() operates on the options between the given place mark and the
|
tomwalters@0
|
665 * bottom of the table.
|
tomwalters@0
|
666 * This is the only call to routine getopts(), which is defined in options.c.
|
tomwalters@0
|
667 * First, each "value" is set to its corresponding "defaultvalue".
|
tomwalters@0
|
668 * Then the options file (the "rc" file) is opened, and any options found there
|
tomwalters@0
|
669 * are assigned to the corresponding "value", (overriding the "defaultvalue").
|
tomwalters@0
|
670 * Then the command-line arguments are examined, and any options found there
|
tomwalters@0
|
671 * are assigned to the corresponding "value", (overriding again).
|
tomwalters@0
|
672 * Special arguments are dealt with:
|
tomwalters@0
|
673 * "help" calls the onLineHelpHandler() routine, (see below).
|
tomwalters@0
|
674 * "update" calls the updateOptionsFile() routine.
|
tomwalters@0
|
675 *
|
tomwalters@0
|
676 * Finally, leave the remainder of the command line (argc and argv).
|
tomwalters@0
|
677 * Anything left on the command line is interpreted as follows:
|
tomwalters@0
|
678 * "filestr" is the input data filename,
|
tomwalters@0
|
679 * "startstr" is the start point in the data,
|
tomwalters@0
|
680 * "lengthstr" is the amount of data to process,
|
tomwalters@0
|
681 * "whichstr" is the last 3 chars of the program name (the program version).
|
tomwalters@0
|
682 *
|
tomwalters@0
|
683 * Note that if no input file has been found by getopts(), (in the "rc" file),
|
tomwalters@0
|
684 * and none remains on the command line, then helpopts() is called.
|
tomwalters@0
|
685 * This is an alias for the onLineHelpHandler() function, which is in turn an
|
tomwalters@0
|
686 * alias for the defaultHelpHandler() routine, (see options.c).
|
tomwalters@0
|
687 *
|
tomwalters@0
|
688 *
|
tomwalters@0
|
689 ***************************************************************************/
|
tomwalters@0
|
690
|
tomwalters@0
|
691 getversion( programName ) ;
|
tomwalters@0
|
692
|
tomwalters@0
|
693 /* The helpstring, defined in model.c, is stored as the comment field */
|
tomwalters@0
|
694 /* of the help option (see table.c). It is accessed in options.c in */
|
tomwalters@0
|
695 /* defaultHelpHandler(), using options[help].comment. */
|
tomwalters@0
|
696
|
tomwalters@0
|
697 (void) sprintf( helpstring, " [file_name]\n Generates %s", modelHelp( which ) ) ;
|
tomwalters@0
|
698
|
tomwalters@0
|
699 options = constructOptions( which, displayopts ) ;
|
tomwalters@0
|
700
|
tomwalters@0
|
701
|
tomwalters@0
|
702 /* Hack to save argc and argv so they don't get mangled by getopts */
|
tomwalters@0
|
703 /* This is so the command line args can override a reused file header */
|
tomwalters@0
|
704
|
tomwalters@0
|
705 argc_save = argc ;
|
tomwalters@0
|
706 argv_save = (char **)malloc( ( argc + 1 ) * sizeof( char *) ) ;
|
tomwalters@0
|
707 for ( i = 0 ; i < argc ; i++ ) {
|
tomwalters@0
|
708 argv_save[i] = (char *)malloc( ( strlen( argv[i] ) + 1 ) * sizeof( char ) ) ;
|
tomwalters@0
|
709 strcpy( argv_save[i], argv[i] ) ;
|
tomwalters@0
|
710 }
|
tomwalters@0
|
711
|
tomwalters@0
|
712 getopts( options, &argc, &argv ) ;
|
tomwalters@0
|
713
|
tomwalters@0
|
714 if( argc == 0 && isNULL( filestr ) ) {
|
tomwalters@0
|
715 (void) helpopts( options, programName ) ;
|
tomwalters@0
|
716 stitch_exit( -1 ) ;
|
tomwalters@0
|
717 }
|
tomwalters@0
|
718
|
tomwalters@0
|
719 if( argc > 0 && strcmp( *argv, "+" ) != 0 && argc-- > 0 )
|
tomwalters@0
|
720 filestr = *argv++ ;
|
tomwalters@0
|
721
|
tomwalters@0
|
722 if( argc > 0 && strcmp( *argv, "+" ) != 0 && argc-- > 0 )
|
tomwalters@0
|
723 startstr = *argv++ ;
|
tomwalters@0
|
724
|
tomwalters@0
|
725 if( argc > 0 && strcmp( *argv, "+" ) != 0 && argc-- > 0 )
|
tomwalters@0
|
726 lengthstr = *argv++ ;
|
tomwalters@0
|
727
|
tomwalters@0
|
728 if( isNULL( whichstr ) )
|
tomwalters@0
|
729 whichstr = which ;
|
tomwalters@0
|
730
|
tomwalters@0
|
731
|
tomwalters@0
|
732 /***************************************************************************
|
tomwalters@0
|
733 * horrrrrrrrible hack for now to try out -envelope option
|
tomwalters@0
|
734 ***************************************************************************/
|
tomwalters@0
|
735
|
tomwalters@0
|
736 if( isON( envstr ) )
|
tomwalters@0
|
737 if( whichstr[1] == 'b' )
|
tomwalters@0
|
738 whichstr[1] = 'e' ;
|
tomwalters@0
|
739 else {
|
tomwalters@0
|
740 /* map sai to sie and sas to sse */
|
tomwalters@0
|
741
|
tomwalters@0
|
742 whichstr[1] = whichstr[2] ;
|
tomwalters@0
|
743 whichstr[2] = 'e' ;
|
tomwalters@0
|
744 }
|
tomwalters@0
|
745
|
tomwalters@0
|
746
|
tomwalters@0
|
747 /***************************************************************************
|
tomwalters@0
|
748 * hack test arguments
|
tomwalters@0
|
749 ***************************************************************************/
|
tomwalters@0
|
750 #if 00
|
tomwalters@0
|
751 test1 = atof( test1str ) ;
|
tomwalters@0
|
752 test2 = atof( test2str ) ;
|
tomwalters@0
|
753 test3 = atof( test3str ) ;
|
tomwalters@0
|
754 test4 = atof( test4str ) ;
|
tomwalters@0
|
755 #endif
|
tomwalters@0
|
756
|
tomwalters@0
|
757 /***************************************************************************
|
tomwalters@0
|
758 * Open input data file, (use stdin if filename "-" is given).
|
tomwalters@0
|
759 ***************************************************************************/
|
tomwalters@0
|
760
|
tomwalters@0
|
761 if( strcmp( filestr, "-" ) == 0 )
|
tomwalters@0
|
762 inputFilePointer = stdin ;
|
tomwalters@0
|
763 else
|
tomwalters@0
|
764 inputFilePointer = fopen( filestr, readBinary ) ;
|
tomwalters@0
|
765
|
tomwalters@0
|
766 /***************************************************************************
|
tomwalters@0
|
767 * Position input data file pointer correctly:
|
tomwalters@0
|
768 * Read any options header at the start of the input file. Set any options.
|
tomwalters@0
|
769 * Skip to the start of the input data, allowing for any offset (ie startstr).
|
tomwalters@0
|
770 * Set "framesstr" to the number of frames in the input data file, (here this
|
tomwalters@0
|
771 * means the number of shorts remaining in the input file).
|
tomwalters@0
|
772 * Create a source for the input data file.
|
tomwalters@0
|
773 * Re-set "framesstr" to allow for a given "lengthstr", (ie not the whole file).
|
tomwalters@0
|
774 ***************************************************************************/
|
tomwalters@0
|
775
|
tomwalters@0
|
776 if( inputFilePointer != (FILE *) 0 ) {
|
tomwalters@0
|
777
|
tomwalters@0
|
778 readopts( options, inputFilePointer ) ;
|
tomwalters@0
|
779
|
tomwalters@0
|
780 headerSize = ftell( inputFilePointer ) ;
|
tomwalters@0
|
781
|
tomwalters@0
|
782 setFrames( fileLength( inputFilePointer ) / sizeof ( short ) - (long) Samples( startstr, Samplerate() ) ) ;
|
tomwalters@0
|
783
|
tomwalters@0
|
784 (void) fseek( inputFilePointer, (long)( headerSize + (long) Samples( startstr, Samplerate() ) * sizeof ( short ) ), 0 ) ;
|
tomwalters@0
|
785
|
tomwalters@0
|
786 source = FileSource( inputFilePointer ) ;
|
tomwalters@0
|
787 }
|
tomwalters@0
|
788
|
tomwalters@0
|
789 /* If a specific processing amount is specifed (other than "remainder") */
|
tomwalters@0
|
790 /* and this amount is less than the remainder of the input file, then */
|
tomwalters@0
|
791 /* override the amount of data to process, (in framesstr). */
|
tomwalters@0
|
792
|
tomwalters@0
|
793 if ( strncmp( lengthstr, LengthStr, strlen(lengthstr) ) != 0 &&
|
tomwalters@0
|
794 Samples( lengthstr, Samplerate() ) < Frames() )
|
tomwalters@0
|
795 setFrames( (long) ( Samples( lengthstr, Samplerate() ) ) / Framestep() ) ;
|
tomwalters@0
|
796
|
tomwalters@0
|
797
|
tomwalters@0
|
798 /***************************************************************************
|
tomwalters@0
|
799 * Create source with data derived from processing file through model.
|
tomwalters@0
|
800 * This may involve several stages of callback, and will initialize a chain of
|
tomwalters@0
|
801 * objects which will ultimately execute the program, (see SinkSource() below).
|
tomwalters@0
|
802 * If reusestr in "on", the "useprevious" option will use a previously
|
tomwalters@0
|
803 * generated file, (see checkForFile() routine below).
|
tomwalters@0
|
804 * If no input data file is found, report error: "could not open file".
|
tomwalters@0
|
805 *
|
tomwalters@0
|
806 * The routine ModeledSource() first uses Findstage() to find the appropriate
|
tomwalters@0
|
807 * place in the stage table called for by the program, (see model.c).
|
tomwalters@0
|
808 * Then it finds the end of the stage table, and works back up the table to
|
tomwalters@0
|
809 * the stage called for by the program. Each stage in the table is a process
|
tomwalters@0
|
810 * on the way to the program as a whole. The order of the stage table sets the
|
tomwalters@0
|
811 * order of processing.
|
tomwalters@0
|
812 * Immediately below are the only two calls to routine ModeledSource().
|
tomwalters@0
|
813 ***************************************************************************/
|
tomwalters@0
|
814
|
tomwalters@0
|
815 if( isON( reusestr ) )
|
tomwalters@0
|
816 source = ModeledSource( source, checkForFile ) ;
|
tomwalters@0
|
817 else
|
tomwalters@0
|
818 if( inputFilePointer != (FILE *) 0 )
|
tomwalters@0
|
819 source = ModeledSource( source, (Source ( * )()) 0 ) ;
|
tomwalters@0
|
820
|
tomwalters@0
|
821 if( inputFilePointer == (FILE *) 0 )
|
tomwalters@0
|
822 stitch_error( "Could not open file \"%s\" for input\n", filestr ) ;
|
tomwalters@0
|
823
|
tomwalters@0
|
824 /***************************************************************************
|
tomwalters@0
|
825 * If the "downchannel" option is on, reduce channels by averaging.
|
tomwalters@0
|
826 * (See DownChannel() routine below).
|
tomwalters@0
|
827 * Then updateFramebytes sets "framebytesstr" to the total number of bytes
|
tomwalters@0
|
828 * in each frame, (ie the new width * height).
|
tomwalters@0
|
829 ***************************************************************************/
|
tomwalters@0
|
830
|
tomwalters@0
|
831
|
tomwalters@0
|
832 for( time=0 ; time<OptionInt( downcstr ) ; time++ ) {
|
tomwalters@0
|
833 source = DownChannel( source, Frameheight() ) ;
|
tomwalters@0
|
834 setFrameheight( Frameheight() / 2 ) ;
|
tomwalters@0
|
835 }
|
tomwalters@0
|
836 updateFramebytes() ;
|
tomwalters@0
|
837
|
tomwalters@0
|
838 #if 0 /* for debugging */
|
tomwalters@0
|
839 fprintf( stderr, "%d %d %d %d %ld\n",
|
tomwalters@0
|
840 Framewidth(),
|
tomwalters@0
|
841 Frameheight(),
|
tomwalters@0
|
842 Framebytes(),
|
tomwalters@0
|
843 Framestep(),
|
tomwalters@0
|
844 Frames() ) ;
|
tomwalters@0
|
845 #endif
|
tomwalters@0
|
846
|
tomwalters@0
|
847 /***************************************************************************
|
tomwalters@0
|
848 * From here on is concerned with setting up for output, then starting the
|
tomwalters@0
|
849 * processing, and finally cleaning up.
|
tomwalters@0
|
850 ***************************************************************************/
|
tomwalters@0
|
851
|
tomwalters@0
|
852 #ifdef X11
|
tomwalters@0
|
853 /* First sort out window placement. */
|
tomwalters@0
|
854
|
tomwalters@0
|
855 if( strcmp( xstr, CenterStr ) == 0 )
|
tomwalters@0
|
856 x = -1 ;
|
tomwalters@0
|
857 else
|
tomwalters@0
|
858 x = atoi( xstr ) ;
|
tomwalters@0
|
859
|
tomwalters@0
|
860 if( strcmp( ystr, CenterStr ) == 0 )
|
tomwalters@0
|
861 y = -1 ;
|
tomwalters@0
|
862 else
|
tomwalters@0
|
863 y = atoi( ystr ) ;
|
tomwalters@0
|
864
|
tomwalters@0
|
865 if( isGREYSCALE( viewstr ) )
|
tomwalters@0
|
866 pixels = 0 ;
|
tomwalters@0
|
867 else {
|
tomwalters@0
|
868 pixels = atoi( penstr ) ;
|
tomwalters@0
|
869
|
tomwalters@0
|
870 if( isON( hiddenstr ) && Frameheight() > 1 )
|
tomwalters@0
|
871
|
tomwalters@0
|
872 pixels = -abs( pixels ) ;
|
tomwalters@0
|
873
|
tomwalters@0
|
874 /* Convert arguments for line-drawing. See draw.ch */
|
tomwalters@0
|
875 drawTilt = atof( tiltstr ) ;
|
tomwalters@0
|
876 drawDistance = atof( diststr ) ;
|
tomwalters@0
|
877 drawHeadroom = atof( roomstr ) ;
|
tomwalters@0
|
878 drawOverlap = atof( overstr ) / 100. ;
|
tomwalters@0
|
879 #ifdef mips
|
tomwalters@0
|
880 if( pixels == 0 )
|
tomwalters@0
|
881 pixels = 1 ;
|
tomwalters@0
|
882 #endif
|
tomwalters@0
|
883 }
|
tomwalters@0
|
884 #endif /* X11 */
|
tomwalters@0
|
885
|
tomwalters@0
|
886 /* work out title of output */
|
tomwalters@0
|
887
|
tomwalters@0
|
888 (void) strcpy( title, filestr ) ;
|
tomwalters@0
|
889 (void) strcat( title, "." ) ;
|
tomwalters@0
|
890 (void) strncat( title, whichstr, strlen( "xxx" )+1 ) ;
|
tomwalters@0
|
891
|
tomwalters@0
|
892 #ifdef X11
|
tomwalters@0
|
893
|
tomwalters@0
|
894 if( strcmp(titlestr,"filename") == 0) /* was: if(isNULL(titlestr)) */
|
tomwalters@0
|
895 titlestr = title ;
|
tomwalters@0
|
896
|
tomwalters@0
|
897 /* calculate axis information */
|
tomwalters@0
|
898
|
tomwalters@0
|
899 if( isEXCITE( viewstr ) ) {
|
tomwalters@0
|
900 ChannelAxis( &xaxis.min, &xaxis.max, &xaxis.label ) ;
|
tomwalters@0
|
901 MagnitudeAxis( &yaxis.min, &yaxis.max, &yaxis.label ) ;
|
tomwalters@0
|
902 }
|
tomwalters@0
|
903 else if( isWATERFALL( viewstr ) ) {
|
tomwalters@0
|
904 ChannelAxis( &xaxis.min, &xaxis.max, &xaxis.label ) ;
|
tomwalters@0
|
905 TimeAxis( &yaxis.min, &yaxis.max, &yaxis.label ) ;
|
tomwalters@0
|
906 } /* landscape ones */
|
tomwalters@0
|
907 else if( Framewidth() > 1 ) {
|
tomwalters@0
|
908 DelayAxis( &xaxis.min, &xaxis.max, &xaxis.label ) ;
|
tomwalters@0
|
909 ChannelAxis( &yaxis.min, &yaxis.max, &yaxis.label ) ;
|
tomwalters@0
|
910 }
|
tomwalters@0
|
911 else {
|
tomwalters@0
|
912 TimeAxis( &xaxis.min, &xaxis.max, &xaxis.label ) ;
|
tomwalters@0
|
913
|
tomwalters@0
|
914 if( Frameheight() > 1 )
|
tomwalters@0
|
915 ChannelAxis( &yaxis.min, &yaxis.max, &yaxis.label ) ;
|
tomwalters@0
|
916 else
|
tomwalters@0
|
917 MagnitudeAxis( &yaxis.min, &yaxis.max, &yaxis.label ) ;
|
tomwalters@0
|
918
|
tomwalters@0
|
919 }
|
tomwalters@0
|
920
|
tomwalters@0
|
921
|
tomwalters@0
|
922 /* select outputs... */
|
tomwalters@0
|
923
|
tomwalters@0
|
924
|
tomwalters@0
|
925 /* select sai drawing method */
|
tomwalters@0
|
926
|
tomwalters@0
|
927 /* Hack so spiral parameters are independent of stage and option order */
|
tomwalters@0
|
928 /* (Spiral parameters appear late in options list, so are not known */
|
tomwalters@0
|
929 /* when an earlier stage is specified. So don't process unless sai). */
|
tomwalters@0
|
930
|
tomwalters@0
|
931 if( strncmp(whichstr,"spl",strlen("spl")) == 0 ) {
|
tomwalters@0
|
932
|
tomwalters@0
|
933 frame_drawer = draw_spiral;
|
tomwalters@0
|
934
|
tomwalters@0
|
935 dotthresh_spl = Top() ;
|
tomwalters@0
|
936 dotsize_spl = OptionInt( penstr ) ;
|
tomwalters@0
|
937 }
|
tomwalters@0
|
938 else
|
tomwalters@0
|
939 frame_drawer = draw_frame;
|
tomwalters@0
|
940
|
tomwalters@0
|
941 /* screen output first */
|
tomwalters@0
|
942 /* (set by option: display=on) */
|
tomwalters@0
|
943
|
tomwalters@0
|
944 if( isON( dispstr ) ) {
|
tomwalters@0
|
945
|
tomwalters@0
|
946 display = newDisplayWindow( titlestr, x, y, atoi( widthstr ), atoi( heightstr ), pixels ) ;
|
tomwalters@0
|
947
|
tomwalters@0
|
948 if( !isGREYSCALE( viewstr ) /* && OptionInt( penstr ) != 0 */ ) {
|
tomwalters@0
|
949
|
tomwalters@0
|
950 if( Top() == Bot() )
|
tomwalters@0
|
951 stitch_error( "error: display top and bottom parameters the same value\n" );
|
tomwalters@0
|
952
|
tomwalters@0
|
953 if( isEXCITE( viewstr ) )
|
tomwalters@0
|
954 source = SourceDraw( source, Bot(), Top(), display, Frameheight(), 1, Nwidth(), Frames(), save_frame, frame_drawer ) ;
|
tomwalters@0
|
955 else if( isWATERFALL( viewstr ) )
|
tomwalters@0
|
956 source = SourceDraw( source, Bot(), Top(), display, Frameheight(), Frames(), Nwidth(), 1, save_frame, frame_drawer ) ;
|
tomwalters@0
|
957 else if( !isON( kludgestr ) )
|
tomwalters@0
|
958 source = SourceDraw( source, Bot(), Top(), display, Framewidth(), Frameheight(), Nwidth(), Frames(), save_frame, frame_drawer ) ;
|
tomwalters@0
|
959 else { /* speed-up for sai */
|
tomwalters@0
|
960 source = SourceDraw( source, Bot(), Top(), display, Framewidth(), Frameheight(), Nwidth(), Frames(), save_frame, fast_frame ) ;
|
tomwalters@0
|
961 gen_state = genstate( display, Bot(), Top(), Framewidth(), Frameheight(), Nwidth(), Frames(), pixels ) ;
|
tomwalters@0
|
962 frame_drawer=fast_frame ;
|
tomwalters@0
|
963 }
|
tomwalters@0
|
964 }
|
tomwalters@0
|
965 else {
|
tomwalters@0
|
966 if( isON( erasestr ) )
|
tomwalters@0
|
967 Clear( display ) ;
|
tomwalters@0
|
968
|
tomwalters@0
|
969 DrawAxes( display ) ;
|
tomwalters@0
|
970
|
tomwalters@0
|
971 if( isON( linstr ) )
|
tomwalters@0
|
972 frequency_scale = frequencies ;
|
tomwalters@0
|
973 else
|
tomwalters@0
|
974 frequency_scale = (double *) 0 ;
|
tomwalters@0
|
975
|
tomwalters@0
|
976 if( Framewidth() > 1 )
|
tomwalters@0
|
977 source = FillDown( display, source, Top(), Bot(), Framewidth(), Frameheight() ) ;
|
tomwalters@0
|
978 else
|
tomwalters@0
|
979 source = fillAcross( display, source, Top(), Bot(), Frameheight(),(int)Frames(), frequency_scale ) ;
|
tomwalters@0
|
980 }
|
tomwalters@0
|
981 }
|
tomwalters@0
|
982
|
tomwalters@0
|
983 /* postscript output next */
|
tomwalters@0
|
984 /* (set by option: postscript=on) */
|
tomwalters@0
|
985
|
tomwalters@0
|
986 if( isON( psstr ) ) {
|
tomwalters@0
|
987
|
tomwalters@0
|
988 if( isON( psfilestr ) )
|
tomwalters@0
|
989 psfilename = AlterSuffix( filestr, POSTSCRIPT_FILE_SUFFIX ) ;
|
tomwalters@0
|
990 else
|
tomwalters@0
|
991 psfilename = (char *) 0 ;
|
tomwalters@0
|
992
|
tomwalters@0
|
993 /* the extra argument to newPSWindow. MAA> 27-1-1993. */
|
tomwalters@0
|
994 psw = newPSWindow( psfilename, x, y, atoi(widthstr), atoi(heightstr), atoi( penstr ), isON( hiddenstr ) );
|
tomwalters@0
|
995
|
tomwalters@0
|
996 if( !isGREYSCALE( viewstr ) && OptionInt( penstr ) != 0 ) {
|
tomwalters@0
|
997
|
tomwalters@0
|
998 if( isEXCITE( viewstr ) )
|
tomwalters@0
|
999 source = SourceDraw( source, Bot(), Top(), psw, Frameheight(), 1, Nwidth(), Frames(), plot_frame, frame_drawer ) ;
|
tomwalters@0
|
1000 else if( isWATERFALL( viewstr ) )
|
tomwalters@0
|
1001 source = SourceDraw( source, Bot(), Top(), psw, Frameheight(), Frames(), Nwidth(), 1, plot_frame, frame_drawer ) ;
|
tomwalters@0
|
1002 else
|
tomwalters@0
|
1003 source = SourceDraw( source, Bot(), Top(), psw, Framewidth(), Frameheight(), Nwidth(), Frames(), plot_frame, frame_drawer ) ;
|
tomwalters@0
|
1004 }
|
tomwalters@0
|
1005 else { /* greyscale displays */
|
tomwalters@0
|
1006
|
tomwalters@0
|
1007 if( isON( erasestr ) )
|
tomwalters@0
|
1008 Clear( psw ) ;
|
tomwalters@0
|
1009
|
tomwalters@0
|
1010 DrawAxes( psw ) ;
|
tomwalters@0
|
1011
|
tomwalters@0
|
1012 if( isON( linstr ) )
|
tomwalters@0
|
1013 frequency_scale = frequencies ;
|
tomwalters@0
|
1014 else
|
tomwalters@0
|
1015 frequency_scale = (double *) 0 ;
|
tomwalters@0
|
1016
|
tomwalters@0
|
1017 if( Framewidth() > 1 )
|
tomwalters@0
|
1018 source = FillDown( psw, source, Top(), Bot(), Framewidth(), Frameheight() ) ;
|
tomwalters@0
|
1019 else
|
tomwalters@0
|
1020 source = fillAcross( psw, source, Top(), Bot(), Frameheight(),(int)Frames(), frequency_scale ) ;
|
tomwalters@0
|
1021 }
|
tomwalters@0
|
1022 }
|
tomwalters@0
|
1023
|
tomwalters@0
|
1024
|
tomwalters@0
|
1025 if( strcmp( typestr, "char" ) == 0 ) {
|
tomwalters@0
|
1026 source = PackShorts( source ) ;
|
tomwalters@0
|
1027 fileFramebytes = Framebytes() / sizeof ( short ) * sizeof ( char ) ;
|
tomwalters@0
|
1028 }
|
tomwalters@0
|
1029 else
|
tomwalters@0
|
1030
|
tomwalters@0
|
1031 #endif /* X11 */
|
tomwalters@0
|
1032
|
tomwalters@0
|
1033 fileFramebytes = Framebytes() ;
|
tomwalters@0
|
1034
|
tomwalters@0
|
1035 /* output to file */
|
tomwalters@0
|
1036
|
tomwalters@0
|
1037 if( !isOFF( outstr ) ) {
|
tomwalters@0
|
1038
|
tomwalters@0
|
1039 (void) unlink( title ) ;
|
tomwalters@0
|
1040
|
tomwalters@0
|
1041 if( OptionStringsEqual( outstr, OnOption ) )
|
tomwalters@0
|
1042 ofp = fopen( title, writeBinary ) ;
|
tomwalters@0
|
1043 else {
|
tomwalters@0
|
1044 if( strcmp( outstr, "stdout" ) == 0 )
|
tomwalters@0
|
1045 ofp = stdout;
|
tomwalters@0
|
1046 else
|
tomwalters@0
|
1047 ofp = fopen( outstr, writeBinary ) ;
|
tomwalters@0
|
1048 }
|
tomwalters@0
|
1049
|
tomwalters@0
|
1050 if( ofp == (FILE *) 0 )
|
tomwalters@0
|
1051 stitch_error( "Unable to open file %s for output\n", title ) ;
|
tomwalters@0
|
1052 else {
|
tomwalters@0
|
1053 if( isON( headstr ) )
|
tomwalters@0
|
1054 writeopts( options, ofp ) ;
|
tomwalters@0
|
1055
|
tomwalters@0
|
1056 source = FileTap( source, ofp ) ;
|
tomwalters@0
|
1057 }
|
tomwalters@0
|
1058 }
|
tomwalters@0
|
1059
|
tomwalters@0
|
1060 #ifdef X11
|
tomwalters@0
|
1061
|
tomwalters@0
|
1062 /* output of screen "image" files in display format */
|
tomwalters@0
|
1063 if( !isOFF( bitmapstr ) ) {
|
tomwalters@0
|
1064 imageFileName = AlterSuffix(filestr, CARTOON_FILE_SUFFIX ) ;
|
tomwalters@0
|
1065
|
tomwalters@0
|
1066 if( (strcmp( bitmapstr, "stdout" ) == 0 )){
|
tomwalters@0
|
1067 imageFilePointer = stdout;
|
tomwalters@0
|
1068 writeopts( options, imageFilePointer ) ;}
|
tomwalters@0
|
1069 else
|
tomwalters@0
|
1070 if ( ( imageFilePointer = fopen(imageFileName, writeBinary ) ) == (FILE *) 0)
|
tomwalters@0
|
1071 stitch_error( "Unable to open file %s for image output\n", imageFileName ) ;
|
tomwalters@0
|
1072 else
|
tomwalters@0
|
1073 writeopts( options, imageFilePointer ) ;}
|
tomwalters@0
|
1074
|
tomwalters@0
|
1075 if (( ofp == stdout ) && ( imageFilePointer == stdout ))
|
tomwalters@0
|
1076 stitch_error( "Both 'output' and 'bitmap' set to stdout.\n", title);
|
tomwalters@0
|
1077
|
tomwalters@0
|
1078 #endif /* X11 */
|
tomwalters@0
|
1079
|
tomwalters@0
|
1080
|
tomwalters@0
|
1081 /***************************************************************************
|
tomwalters@0
|
1082 * Execute the program by pulling data from the source.
|
tomwalters@0
|
1083 * This is the only call to routine SinkSource(), which is defined in
|
tomwalters@0
|
1084 * stitch/source.c as sinkSource().
|
tomwalters@0
|
1085 * (SinkSource is an alias, defined in stitch/source.h, to cast the arguments).
|
tomwalters@0
|
1086 * Routine sinkSource() executes: "(void) Pull( source, fileFramebytes ) ;"
|
tomwalters@0
|
1087 * for "Frames()" times in succession.
|
tomwalters@0
|
1088 * A chain of source objects, linked by callback-function pointers, was setup
|
tomwalters@0
|
1089 * earlier, (see call to ModeledSource() above).
|
tomwalters@0
|
1090 ***************************************************************************/
|
tomwalters@0
|
1091
|
tomwalters@0
|
1092
|
tomwalters@0
|
1093 SinkSource( source, fileFramebytes, Frames() ) ;
|
tomwalters@0
|
1094
|
tomwalters@0
|
1095
|
tomwalters@0
|
1096 /***************************************************************************
|
tomwalters@0
|
1097 * Clean up and close
|
tomwalters@0
|
1098 ****************************************************************************/
|
tomwalters@0
|
1099
|
tomwalters@0
|
1100 CloseSource( source ) ;
|
tomwalters@0
|
1101
|
tomwalters@0
|
1102 if( ofp != (FILE *) 0 )
|
tomwalters@0
|
1103 (void) fclose( ofp ) ;
|
tomwalters@0
|
1104
|
tomwalters@0
|
1105 #ifdef X11
|
tomwalters@0
|
1106
|
tomwalters@0
|
1107 if( psw != (WindowObject) 0 )
|
tomwalters@0
|
1108 Close( psw ) ;
|
tomwalters@0
|
1109
|
tomwalters@0
|
1110 if( display != (WindowObject) 0 ) {
|
tomwalters@0
|
1111
|
tomwalters@0
|
1112 /* animate sai's if selected */
|
tomwalters@0
|
1113
|
tomwalters@0
|
1114 do
|
tomwalters@0
|
1115 {
|
tomwalters@0
|
1116 for( image=1 ; image <= images ; image++ )
|
tomwalters@0
|
1117 for( time = OptionInt( animstr ) ; time>0 ; time-- )
|
tomwalters@0
|
1118 Recall( display, image ) ;
|
tomwalters@0
|
1119
|
tomwalters@0
|
1120 if( Pause( display ) == 'q' )
|
tomwalters@0
|
1121 break;
|
tomwalters@0
|
1122
|
tomwalters@0
|
1123 } while( isON( animstr ) ) ;
|
tomwalters@0
|
1124
|
tomwalters@0
|
1125 Close( display ) ;
|
tomwalters@0
|
1126 }
|
tomwalters@0
|
1127
|
tomwalters@0
|
1128 #endif /* X11 */
|
tomwalters@0
|
1129
|
tomwalters@0
|
1130 stitch_exit( 0 ) ;
|
tomwalters@0
|
1131 }
|
tomwalters@0
|
1132
|
tomwalters@0
|
1133 /*************************** End main *************************************/
|
tomwalters@0
|
1134
|
tomwalters@0
|
1135 /***************************************************************************
|
tomwalters@0
|
1136 * checkForFile()
|
tomwalters@0
|
1137 * Create source from file if present, to be used if reusestr in "on".
|
tomwalters@0
|
1138 * This is the "useprevious" option to use previously generated files.
|
tomwalters@0
|
1139 ***************************************************************************/
|
tomwalters@0
|
1140
|
tomwalters@0
|
1141 Source checkForFile( which )
|
tomwalters@0
|
1142 char *which ;
|
tomwalters@0
|
1143 {
|
tomwalters@0
|
1144 static Source noSource = { (struct _source *) 0 } ;
|
tomwalters@0
|
1145 long headerSize, fileFramebytes ;
|
tomwalters@0
|
1146 char file_name[200] ;
|
tomwalters@0
|
1147 FILE *tmp ;
|
tomwalters@0
|
1148
|
tomwalters@0
|
1149 (void) strcpy( file_name, filestr ) ;
|
tomwalters@0
|
1150 (void) strcat( file_name, "." ) ;
|
tomwalters@0
|
1151 (void) strcat( file_name, which ) ;
|
tomwalters@0
|
1152
|
tomwalters@0
|
1153 if( ( tmp = fopen( file_name, readBinary ) ) != ( FILE * ) 0 ) {
|
tomwalters@0
|
1154
|
tomwalters@0
|
1155 inputFilePointer = tmp ;
|
tomwalters@0
|
1156
|
tomwalters@0
|
1157 (void) fprintf( stderr, "Using existing file \"%s\"\n", file_name ) ;
|
tomwalters@0
|
1158
|
tomwalters@0
|
1159 readopts( options, inputFilePointer ) ;
|
tomwalters@0
|
1160
|
tomwalters@0
|
1161 /* the saved command line overrides options from file header */
|
tomwalters@0
|
1162
|
tomwalters@0
|
1163 if( isON( reusestr ) )
|
tomwalters@0
|
1164 cmd_line_opts( options, &argc_save, &argv_save ) ;
|
tomwalters@0
|
1165
|
tomwalters@0
|
1166 headerSize = ftell( inputFilePointer ) ;
|
tomwalters@0
|
1167
|
tomwalters@0
|
1168 if( strcmp( typestr, "char" ) == 0 )
|
tomwalters@0
|
1169 fileFramebytes = Framebytes() / 2 ;
|
tomwalters@0
|
1170 else
|
tomwalters@0
|
1171 fileFramebytes = Framebytes() ;
|
tomwalters@0
|
1172
|
tomwalters@0
|
1173 /*
|
tomwalters@0
|
1174 If length=remainder then use the whole file.
|
tomwalters@0
|
1175 Otherwise the length of the reused file is that given on the command
|
tomwalters@0
|
1176 line, or the default length (if no length option is given).
|
tomwalters@0
|
1177 */
|
tomwalters@0
|
1178
|
tomwalters@0
|
1179 if ( strncmp( lengthstr, LengthStr, strlen(lengthstr) ) == 0 )
|
tomwalters@0
|
1180 setFrames( ( fileLength( inputFilePointer ) - headerSize ) / fileFramebytes - (long) Samples( startstr, Samplerate() ) / Framestep() ) ;
|
tomwalters@0
|
1181 else
|
tomwalters@0
|
1182 setFrames( (long) ( Samples( lengthstr, Samplerate() ) ) / Framestep() ) ;
|
tomwalters@0
|
1183
|
tomwalters@0
|
1184
|
tomwalters@0
|
1185 (void) fseek( inputFilePointer, headerSize + (long) Samples( startstr, Samplerate() ) / Framestep() * fileFramebytes, 0 ) ;
|
tomwalters@0
|
1186
|
tomwalters@0
|
1187 #ifndef PC
|
tomwalters@0
|
1188 if( strcmp( typestr, "char" ) == 0 )
|
tomwalters@0
|
1189 return( CharShortSource( FileSource( inputFilePointer ) ) ) ;
|
tomwalters@0
|
1190 else
|
tomwalters@0
|
1191 #endif
|
tomwalters@0
|
1192 return( FileSource( inputFilePointer ) ) ;
|
tomwalters@0
|
1193 }
|
tomwalters@0
|
1194 else
|
tomwalters@0
|
1195 return( noSource ) ;
|
tomwalters@0
|
1196 }
|
tomwalters@0
|
1197
|
tomwalters@0
|
1198 /***************************************************************************
|
tomwalters@0
|
1199 * AlterSuffix().
|
tomwalters@0
|
1200 * Returns its argument fileName with a newSuffix appended in place of
|
tomwalters@0
|
1201 * any previous suffix it may have had. It should be noted that this
|
tomwalters@0
|
1202 * suffix must include any DOT it wishes to have appended to the name.
|
tomwalters@0
|
1203 ***************************************************************************/
|
tomwalters@0
|
1204
|
tomwalters@0
|
1205 /* File Name Suffix Conversion Parameters */
|
tomwalters@0
|
1206
|
tomwalters@0
|
1207 #define BACKSLASH_CHAR '\\'
|
tomwalters@0
|
1208 #define SLASH_CHARACTER '/'
|
tomwalters@0
|
1209 #define NULL_CHARACTER '\000'
|
tomwalters@0
|
1210 #define DOT_CHARACTER '.'
|
tomwalters@0
|
1211
|
tomwalters@0
|
1212 char *AlterSuffix(fileName, newSuffix)
|
tomwalters@0
|
1213 char *fileName, *newSuffix;
|
tomwalters@0
|
1214 {
|
tomwalters@0
|
1215 char *temp, *temp2, *lastPart;
|
tomwalters@0
|
1216 #if defined( PC )
|
tomwalters@0
|
1217 int i;
|
tomwalters@0
|
1218 #endif
|
tomwalters@0
|
1219
|
tomwalters@0
|
1220 temp = stitch_malloc((unsigned) (strlen(fileName) + strlen(newSuffix) + 1), "AlterSuffix" );
|
tomwalters@0
|
1221
|
tomwalters@0
|
1222 temp = strcpy(temp, fileName);
|
tomwalters@0
|
1223
|
tomwalters@0
|
1224 #if defined(PC)
|
tomwalters@0
|
1225 /* Change all backslashes to forward slashes */
|
tomwalters@0
|
1226 for (i = 0; temp[i] != NULL_CHARACTER; i++)
|
tomwalters@0
|
1227 if (temp[i] == BACKSLASH_CHAR)
|
tomwalters@0
|
1228 temp[i] = SLASH_CHARACTER;
|
tomwalters@0
|
1229 #endif
|
tomwalters@0
|
1230
|
tomwalters@0
|
1231 if ((lastPart = strrchr(temp, SLASH_CHARACTER)) == NULL)
|
tomwalters@0
|
1232 lastPart = temp;
|
tomwalters@0
|
1233 else
|
tomwalters@0
|
1234 lastPart++; /* Skip over the actual "/" */
|
tomwalters@0
|
1235
|
tomwalters@0
|
1236 /* lastPart points to the tail name of the path */
|
tomwalters@0
|
1237
|
tomwalters@0
|
1238 if ((temp2 = strchr(lastPart, DOT_CHARACTER)) == NULL)
|
tomwalters@0
|
1239 temp = strcat(temp, newSuffix);
|
tomwalters@0
|
1240 else
|
tomwalters@0
|
1241 temp2 = strcpy(temp2, newSuffix);
|
tomwalters@0
|
1242
|
tomwalters@0
|
1243 return (temp);
|
tomwalters@0
|
1244 }
|
tomwalters@0
|
1245
|
tomwalters@0
|
1246 #ifdef X11
|
tomwalters@0
|
1247
|
tomwalters@0
|
1248 /***************************************************************************
|
tomwalters@0
|
1249 * Interceptions for various combinations of drawing.
|
tomwalters@0
|
1250 * An "interception function" is a function inserted into a chain a functions
|
tomwalters@0
|
1251 * linked by function pointers. The inserted function "intercepts" the
|
tomwalters@0
|
1252 * processing, to perform some transformation.
|
tomwalters@0
|
1253 ****************************************************************************/
|
tomwalters@0
|
1254
|
tomwalters@0
|
1255 /* intercept draw to store images for animation */
|
tomwalters@0
|
1256
|
tomwalters@0
|
1257 void save_frame( state, frame, first )
|
tomwalters@0
|
1258 struct _draw_state *state ;
|
tomwalters@0
|
1259 short *frame ;
|
tomwalters@0
|
1260 int first ;
|
tomwalters@0
|
1261 {
|
tomwalters@0
|
1262 if( first ) {
|
tomwalters@0
|
1263 if( isON( erasestr ) )
|
tomwalters@0
|
1264 Clear( state->window ) ;
|
tomwalters@0
|
1265
|
tomwalters@0
|
1266 if( frame_drawer != (void (*)()) draw_spiral && state->framenumber == 1 )
|
tomwalters@0
|
1267 DrawAxes( state->window ) ;
|
tomwalters@0
|
1268 }
|
tomwalters@0
|
1269
|
tomwalters@0
|
1270 frame_drawer( state, frame ) ;
|
tomwalters@0
|
1271
|
tomwalters@0
|
1272 if( isON( animstr ) && isOFF( kludgestr ) )
|
tomwalters@0
|
1273 if( Store( state->window ) )
|
tomwalters@0
|
1274 ++images ;
|
tomwalters@0
|
1275
|
tomwalters@0
|
1276 if( isON( bitmapstr ) )
|
tomwalters@0
|
1277 Write( state->window, imageFilePointer ) ;
|
tomwalters@0
|
1278
|
tomwalters@0
|
1279 return ;
|
tomwalters@0
|
1280 }
|
tomwalters@0
|
1281
|
tomwalters@0
|
1282 /* hacky but effective faster frame drawing routine - for sai only! */
|
tomwalters@0
|
1283
|
tomwalters@0
|
1284 void fast_frame( state, frame, first )
|
tomwalters@0
|
1285 struct _draw_state *state ;
|
tomwalters@0
|
1286 short *frame ;
|
tomwalters@0
|
1287 int first ;
|
tomwalters@0
|
1288 {
|
tomwalters@0
|
1289 if( isON( animstr ) || images == 0 )
|
tomwalters@0
|
1290 if( Store( state->window ) )
|
tomwalters@0
|
1291 ++images ;
|
tomwalters@0
|
1292
|
tomwalters@0
|
1293 /* generate image in current cleared image */
|
tomwalters@0
|
1294
|
tomwalters@0
|
1295 generate( gen_state, frame ) ;
|
tomwalters@0
|
1296
|
tomwalters@0
|
1297 /* then recal the window using the modified image */
|
tomwalters@0
|
1298
|
tomwalters@0
|
1299 Recall( state->window, images );
|
tomwalters@0
|
1300
|
tomwalters@0
|
1301 return ;
|
tomwalters@0
|
1302 }
|
tomwalters@0
|
1303
|
tomwalters@0
|
1304 /* intercept plot to check if page should be output for printing */
|
tomwalters@0
|
1305
|
tomwalters@0
|
1306 static int plot_wanted( state )
|
tomwalters@0
|
1307 struct _draw_state *state ;
|
tomwalters@0
|
1308 {
|
tomwalters@0
|
1309 #if !defined(PC)
|
tomwalters@0
|
1310 if( display != ( WindowObject ) 0 && state->framewidth > 1 && state->frames > 1 ) {
|
tomwalters@0
|
1311 (void) fprintf(stderr, "Hit \"y\" to include this image in the PostScript file: ");
|
tomwalters@0
|
1312
|
tomwalters@0
|
1313 switch ( Pause( display ) ) {
|
tomwalters@0
|
1314
|
tomwalters@0
|
1315 case 'y' : case 'Y' :
|
tomwalters@0
|
1316 case 'p' : case 'P' :
|
tomwalters@0
|
1317 return 1 ;
|
tomwalters@0
|
1318
|
tomwalters@0
|
1319 default :
|
tomwalters@0
|
1320 return 0 ;
|
tomwalters@0
|
1321 }
|
tomwalters@0
|
1322 }
|
tomwalters@0
|
1323 #endif
|
tomwalters@0
|
1324 return 1 ;
|
tomwalters@0
|
1325 }
|
tomwalters@0
|
1326
|
tomwalters@0
|
1327 void plot_frame( state, frame, first )
|
tomwalters@0
|
1328 struct _draw_state *state ;
|
tomwalters@0
|
1329 short *frame ;
|
tomwalters@0
|
1330 int first ;
|
tomwalters@0
|
1331 {
|
tomwalters@0
|
1332 int centering = state->window->entries->x( state->window ) < 0 &&
|
tomwalters@0
|
1333 state->window->entries->y( state->window ) < 0 ;
|
tomwalters@0
|
1334
|
tomwalters@0
|
1335 if( isOFF( erasestr ) || state->framewidth == 1 || plot_wanted( state ) ) {
|
tomwalters@0
|
1336
|
tomwalters@0
|
1337 if( first && ( state->framenumber == 1 || isON( erasestr ) ) ) {
|
tomwalters@0
|
1338 /* *** if( centering ) *** removed the conditional. M.Akeroyd. 22-1-1993.*/
|
tomwalters@0
|
1339 Clear( state->window ) ;
|
tomwalters@0
|
1340
|
tomwalters@0
|
1341 if( frame_drawer != (void (*)()) draw_spiral )
|
tomwalters@0
|
1342 DrawAxes( state->window ) ;
|
tomwalters@0
|
1343 }
|
tomwalters@0
|
1344
|
tomwalters@0
|
1345 frame_drawer( state, frame ) ;
|
tomwalters@0
|
1346 }
|
tomwalters@0
|
1347
|
tomwalters@0
|
1348 return ;
|
tomwalters@0
|
1349 }
|
tomwalters@0
|
1350
|
tomwalters@0
|
1351 #endif /* X11 */
|
tomwalters@0
|
1352
|
tomwalters@0
|
1353 /***************************************************************************
|
tomwalters@0
|
1354 * downchannel: average across channels for output (with special sai version)
|
tomwalters@0
|
1355 ***************************************************************************/
|
tomwalters@0
|
1356
|
tomwalters@0
|
1357 struct _down_channel_state {
|
tomwalters@0
|
1358 struct _fillable_source parent ;
|
tomwalters@0
|
1359 int channels ;
|
tomwalters@0
|
1360 Source input ;
|
tomwalters@0
|
1361 } ;
|
tomwalters@0
|
1362
|
tomwalters@0
|
1363
|
tomwalters@0
|
1364 static Pointer down_channel_callback( state, bytes, buffer )
|
tomwalters@0
|
1365 struct _down_channel_state *state ;
|
tomwalters@0
|
1366 ByteCount *bytes ;
|
tomwalters@0
|
1367 short *buffer ;
|
tomwalters@0
|
1368 {
|
tomwalters@0
|
1369 register int last = *bytes == 0 ;
|
tomwalters@0
|
1370 register int chan, outchans = state->channels >> 1 ;
|
tomwalters@0
|
1371 long frame, frames = ToPoints( short, *bytes ) / outchans ;
|
tomwalters@0
|
1372 register short *iptr = PullItems( state->input, frames * state->channels, short ) ;
|
tomwalters@0
|
1373 register short *bptr = buffer ;
|
tomwalters@0
|
1374
|
tomwalters@0
|
1375 for( frame=0 ; frame<frames ; frame++ ) {
|
tomwalters@0
|
1376 for( chan=0 ; chan<outchans ; chan++ )
|
tomwalters@0
|
1377 *bptr++ = ( *iptr++ + *iptr++ ) / 2 ;
|
tomwalters@0
|
1378
|
tomwalters@0
|
1379 if( ( outchans << 1 ) != state->channels )
|
tomwalters@0
|
1380 iptr++ ;
|
tomwalters@0
|
1381 }
|
tomwalters@0
|
1382
|
tomwalters@0
|
1383 if( !last )
|
tomwalters@0
|
1384 return ( (Pointer) buffer ) ;
|
tomwalters@0
|
1385 else
|
tomwalters@0
|
1386 return ( DeleteFillableSource( state ) ) ;
|
tomwalters@0
|
1387 }
|
tomwalters@0
|
1388
|
tomwalters@0
|
1389 static Pointer down_channel_callback_sai( state, bytes, buffer )
|
tomwalters@0
|
1390 struct _down_channel_state *state ;
|
tomwalters@0
|
1391 ByteCount *bytes ;
|
tomwalters@0
|
1392 short *buffer ;
|
tomwalters@0
|
1393 {
|
tomwalters@0
|
1394 register int last = *bytes == 0 ;
|
tomwalters@0
|
1395 register int chan, outchans = state->channels >> 1 ;
|
tomwalters@0
|
1396 long frame, frames = ToPoints( short, *bytes ) / outchans ;
|
tomwalters@0
|
1397 register short *iptr = PullItems( state->input, frames * state->channels, short ) ;
|
tomwalters@0
|
1398 register short *bptr = buffer ;
|
tomwalters@0
|
1399 register short *iptr2 ;
|
tomwalters@0
|
1400
|
tomwalters@0
|
1401 iptr2 = iptr + frames ;
|
tomwalters@0
|
1402 for( chan=0 ; chan<outchans ; chan++ ) {
|
tomwalters@0
|
1403 for( frame=0 ; frame<frames ; frame++ )
|
tomwalters@0
|
1404 *bptr++ = ( *iptr++ + *iptr2++ ) / 2 ;
|
tomwalters@0
|
1405 }
|
tomwalters@0
|
1406
|
tomwalters@0
|
1407 if( !last )
|
tomwalters@0
|
1408 return ( (Pointer) buffer ) ;
|
tomwalters@0
|
1409 else
|
tomwalters@0
|
1410 return ( DeleteFillableSource( state ) ) ;
|
tomwalters@0
|
1411 }
|
tomwalters@0
|
1412
|
tomwalters@0
|
1413
|
tomwalters@0
|
1414 Source DownChannel( source, channels )
|
tomwalters@0
|
1415 Source source ;
|
tomwalters@0
|
1416 {
|
tomwalters@0
|
1417 DeclareNew( struct _down_channel_state *, state ) ;
|
tomwalters@0
|
1418
|
tomwalters@0
|
1419 state->channels = channels ;
|
tomwalters@0
|
1420 state->input = source ;
|
tomwalters@0
|
1421
|
tomwalters@0
|
1422
|
tomwalters@0
|
1423 /* Hack for special-case downchannel routine to handle format of sai and spl frames (mha: 22/6/93) */
|
tomwalters@0
|
1424
|
tomwalters@0
|
1425 if( strncmp(whichstr,"sai",strlen("sai")) == 0 ||
|
tomwalters@0
|
1426 strncmp(whichstr,"spl",strlen("spl")) == 0 )
|
tomwalters@0
|
1427
|
tomwalters@0
|
1428 return ( SetFillableSource( state, down_channel_callback_sai, "down channeling sai frames" ) ) ;
|
tomwalters@0
|
1429
|
tomwalters@0
|
1430 return ( SetFillableSource( state, down_channel_callback, "down channeling" ) ) ;
|
tomwalters@0
|
1431 }
|
tomwalters@0
|
1432
|
tomwalters@0
|
1433
|
tomwalters@0
|
1434 #ifdef X11
|
tomwalters@0
|
1435
|
tomwalters@0
|
1436 /***************************************************************************
|
tomwalters@0
|
1437 * Pack model output onto a single byte if required,
|
tomwalters@0
|
1438 * using greyscale Top() from display.
|
tomwalters@0
|
1439 ***************************************************************************/
|
tomwalters@0
|
1440
|
tomwalters@0
|
1441 typedef struct { struct _fillable_source parent ; Source input ; } *PackSource ;
|
tomwalters@0
|
1442
|
tomwalters@0
|
1443 static Pointer pack_callback( state, bytes, buffer )
|
tomwalters@0
|
1444 PackSource state ;
|
tomwalters@0
|
1445 ByteCount *bytes ;
|
tomwalters@0
|
1446 Pointer buffer ;
|
tomwalters@0
|
1447 {
|
tomwalters@0
|
1448 register int last = *bytes == 0 ;
|
tomwalters@0
|
1449 register short *iptr = PullShorts( state->input, *bytes ) ;
|
tomwalters@0
|
1450 register Pointer optr = buffer ;
|
tomwalters@0
|
1451 register Pointer eptr = buffer + *bytes ;
|
tomwalters@0
|
1452 register int bytemax = atoi( bmaxstr ) ;
|
tomwalters@0
|
1453 register int max = Top() ;
|
tomwalters@0
|
1454 register int min = Bot() ;
|
tomwalters@0
|
1455
|
tomwalters@0
|
1456 while( optr < eptr )
|
tomwalters@0
|
1457 if( *iptr > max ) {
|
tomwalters@0
|
1458 *optr++ = bytemax ;
|
tomwalters@0
|
1459 iptr++ ;
|
tomwalters@0
|
1460 }
|
tomwalters@0
|
1461 else if( *iptr < min ) {
|
tomwalters@0
|
1462 *optr++ = 0 ;
|
tomwalters@0
|
1463 iptr++ ;
|
tomwalters@0
|
1464 }
|
tomwalters@0
|
1465 else
|
tomwalters@0
|
1466 *optr++ = ( ( ( *iptr++ - min ) * bytemax + ( bytemax >> 1 ) ) / ( max - min ) ) & 0xff ;
|
tomwalters@0
|
1467
|
tomwalters@0
|
1468 if( !last )
|
tomwalters@0
|
1469 return ( buffer ) ;
|
tomwalters@0
|
1470 else
|
tomwalters@0
|
1471 return ( DeleteFillableSource( state ) ) ;
|
tomwalters@0
|
1472 }
|
tomwalters@0
|
1473
|
tomwalters@0
|
1474
|
tomwalters@0
|
1475 Source PackShorts( input )
|
tomwalters@0
|
1476 Source input ;
|
tomwalters@0
|
1477 {
|
tomwalters@0
|
1478 DeclareNew( PackSource, source ) ;
|
tomwalters@0
|
1479
|
tomwalters@0
|
1480 source->input = input ;
|
tomwalters@0
|
1481
|
tomwalters@0
|
1482 return ( SetFillableSource( source, pack_callback, "gen.c packing" ) ) ;
|
tomwalters@0
|
1483 }
|
tomwalters@0
|
1484
|
tomwalters@0
|
1485 #endif /* X11 */
|
tomwalters@0
|
1486
|
tomwalters@0
|
1487 /***************************************************************************/
|
tomwalters@0
|
1488
|
tomwalters@0
|
1489 #ifdef PC
|
tomwalters@0
|
1490 static lowerArgs( argv, argc )
|
tomwalters@0
|
1491 char **argv ;
|
tomwalters@0
|
1492 int argc ;
|
tomwalters@0
|
1493 {
|
tomwalters@0
|
1494 register char *ptr ;
|
tomwalters@0
|
1495 register int arg ;
|
tomwalters@0
|
1496
|
tomwalters@0
|
1497 for( arg=0 ; arg<=argc ; arg++ )
|
tomwalters@0
|
1498 for( ptr=argv[arg] ; *ptr != '\000' ; ptr++ )
|
tomwalters@0
|
1499 if( isupper( *ptr ) )
|
tomwalters@0
|
1500 *ptr = tolower( (int) *ptr ) ;
|
tomwalters@0
|
1501 return ;
|
tomwalters@0
|
1502 }
|
tomwalters@0
|
1503 #endif
|
tomwalters@0
|
1504
|
tomwalters@0
|
1505
|
tomwalters@0
|
1506 /***************************************************************************
|
tomwalters@0
|
1507 * Set the value of versionstr to the model version number and current time.
|
tomwalters@0
|
1508 * The version number is the sccs <release-number>.<level-number> of the file
|
tomwalters@0
|
1509 * version.c. The current time is returned by ctime(time(0)).
|
tomwalters@0
|
1510 * This routine initializes the default version-string (headerstr), which is
|
tomwalters@0
|
1511 * later copied into the version-string (versionstr) during getopts().
|
tomwalters@0
|
1512 * In this way, the version-string is available for output at the head of
|
tomwalters@0
|
1513 * the help and the options (rc) files, and also output as part of the header,
|
tomwalters@0
|
1514 * (when output=on).
|
tomwalters@0
|
1515 * Note, the versionstr has to be quoted, otherwise the routine
|
tomwalters@0
|
1516 * processOptionFile in options.c will report an error (Detected Trailing...)
|
tomwalters@0
|
1517 * when it finds blanks within a line. This happens when trying to read an
|
tomwalters@0
|
1518 * options file, for example when reviewing. The addition of quotes enables
|
tomwalters@0
|
1519 * a line containing blanks to be read complete by the subroutine getName.
|
tomwalters@0
|
1520 ***************************************************************************/
|
tomwalters@0
|
1521
|
tomwalters@0
|
1522 #include "version.c"
|
tomwalters@0
|
1523
|
tomwalters@0
|
1524 getversion( name )
|
tomwalters@0
|
1525 char *name ;
|
tomwalters@0
|
1526 {
|
tomwalters@0
|
1527 char releasestr[8] ;
|
tomwalters@0
|
1528 char levelstr[8] ;
|
tomwalters@0
|
1529 char timestr[32] ;
|
tomwalters@0
|
1530 char *namestr ;
|
tomwalters@0
|
1531 long int timeval ;
|
tomwalters@0
|
1532
|
tomwalters@0
|
1533 sprintf(releasestr, "%d", atoi( version_Id ) ) ;
|
tomwalters@0
|
1534 sprintf(levelstr, "%d", atoi( version_Id + strlen(releasestr) + 1 ) ) ;
|
tomwalters@0
|
1535
|
tomwalters@0
|
1536 if ( ( namestr = strrchr( name, '/' ) ) == (char *)0 ) namestr = name ;
|
tomwalters@0
|
1537 else namestr++ ;
|
tomwalters@0
|
1538
|
tomwalters@0
|
1539 #if defined( PC ) || defined( THINK_C )
|
tomwalters@0
|
1540 sprintf(headerstr, "\"AIM MRC-APU Release R%s.%s [%s]\"", releasestr, levelstr, namestr ) ;
|
tomwalters@0
|
1541 #else
|
tomwalters@0
|
1542 timeval = time(0);
|
tomwalters@0
|
1543 sprintf(timestr,"%s", ctime(&timeval) ) ;
|
tomwalters@0
|
1544 timestr[strlen(timestr) - 1] = '\0'; /* remove newline */
|
tomwalters@0
|
1545 sprintf(headerstr, "\"AIM MRC-APU Release R%s.%s [%s] %s\"", releasestr, levelstr, namestr, timestr ) ;
|
tomwalters@0
|
1546 #endif
|
tomwalters@0
|
1547
|
tomwalters@0
|
1548 }
|