1 | |
---|
2 | /* file animatrix.c |
---|
3 | * =========== |
---|
4 | * |
---|
5 | * version 7, 22-Mar-2006 |
---|
6 | * |
---|
7 | * animate matrices |
---|
8 | * K. Stammler, 31-Oct-97 |
---|
9 | */ |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | #include <stdio.h> |
---|
14 | #include <math.h> |
---|
15 | #include "../basecnst.h" |
---|
16 | #include <Xm/Xm.h> |
---|
17 | #include <Mrm/MrmPublic.h> |
---|
18 | #undef BC_DEFINE_TRUE_FALSE |
---|
19 | #ifdef BC_INC_STDLIB |
---|
20 | #include BC_INC_STDLIB |
---|
21 | #endif |
---|
22 | #include BC_SYSBASE |
---|
23 | #include BC_CPAR |
---|
24 | #include "../motif/pixmaps.h" |
---|
25 | #include "../tcusrdef.h" |
---|
26 | |
---|
27 | #define MY_PI 3.14159265358979323846 |
---|
28 | #define MY_E 2.7182818284590452354 |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | #define w_toplevel 0 |
---|
33 | #define w_main 1 |
---|
34 | #define w_draw 2 |
---|
35 | #define w_menu_main 5 |
---|
36 | #define w_entry_quit 51 |
---|
37 | #define w_entry_plot 52 |
---|
38 | #define w_entry_plot_log 53 |
---|
39 | #define w_entry_plot_p2 54 |
---|
40 | #define w_entry_plot_p4 55 |
---|
41 | #define w_entry_radial_grid 56 |
---|
42 | #define w_entry_colors_green_red 57 |
---|
43 | #define w_entry_colors_blue_red 58 |
---|
44 | #define w_entry_colors_black_white 59 |
---|
45 | #define w_entry_colors_blue_yellow 60 |
---|
46 | #define w_entry_readnext 61 |
---|
47 | #define w_entry_readprev 62 |
---|
48 | #define w_entry_readloop 63 |
---|
49 | #define MmcMAX_WIDGET 100 |
---|
50 | |
---|
51 | #define MmcMAX_COLOR 101 |
---|
52 | #define MmcMAXCMT 16 |
---|
53 | |
---|
54 | #define MmcCHARHEIGHT 30 |
---|
55 | |
---|
56 | #define MmcCOLORS_GREEN_RED 1 |
---|
57 | #define MmcCOLORS_BLUE_RED 2 |
---|
58 | #define MmcCOLORS_BLACK_WHITE 3 |
---|
59 | #define MmcCOLORS_BLUE_YELLOW 4 |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | /* local types */ |
---|
65 | |
---|
66 | typedef struct { |
---|
67 | float **val; /* pointer to matrix */ |
---|
68 | int width; /* width of matrix */ |
---|
69 | int height; /* height of matrix */ |
---|
70 | float minval; /* minimum value */ |
---|
71 | float maxval; /* maximum value */ |
---|
72 | } MmtMATRIX; |
---|
73 | |
---|
74 | typedef struct { |
---|
75 | int colnum; /* number of colors */ |
---|
76 | unsigned margin_l; /* left margin */ |
---|
77 | unsigned margin_r; /* right margin */ |
---|
78 | unsigned margin_t; /* top margin */ |
---|
79 | unsigned margin_b; /* bottom margin */ |
---|
80 | } MmtDSP_SETUP; |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | /* global variables */ |
---|
85 | static char *mmv_vec[]={"animatrix.uid"}; /* MRM database file list */ |
---|
86 | static Display *mmv_display; /* display */ |
---|
87 | static Widget mmv_w[MmcMAX_WIDGET]; /* widget array */ |
---|
88 | static char mmv_pname[BC_FILELTH+1]; /* program name */ |
---|
89 | static MmtMATRIX mmv_matrix; /* matrix */ |
---|
90 | static MmtDSP_SETUP mmv_setup; /* display setup */ |
---|
91 | static GC mmv_gc[MmcMAX_COLOR]; /* color gc's */ |
---|
92 | static GC mmv_cleargc; /* for erasing */ |
---|
93 | |
---|
94 | static char mmv_cmt[MmcMAXCMT][BC_LINELTH+1]; /* comment lines */ |
---|
95 | static int mmv_cmtcnt; /* comment counter */ |
---|
96 | static float mmv_scale; /* scale factor */ |
---|
97 | static float mmv_yscale; /* y-scale factor (cart.) */ |
---|
98 | static BOOLEAN mmv_pixinit=FALSE; /* pixel buffer initialized */ |
---|
99 | static BOOLEAN mmv_grid_on=TRUE; /* draw grid */ |
---|
100 | static BOOLEAN mmv_cartesian; /* cartesian coo. system */ |
---|
101 | static char mmv_abstime[cBcTimeLth+1]; /* absolute time */ |
---|
102 | static float mmv_ymin; /* y start value (cart) */ |
---|
103 | static BOOLEAN mmv_square_it; /* square input data */ |
---|
104 | static char mmv_inpfile[BC_FILELTH+1]; /* name of input file */ |
---|
105 | static int mmv_fcnt; /* file counter */ |
---|
106 | static int mmv_stepnum=100; /* number of steps */ |
---|
107 | static int mmv_sleep=0; /* sleep time in us */ |
---|
108 | static float mmv_relpow=1.0; /* relative power of FK */ |
---|
109 | static float mmv_peakqual=0.0; /* FK peak quality number */ |
---|
110 | static float mmv_colscale=1.0; /* color scaling based on relpow */ |
---|
111 | static BOOLEAN mmv_powscale=FALSE; /* scale with rel. power */ |
---|
112 | static float mmv_minrelpow=1.1; /* min. relpow for detection */ |
---|
113 | static float mmv_minpeakqual=1.0e20; /* min. peakqual for detect. */ |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | /* prototypes */ |
---|
118 | static void cb_call_create_widget( Widget widget, int *tag, |
---|
119 | XmAnyCallbackStruct *data ); |
---|
120 | static void cb_call_activate( Widget widget, int *tag, |
---|
121 | XmToggleButtonCallbackStruct *data ); |
---|
122 | void cb_action_motion_rad( Widget w, XEvent *ev, String *params, |
---|
123 | Cardinal *parno ); |
---|
124 | void cb_action_motion_cart( Widget w, XEvent *ev, String *params, |
---|
125 | Cardinal *parno ); |
---|
126 | static void cb_call_expose( Widget widget, char *tag, |
---|
127 | XmDrawingAreaCallbackStruct *data ); |
---|
128 | |
---|
129 | static void mm_prepare_gc( Widget w, MmtDSP_SETUP *setup, GC gc[] ); |
---|
130 | static void mm_read_matrix( char filename[], BOOLEAN sqr, MmtMATRIX *mat ); |
---|
131 | static void mm_display_matrix( Widget w, GC gc[], MmtDSP_SETUP *setup, |
---|
132 | MmtMATRIX *mat, int power ); |
---|
133 | static void mm_draw_radial_grid( Widget w ); |
---|
134 | static void mm_change_gc( Widget w, int mode, MmtDSP_SETUP *setup, GC gc[] ); |
---|
135 | |
---|
136 | |
---|
137 | /* routines to register */ |
---|
138 | static MrmCount mmv_regnum = 3 ; |
---|
139 | static MrmRegisterArg mmv_regvec[] = { |
---|
140 | { "call_create_widget", (caddr_t)cb_call_create_widget }, |
---|
141 | { "call_activate", (caddr_t)cb_call_activate }, |
---|
142 | { "call_expose", (caddr_t)cb_call_expose } |
---|
143 | }; |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | /* action routines */ |
---|
148 | static XtActionsRec mmv_new_actions_rad[] = { |
---|
149 | {"cb_action_motion_rad", cb_action_motion_rad} |
---|
150 | }; |
---|
151 | static XtActionsRec mmv_new_actions_cart[] = { |
---|
152 | {"cb_action_motion_cart", cb_action_motion_cart} |
---|
153 | }; |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | int main( int argc, char *argv[] ) |
---|
158 | { |
---|
159 | /* local variables */ |
---|
160 | MrmHierarchy hierarchy; /* hierarchy */ |
---|
161 | MrmCode class; /* class */ |
---|
162 | XtAppContext app_context; /* application contex */ |
---|
163 | Arg arglist[2]; |
---|
164 | int n; |
---|
165 | int pix_w, pix_h; /* size of window in pixel */ |
---|
166 | char fname[cBcFileLth+1]; /* filename to use */ |
---|
167 | int i; /* counter */ |
---|
168 | TSyBoolean interactive=TRUE; /* interactive mode */ |
---|
169 | |
---|
170 | /* executable code */ |
---|
171 | |
---|
172 | pa_init( argc, argv ); |
---|
173 | pix_w = pix_h = 0; |
---|
174 | |
---|
175 | if (pa_pnumber() < 4) { |
---|
176 | fprintf( stderr, "*** Usage: %s <file-prefix> <colnum> <maxslow> <firstnum> [<loopcnt>]***\n", |
---|
177 | argv[0] ); |
---|
178 | fprintf( stderr, " parameters:\n" ); |
---|
179 | fprintf( stderr, " <file-prefix> file prefix of fk files (without number)\n" ); |
---|
180 | fprintf( stderr, " <colnum> number of colours used\n" ); |
---|
181 | fprintf( stderr, " <maxslow> maximum slowness of FK spectra\n" ); |
---|
182 | fprintf( stderr, " <firstnum> starting number of FK file\n" ); |
---|
183 | fprintf( stderr, " <loopcnt> number of files to loop on loop menu entry\n" ); |
---|
184 | fprintf( stderr, " qualifiers:\n" ); |
---|
185 | fprintf( stderr, " -w=<pixwidth> width of display window in pixel\n" ); |
---|
186 | fprintf( stderr, " -h=<pixheight> height of display window in pixel\n" ); |
---|
187 | fprintf( stderr, " -r=<pixmargin> right margin pixels\n" ); |
---|
188 | fprintf( stderr, " -noninter noninteractive mode, immediately start loop\n" ); |
---|
189 | fprintf( stderr, " -sleep=<microsec> sleep time between pictures\n" ); |
---|
190 | fprintf( stderr, " -nogrid no slowness/azimuth grid lines\n" ); |
---|
191 | fprintf( stderr, " -powscale scale colours by rel. power (>0.5=full)\n" ); |
---|
192 | fprintf( stderr, " -square square spectra before plotting\n" ); |
---|
193 | fprintf( stderr, " -minrelpow=<rp> minimum rel power for detection\n" ); |
---|
194 | fprintf( stderr, " -minpeakqual=<q> minimum peak quality for detection\n" ); |
---|
195 | return 1; |
---|
196 | } /*endif*/ |
---|
197 | |
---|
198 | /* set margins */ |
---|
199 | mmv_setup.margin_l = 20; |
---|
200 | mmv_setup.margin_r = 320; |
---|
201 | mmv_setup.margin_t = 20; |
---|
202 | mmv_setup.margin_b = 20; |
---|
203 | |
---|
204 | /* strcpy( mmv_pname, argv[0] ); */ |
---|
205 | strcpy( mmv_pname, "animatrix" ); |
---|
206 | strcpy( mmv_inpfile, pa_pvalue(1) ); |
---|
207 | sscanf( pa_pvalue(2), "%d", &mmv_setup.colnum ); |
---|
208 | sscanf( pa_pvalue(3), "%f", &mmv_scale ); |
---|
209 | sscanf( pa_pvalue(4), "%d", &mmv_fcnt ); |
---|
210 | if (pa_pnumber() >= 5) |
---|
211 | sscanf( pa_pvalue(5), "%d", &mmv_stepnum ); |
---|
212 | if (mmv_setup.colnum < 2) mmv_setup.colnum = 2; |
---|
213 | if (mmv_setup.colnum > 500) mmv_setup.colnum = 500; |
---|
214 | if (pa_qspecified("-w")) { |
---|
215 | sscanf( pa_qvalue("-w"), "%d", &pix_w ); |
---|
216 | if (pix_w < 400) pix_w = 400; |
---|
217 | } /*endif*/ |
---|
218 | if (pa_qspecified("-h")) { |
---|
219 | sscanf( pa_qvalue("-h"), "%d", &pix_h ); |
---|
220 | if (pix_h < 400) pix_h = 400; |
---|
221 | } /*endif*/ |
---|
222 | if (pa_qspecified("-r")) |
---|
223 | sscanf( pa_qvalue("-r"), "%d", &mmv_setup.margin_r ); |
---|
224 | if (pa_qspecified("-nogrid")) mmv_grid_on = FALSE; |
---|
225 | if (pa_qspecified("-noninter")) interactive = FALSE; |
---|
226 | if (pa_qspecified("-powscale")) mmv_powscale = TRUE; |
---|
227 | mmv_square_it = FALSE; |
---|
228 | if (pa_qspecified("-square")) mmv_square_it = TRUE; |
---|
229 | mmv_cartesian = FALSE; |
---|
230 | if (pa_qspecified("-ymax")) { |
---|
231 | mmv_cartesian = TRUE; |
---|
232 | sscanf( pa_qvalue("-ymax"), "%f", &mmv_yscale ); |
---|
233 | } /*endif*/ |
---|
234 | mmv_ymin = 0.0; |
---|
235 | if (pa_qspecified("-ymin")) |
---|
236 | sscanf( pa_qvalue("-ymin"), "%f", &mmv_ymin ); |
---|
237 | if (pa_qspecified("-minrelpow")) |
---|
238 | sscanf( pa_qvalue("-minrelpow"), "%f", &mmv_minrelpow ); |
---|
239 | if (pa_qspecified("-minpeakqual")) |
---|
240 | sscanf( pa_qvalue("-minpeakqual"), "%f", &mmv_minpeakqual ); |
---|
241 | *mmv_abstime = '\0'; |
---|
242 | if (pa_qspecified("-xtime")) |
---|
243 | strcpy( mmv_abstime, pa_qvalue("-xtime") ); |
---|
244 | if (pa_qspecified("-sleep")) { |
---|
245 | sscanf( pa_qvalue("-sleep"), "%d", &mmv_sleep ); |
---|
246 | if (mmv_sleep > 1000000) mmv_sleep = 1000000; |
---|
247 | } /*endif*/ |
---|
248 | |
---|
249 | if (mmv_ymin != 0.0) |
---|
250 | mmv_yscale -= mmv_ymin; |
---|
251 | |
---|
252 | MrmInitialize (); |
---|
253 | XtToolkitInitialize(); |
---|
254 | app_context = XtCreateApplicationContext(); |
---|
255 | mmv_display = XtOpenDisplay(app_context, NULL, mmv_pname, "mapmatrix", |
---|
256 | NULL, 0, &argc, argv); |
---|
257 | if (mmv_display == NULL) { |
---|
258 | fprintf(stderr, "%s: Can't open display\n", mmv_pname ); |
---|
259 | exit(1); |
---|
260 | } /*endif*/ |
---|
261 | |
---|
262 | if (mmv_cartesian) |
---|
263 | XtAppAddActions( app_context, mmv_new_actions_cart, 1 ); |
---|
264 | else |
---|
265 | XtAppAddActions( app_context, mmv_new_actions_rad, 1 ); |
---|
266 | |
---|
267 | n = 0; |
---|
268 | /* XtSetArg(arglist[n], XmNallowShellResize, True); n++; */ |
---|
269 | mmv_w[w_toplevel] = XtAppCreateShell( mmv_pname, NULL, |
---|
270 | applicationShellWidgetClass, mmv_display, arglist, n); |
---|
271 | |
---|
272 | if (MrmOpenHierarchy(1,mmv_vec,NULL,&hierarchy) != MrmSUCCESS) { |
---|
273 | fprintf ( stderr, "can't open hierarchy\n" ); |
---|
274 | exit( 1 ); |
---|
275 | } /*endif*/ |
---|
276 | |
---|
277 | if (MrmRegisterNames(mmv_regvec,mmv_regnum) != MrmSUCCESS) { |
---|
278 | fprintf( stderr, "can't register names\n" ); |
---|
279 | exit( 1 ); |
---|
280 | } /*endif*/ |
---|
281 | |
---|
282 | if (MrmFetchWidget(hierarchy,"main_window",mmv_w[w_toplevel], |
---|
283 | mmv_w+w_main,&class) != MrmSUCCESS) { |
---|
284 | fprintf( stderr, "can't fetch widget\n" ); |
---|
285 | exit( 1 ); |
---|
286 | } /*endif*/ |
---|
287 | |
---|
288 | n = 0; |
---|
289 | if (pix_w > 0) {XtSetArg( arglist[n], XmNwidth, pix_w ); n++;} |
---|
290 | if (pix_h > 0) {XtSetArg( arglist[n], XmNheight, pix_h ); n++;} |
---|
291 | if (n > 0) XtSetValues( mmv_w[w_draw], arglist, n ); |
---|
292 | /*if (n > 0) XtSetValues( mmv_w[w_main], arglist, n );*/ |
---|
293 | |
---|
294 | XtManageChild( mmv_w[w_main] ); |
---|
295 | XtRealizeWidget( mmv_w[w_toplevel] ); |
---|
296 | |
---|
297 | mmv_cleargc = XCreateGC( XtDisplay(mmv_w[w_draw]), |
---|
298 | XtWindow(mmv_w[w_draw]), 0, NULL ); |
---|
299 | XSetForeground( XtDisplay(mmv_w[w_draw]), mmv_cleargc, |
---|
300 | WhitePixel(XtDisplay(mmv_w[w_draw]),0) ); |
---|
301 | XSetBackground( XtDisplay(mmv_w[w_draw]), mmv_cleargc, |
---|
302 | WhitePixel(XtDisplay(mmv_w[w_draw]),0) ); |
---|
303 | |
---|
304 | /* read in data file */ |
---|
305 | mmv_matrix.val = NULL; |
---|
306 | sprintf( fname, "%s%05d.out", mmv_inpfile, mmv_fcnt ); |
---|
307 | mm_read_matrix( fname, mmv_square_it, &mmv_matrix ); |
---|
308 | mm_prepare_gc( mmv_w[w_draw], &mmv_setup, mmv_gc ); |
---|
309 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 1 ); |
---|
310 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
311 | |
---|
312 | if (interactive) { |
---|
313 | XtAppMainLoop(app_context); |
---|
314 | } else { |
---|
315 | for (i=0; i<mmv_stepnum; i++) { |
---|
316 | /* read in data file */ |
---|
317 | sprintf( fname, "%s%05d.out", mmv_inpfile, ++mmv_fcnt ); |
---|
318 | mm_read_matrix( fname, mmv_square_it, &mmv_matrix ); |
---|
319 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 1); |
---|
320 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
321 | if (mmv_sleep > 0) usleep( mmv_sleep ); |
---|
322 | } /*endfor*/ |
---|
323 | } /*endif*/ |
---|
324 | |
---|
325 | return 0; |
---|
326 | |
---|
327 | } /* end of main */ |
---|
328 | |
---|
329 | |
---|
330 | |
---|
331 | /*--------------------------------------------------------------------------*/ |
---|
332 | |
---|
333 | |
---|
334 | |
---|
335 | static void cb_call_create_widget( Widget widget, int *tag, |
---|
336 | XmAnyCallbackStruct *data ) |
---|
337 | |
---|
338 | /* Callback routine on createing widgets |
---|
339 | * |
---|
340 | * parameters of routine |
---|
341 | * Widget widget; input; widget number of drawing area |
---|
342 | * int *tag; input; widget number |
---|
343 | * XmAnyCallbackStruct *data; input; not used here |
---|
344 | */ |
---|
345 | { |
---|
346 | /* local variables */ |
---|
347 | int wno = *tag; /* widget number */ |
---|
348 | char acttable[BC_LONGSTRLTH+1]; /* action table */ |
---|
349 | XtTranslations new_table; /* translated table */ |
---|
350 | Arg al[1]; |
---|
351 | |
---|
352 | /* executable code */ |
---|
353 | |
---|
354 | if (wno >= MmcMAX_WIDGET || wno < 0) { |
---|
355 | fprintf( stderr, "--> illegal widget number %d\n", wno ); |
---|
356 | return; |
---|
357 | } /*endif*/ |
---|
358 | |
---|
359 | /* printf( "[%d]", wno ); */ |
---|
360 | mmv_w[wno] = widget; |
---|
361 | |
---|
362 | if (wno == w_draw) { |
---|
363 | if (mmv_cartesian) { |
---|
364 | strcpy( acttable, "<Motion>: cb_action_motion_cart()\n" ); |
---|
365 | strcat( acttable, "<Btn1Down>: cb_action_motion_cart()\n" ); |
---|
366 | strcat( acttable, "<Btn1Up>: cb_action_motion_cart()\n" ); |
---|
367 | strcat( acttable, "<Btn2Down>: cb_action_motion_cart()\n" ); |
---|
368 | strcat( acttable, "<Btn2Up>: cb_action_motion_cart()\n" ); |
---|
369 | strcat( acttable, "<Btn3Down>: cb_action_motion_cart()\n" ); |
---|
370 | strcat( acttable, "<Btn3Up>: cb_action_motion_cart()\n" ); |
---|
371 | strcat( acttable, "<KeyPress>: cb_action_motion_cart()\n" ); |
---|
372 | } else { |
---|
373 | strcpy( acttable, "<Motion>: cb_action_motion_rad()\n" ); |
---|
374 | strcat( acttable, "<Btn1Down>: cb_action_motion_rad()\n" ); |
---|
375 | strcat( acttable, "<Btn1Up>: cb_action_motion_rad()\n" ); |
---|
376 | strcat( acttable, "<Btn2Down>: cb_action_motion_rad()\n" ); |
---|
377 | strcat( acttable, "<Btn2Up>: cb_action_motion_rad()\n" ); |
---|
378 | strcat( acttable, "<Btn3Down>: cb_action_motion_rad()\n" ); |
---|
379 | strcat( acttable, "<Btn3Up>: cb_action_motion_rad()\n" ); |
---|
380 | strcat( acttable, "<KeyPress>: cb_action_motion_rad()\n" ); |
---|
381 | } /*endif*/ |
---|
382 | new_table = XtParseTranslationTable( acttable ); |
---|
383 | XtSetArg( al[0], XmNtranslations, new_table ); |
---|
384 | XtSetValues( mmv_w[w_draw], al, 1 ); |
---|
385 | } /*endif*/ |
---|
386 | |
---|
387 | } /* end of cb_call_create_widget */ |
---|
388 | |
---|
389 | |
---|
390 | |
---|
391 | /*--------------------------------------------------------------------------*/ |
---|
392 | |
---|
393 | |
---|
394 | |
---|
395 | static void cb_call_activate( Widget widget, int *tag, |
---|
396 | XmToggleButtonCallbackStruct *data ) |
---|
397 | |
---|
398 | /* Callback routine on button selection |
---|
399 | * |
---|
400 | * parameters of routine |
---|
401 | * Widget widget; input; widget number of drawing area |
---|
402 | * int *tag; input; tag entry |
---|
403 | * XmPushButtonCallbackStruct *data; input; |
---|
404 | */ |
---|
405 | { |
---|
406 | /* local variables */ |
---|
407 | static int power=1; /* current power */ |
---|
408 | STATUS locstat; /* local status */ |
---|
409 | char fname[cBcFileLth+1]; /* filename to read data */ |
---|
410 | int i; /* counter */ |
---|
411 | |
---|
412 | /* executable code */ |
---|
413 | |
---|
414 | if (!mmv_pixinit) { |
---|
415 | locstat = BC_NOERROR; |
---|
416 | pix_create_window_buffer( XtDisplay(mmv_w[w_draw]), |
---|
417 | XtWindow(mmv_w[w_draw]), TRUE, &locstat ); |
---|
418 | if (Severe(&locstat)) { |
---|
419 | fprintf( stderr, "mapmatrix: error creating window buffer\n" ); |
---|
420 | exit( 1 ); |
---|
421 | } /*endif*/ |
---|
422 | mmv_pixinit = TRUE; |
---|
423 | } /*endif*/ |
---|
424 | |
---|
425 | switch (*tag) { |
---|
426 | case w_entry_quit: |
---|
427 | exit( 0 ); |
---|
428 | case w_entry_readnext: |
---|
429 | /* read in data file */ |
---|
430 | sprintf( fname, "%s%05d.out", mmv_inpfile, ++mmv_fcnt ); |
---|
431 | mm_read_matrix( fname, mmv_square_it, &mmv_matrix ); |
---|
432 | /*mm_prepare_gc( mmv_w[w_draw], &mmv_setup, mmv_gc );*/ |
---|
433 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 1 ); |
---|
434 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
435 | break; |
---|
436 | case w_entry_readprev: |
---|
437 | /* read in data file */ |
---|
438 | sprintf( fname, "%s%05d.out", mmv_inpfile, --mmv_fcnt ); |
---|
439 | mm_read_matrix( fname, mmv_square_it, &mmv_matrix ); |
---|
440 | /*mm_prepare_gc( mmv_w[w_draw], &mmv_setup, mmv_gc );*/ |
---|
441 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 1 ); |
---|
442 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
443 | break; |
---|
444 | case w_entry_readloop: |
---|
445 | for (i=0; i<mmv_stepnum; i++) { |
---|
446 | /* read in data file */ |
---|
447 | sprintf( fname, "%s%05d.out", mmv_inpfile, ++mmv_fcnt ); |
---|
448 | mm_read_matrix( fname, mmv_square_it, &mmv_matrix ); |
---|
449 | /*mm_prepare_gc( mmv_w[w_draw], &mmv_setup, mmv_gc );*/ |
---|
450 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 1); |
---|
451 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
452 | if (mmv_sleep > 0) usleep( mmv_sleep ); |
---|
453 | } /*endfor*/ |
---|
454 | break; |
---|
455 | case w_entry_plot: |
---|
456 | power=1; |
---|
457 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 1 ); |
---|
458 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
459 | break; |
---|
460 | case w_entry_plot_log: |
---|
461 | power = 0; |
---|
462 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 0 ); |
---|
463 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
464 | break; |
---|
465 | case w_entry_plot_p2: |
---|
466 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, |
---|
467 | ++power ); |
---|
468 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
469 | break; |
---|
470 | case w_entry_plot_p4: |
---|
471 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, |
---|
472 | --power ); |
---|
473 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
474 | break; |
---|
475 | case w_entry_radial_grid: |
---|
476 | mmv_grid_on = !mmv_grid_on; |
---|
477 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
478 | else mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, |
---|
479 | power ); |
---|
480 | break; |
---|
481 | case w_entry_colors_green_red: |
---|
482 | mm_change_gc( mmv_w[w_draw], MmcCOLORS_GREEN_RED, &mmv_setup, mmv_gc ); |
---|
483 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, power); |
---|
484 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
485 | break; |
---|
486 | case w_entry_colors_blue_red: |
---|
487 | mm_change_gc( mmv_w[w_draw], MmcCOLORS_BLUE_RED, &mmv_setup, mmv_gc ); |
---|
488 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, power); |
---|
489 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
490 | break; |
---|
491 | case w_entry_colors_black_white: |
---|
492 | mm_change_gc( mmv_w[w_draw], MmcCOLORS_BLACK_WHITE, &mmv_setup, mmv_gc ); |
---|
493 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, power); |
---|
494 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
495 | break; |
---|
496 | case w_entry_colors_blue_yellow: |
---|
497 | mm_change_gc( mmv_w[w_draw], MmcCOLORS_BLUE_YELLOW, &mmv_setup, mmv_gc ); |
---|
498 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, power); |
---|
499 | if (mmv_grid_on) mm_draw_radial_grid( mmv_w[w_draw] ); |
---|
500 | break; |
---|
501 | default: |
---|
502 | fprintf( stderr, "illegal widget activated (%d)\n", *tag ); |
---|
503 | return; |
---|
504 | } /*endswitch*/ |
---|
505 | |
---|
506 | } /* end of cb_call_activate */ |
---|
507 | |
---|
508 | |
---|
509 | |
---|
510 | /*--------------------------------------------------------------------------*/ |
---|
511 | |
---|
512 | |
---|
513 | |
---|
514 | static void cb_call_expose( Widget widget, char *tag, |
---|
515 | XmDrawingAreaCallbackStruct *data ) |
---|
516 | |
---|
517 | /* Callback routine on creation of drawing area |
---|
518 | * |
---|
519 | * parameters of routine |
---|
520 | * Widget widget; input; widget number of drawing area |
---|
521 | * char *tag; input; not used here |
---|
522 | * XmDrawingAreaCallbackStruct *data; input; |
---|
523 | */ |
---|
524 | { |
---|
525 | /* local variables */ |
---|
526 | |
---|
527 | /* executable code */ |
---|
528 | |
---|
529 | if (mmv_pixinit) |
---|
530 | pix_manage_exposure( &(data->event->xexpose) ); |
---|
531 | |
---|
532 | } /* end of cb_call_expose */ |
---|
533 | |
---|
534 | |
---|
535 | |
---|
536 | /*--------------------------------------------------------------------------*/ |
---|
537 | |
---|
538 | |
---|
539 | #define POSTEXT_X 10 |
---|
540 | #define POSTEXT_Y 10 |
---|
541 | |
---|
542 | |
---|
543 | |
---|
544 | void cb_action_motion_rad( Widget w, XEvent *ev, String *params, |
---|
545 | Cardinal *parno ) |
---|
546 | |
---|
547 | /* action routine for pointer motion |
---|
548 | * |
---|
549 | * parameters of routine |
---|
550 | * Widget w; input; widget ID |
---|
551 | * XEvent *ev; input; current event |
---|
552 | * ... (don't know much about it) |
---|
553 | */ |
---|
554 | { |
---|
555 | /* local variables */ |
---|
556 | static BOOLEAN is_init=FALSE; /* already initialized */ |
---|
557 | static int pos_x, pos_y; /* draw position */ |
---|
558 | static GC xgc; /* clear GC */ |
---|
559 | static char oldstr[BC_LINELTH+1];/* old string */ |
---|
560 | static char oldstr2[BC_LINELTH+1];/* old string */ |
---|
561 | static int eff_w, eff_h; /* effective size of window */ |
---|
562 | char postext[BC_LINELTH+1]; /* position text */ |
---|
563 | char postext2[BC_LINELTH+1]; /* position text */ |
---|
564 | Window root; /* root window */ |
---|
565 | int w_x, w_y; /* window position */ |
---|
566 | unsigned w_w, w_h; /* size of window */ |
---|
567 | unsigned border, depth; /* window pars (not used) */ |
---|
568 | float slow_x, slow_y; /* slowness position */ |
---|
569 | float slowness, azimuth; /* slowness and azimuth */ |
---|
570 | float veloc; /* current velocity */ |
---|
571 | |
---|
572 | /* executable code */ |
---|
573 | |
---|
574 | if (w != mmv_w[w_draw]) {printf("--> motion: ill wdw\n"); return;} |
---|
575 | |
---|
576 | if (!is_init) { |
---|
577 | XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h, |
---|
578 | &border, &depth ); |
---|
579 | pos_x = w_w - mmv_setup.margin_r + POSTEXT_X; |
---|
580 | pos_y = w_h - mmv_setup.margin_b - POSTEXT_Y; |
---|
581 | eff_w = w_w - mmv_setup.margin_l - mmv_setup.margin_r; |
---|
582 | eff_h = w_h - mmv_setup.margin_t - mmv_setup.margin_b; |
---|
583 | xgc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
584 | /* XSetForeground( XtDisplay(w), xgc, BlackPixel(XtDisplay(w),0) ); */ |
---|
585 | /* XSetBackground( XtDisplay(w), xgc, WhitePixel(XtDisplay(w),0) ); */ |
---|
586 | XCopyGC( XtDisplay(w), mmv_gc[mmv_setup.colnum], GCFont, xgc ); |
---|
587 | XSetForeground( XtDisplay(w), xgc, WhitePixel(XtDisplay(w),0) ); |
---|
588 | XSetBackground( XtDisplay(w), xgc, BlackPixel(XtDisplay(w),0) ); |
---|
589 | /* XSetFunction( XtDisplay(w), xgc, GXxor ); */ |
---|
590 | is_init = TRUE; |
---|
591 | } /*endif*/ |
---|
592 | |
---|
593 | if (ev->type == MotionNotify) { |
---|
594 | if (ev->xmotion.x < mmv_setup.margin_l |
---|
595 | || ev->xmotion.y < mmv_setup.margin_t |
---|
596 | || ev->xmotion.x > mmv_setup.margin_l+eff_w |
---|
597 | || ev->xmotion.y > mmv_setup.margin_t+eff_h) { |
---|
598 | *postext = *postext2 = '\0'; |
---|
599 | } else { |
---|
600 | slow_x = (float)(ev->xmotion.x - mmv_setup.margin_l); |
---|
601 | slow_y = (float)(ev->xmotion.y - mmv_setup.margin_t); |
---|
602 | slow_x = slow_x / (float)eff_w * mmv_scale * 2.0 - mmv_scale; |
---|
603 | slow_y = -(slow_y / (float)eff_h * mmv_scale * 2.0 - mmv_scale); |
---|
604 | slowness = sqrt( slow_x*slow_x + slow_y*slow_y ); |
---|
605 | if (slow_x == 0.0 && slow_y == 0.0) azimuth = 0.0; |
---|
606 | else azimuth = atan2( slow_x, slow_y ) / (2.0*MY_PI) * 360.0; |
---|
607 | if (azimuth < 0.0) azimuth += 360.0; |
---|
608 | if (slowness > 0.0) veloc = 1.0 / slowness; |
---|
609 | sprintf( postext, " curr. slowness : %6.2f,%6.2f", slow_x, slow_y ); |
---|
610 | sprintf( postext2, " vel, slo, az: %6.2f %6.2f %6.2f", |
---|
611 | veloc, slowness, azimuth ); |
---|
612 | } /*endif*/ |
---|
613 | if (*oldstr != '\0') { |
---|
614 | pix_DrawString( XtDisplay(w), XtWindow(w), xgc, |
---|
615 | pos_x, pos_y, oldstr, strlen(oldstr) ); |
---|
616 | pix_DrawString( XtDisplay(w), XtWindow(w), xgc, |
---|
617 | pos_x, pos_y+20, oldstr2, strlen(oldstr2) ); |
---|
618 | } /*endif*/ |
---|
619 | if (*postext != '\0') { |
---|
620 | pix_DrawString( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], |
---|
621 | pos_x, pos_y, postext, strlen(postext) ); |
---|
622 | pix_DrawString( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], |
---|
623 | pos_x, pos_y+20, postext2, strlen(postext2) ); |
---|
624 | } /*endif*/ |
---|
625 | strcpy( oldstr, postext ); |
---|
626 | strcpy( oldstr2, postext2 ); |
---|
627 | XFlush( XtDisplay(w) ); |
---|
628 | } /*endif*/ |
---|
629 | |
---|
630 | if (ev->type == KeyPress) { |
---|
631 | /* this is a workaround for accelerators not working on recent Suse * |
---|
632 | * Linux implementations */ |
---|
633 | int tag; |
---|
634 | Modifiers mret; |
---|
635 | KeySym keysym; |
---|
636 | XtTranslateKeycode( ev->xkey.display, ev->xkey.keycode, ev->xkey.state, |
---|
637 | &mret, &keysym ); |
---|
638 | switch ((char)keysym) { |
---|
639 | case 'q': tag = w_entry_quit; break; |
---|
640 | case 'b': tag = w_entry_readprev; break; |
---|
641 | case 'n': tag = w_entry_readnext; break; |
---|
642 | case 'f': tag = w_entry_readloop; break; |
---|
643 | case 'p': tag = w_entry_plot; break; |
---|
644 | case 'l': tag = w_entry_plot_log; break; |
---|
645 | case 'u': tag = w_entry_plot_p2; break; |
---|
646 | case 'd': tag = w_entry_plot_p4; break; |
---|
647 | case 'r': tag = w_entry_radial_grid; break; |
---|
648 | case '1': tag = w_entry_colors_green_red; break; |
---|
649 | case '2': tag = w_entry_colors_blue_red; break; |
---|
650 | case '3': tag = w_entry_colors_black_white; break; |
---|
651 | case '4': tag = w_entry_colors_blue_yellow; break; |
---|
652 | default: tag = 0; |
---|
653 | printf( "--> pressed key %d, keysym %x\n", ev->xkey.keycode, keysym ); |
---|
654 | } /*endswitch*/ |
---|
655 | if (tag > 0) cb_call_activate( w, &tag, NULL ); |
---|
656 | } /*endif*/ |
---|
657 | |
---|
658 | } /* end of cb_action_motion_rad */ |
---|
659 | |
---|
660 | |
---|
661 | |
---|
662 | /*--------------------------------------------------------------------------*/ |
---|
663 | |
---|
664 | |
---|
665 | |
---|
666 | |
---|
667 | void cb_action_motion_cart( Widget w, XEvent *ev, String *params, |
---|
668 | Cardinal *parno ) |
---|
669 | |
---|
670 | /* action routine for pointer motion |
---|
671 | * |
---|
672 | * parameters of routine |
---|
673 | * Widget w; input; widget ID |
---|
674 | * XEvent *ev; input; current event |
---|
675 | * ... (don't know much about it) |
---|
676 | */ |
---|
677 | { |
---|
678 | /* local variables */ |
---|
679 | static BOOLEAN is_init=FALSE; /* already initialized */ |
---|
680 | static int pos_x, pos_y; /* draw position */ |
---|
681 | static GC xgc; /* clear GC */ |
---|
682 | static char oldstr[BC_LINELTH+1];/* old string */ |
---|
683 | static char oldstr2[BC_LINELTH+1];/* old string */ |
---|
684 | static int eff_w, eff_h; /* effective size of window */ |
---|
685 | char postext[BC_LINELTH+1]; /* position text */ |
---|
686 | char postext2[BC_LINELTH+1]; /* position text */ |
---|
687 | Window root; /* root window */ |
---|
688 | int w_x, w_y; /* window position */ |
---|
689 | unsigned w_w, w_h; /* size of window */ |
---|
690 | unsigned border, depth; /* window pars (not used) */ |
---|
691 | float slow_x, slow_y; /* slowness position */ |
---|
692 | char ctime[cBcTimeLth+1]; /* current absolute time */ |
---|
693 | STATUS locstat; /* local status */ |
---|
694 | |
---|
695 | /* executable code */ |
---|
696 | |
---|
697 | if (w != mmv_w[w_draw]) {printf("--> motion: ill wdw\n"); return;} |
---|
698 | |
---|
699 | if (!is_init) { |
---|
700 | XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h, |
---|
701 | &border, &depth ); |
---|
702 | pos_x = w_w - mmv_setup.margin_r + POSTEXT_X; |
---|
703 | pos_y = w_h - mmv_setup.margin_b - POSTEXT_Y; |
---|
704 | eff_w = w_w - mmv_setup.margin_l - mmv_setup.margin_r; |
---|
705 | eff_h = w_h - mmv_setup.margin_t - mmv_setup.margin_b; |
---|
706 | xgc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
707 | /* XSetForeground( XtDisplay(w), xgc, BlackPixel(XtDisplay(w),0) ); */ |
---|
708 | /* XSetBackground( XtDisplay(w), xgc, WhitePixel(XtDisplay(w),0) ); */ |
---|
709 | XCopyGC( XtDisplay(w), mmv_gc[mmv_setup.colnum], GCFont, xgc ); |
---|
710 | XSetForeground( XtDisplay(w), xgc, WhitePixel(XtDisplay(w),0) ); |
---|
711 | XSetBackground( XtDisplay(w), xgc, BlackPixel(XtDisplay(w),0) ); |
---|
712 | /* XSetFunction( XtDisplay(w), xgc, GXxor ); */ |
---|
713 | is_init = TRUE; |
---|
714 | } /*endif*/ |
---|
715 | |
---|
716 | if (ev->type == MotionNotify) { |
---|
717 | if (ev->xmotion.x < mmv_setup.margin_l |
---|
718 | || ev->xmotion.y < mmv_setup.margin_t |
---|
719 | || ev->xmotion.x > mmv_setup.margin_l+eff_w |
---|
720 | || ev->xmotion.y > mmv_setup.margin_t+eff_h) { |
---|
721 | *postext = *postext2 = '\0'; |
---|
722 | } else { |
---|
723 | slow_x = (float)(ev->xmotion.x - mmv_setup.margin_l); |
---|
724 | slow_y = (float)(ev->xmotion.y - mmv_setup.margin_t); |
---|
725 | slow_x = slow_x / (float)eff_w * mmv_scale; |
---|
726 | slow_y = mmv_ymin + mmv_yscale - (slow_y / (float)eff_h * mmv_yscale); |
---|
727 | locstat = cBcNoError; |
---|
728 | if (*mmv_abstime == '\0') { |
---|
729 | sprintf( postext, " curr. time: %6.2f", slow_x ); |
---|
730 | } else { |
---|
731 | tc_tadd( mmv_abstime, slow_x, ctime, &locstat ); |
---|
732 | /*sprintf( postext, " curr. time: %s", ctime );*/ |
---|
733 | strcpy( postext, ctime ); |
---|
734 | } /*endif*/ |
---|
735 | sprintf( postext2, " slowness : %6.2f", slow_y ); |
---|
736 | } /*endif*/ |
---|
737 | if (*oldstr != '\0') { |
---|
738 | pix_DrawString( XtDisplay(w), XtWindow(w), xgc, |
---|
739 | pos_x, pos_y, oldstr, strlen(oldstr) ); |
---|
740 | pix_DrawString( XtDisplay(w), XtWindow(w), xgc, |
---|
741 | pos_x, pos_y+20, oldstr2, strlen(oldstr2) ); |
---|
742 | } /*endif*/ |
---|
743 | if (*postext != '\0') { |
---|
744 | pix_DrawString( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], |
---|
745 | pos_x, pos_y, postext, strlen(postext) ); |
---|
746 | pix_DrawString( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], |
---|
747 | pos_x, pos_y+20, postext2, strlen(postext2) ); |
---|
748 | } /*endif*/ |
---|
749 | strcpy( oldstr, postext ); |
---|
750 | strcpy( oldstr2, postext2 ); |
---|
751 | XFlush( XtDisplay(w) ); |
---|
752 | } /*endif*/ |
---|
753 | |
---|
754 | if (ev->type == KeyPress) { |
---|
755 | /* this is a workaround for accelerators not working on recent Suse * |
---|
756 | * Linux implementations */ |
---|
757 | int tag; |
---|
758 | Modifiers mret; |
---|
759 | KeySym keysym; |
---|
760 | XtTranslateKeycode( ev->xkey.display, ev->xkey.keycode, ev->xkey.state, |
---|
761 | &mret, &keysym ); |
---|
762 | switch ((char)keysym) { |
---|
763 | case 'n': tag = w_entry_readnext; break; |
---|
764 | default: tag = 0; |
---|
765 | printf( "--> pressed key %d, keysym %ld\n", ev->xkey.keycode, keysym ); |
---|
766 | } /*endswitch*/ |
---|
767 | if (tag > 0) cb_call_activate( w, &tag, NULL ); |
---|
768 | } /*endif*/ |
---|
769 | |
---|
770 | } /* end of cb_action_motion_cart */ |
---|
771 | |
---|
772 | |
---|
773 | |
---|
774 | /*--------------------------------------------------------------------------*/ |
---|
775 | |
---|
776 | |
---|
777 | |
---|
778 | #define TMPNAME "animatrix.000" |
---|
779 | #define TMPNAMEGZ "animatrix.000.gz" |
---|
780 | |
---|
781 | |
---|
782 | |
---|
783 | static void mm_read_matrix( char filename[], BOOLEAN sqr, MmtMATRIX *mat ) |
---|
784 | |
---|
785 | /* Allocates memory for matrix and reads it from file |
---|
786 | * |
---|
787 | * parameters of routine |
---|
788 | * char filename[]; input; name of input file |
---|
789 | * BOOLEAN sqr; input; square input |
---|
790 | * MmtMATRIX *mat; output; matrix |
---|
791 | */ |
---|
792 | { |
---|
793 | /* local variables */ |
---|
794 | FILE *fp; /* pointer to input file */ |
---|
795 | char line[BC_LINELTH+1]; /* current line in input file */ |
---|
796 | int i, j; /* counters */ |
---|
797 | char fname[cBcFileLth+1]; /* name of input file */ |
---|
798 | char uname[cBcFileLth+1]; /* name of used file */ |
---|
799 | BOOLEAN compressed; /* file is compressed */ |
---|
800 | char syscmd[cBcLongStrLth+1]; /* shell command */ |
---|
801 | |
---|
802 | /* executable code */ |
---|
803 | |
---|
804 | strcpy( fname, filename ); |
---|
805 | |
---|
806 | fp = fopen( fname, "r" ); |
---|
807 | if (fp == NULL) { |
---|
808 | strcat( fname, ".gz" ); |
---|
809 | fp = fopen( fname, "r" ); |
---|
810 | if (fp == NULL) { |
---|
811 | fprintf( stderr, "%s: couldn't open input file %s\n", |
---|
812 | mmv_pname, fname ); |
---|
813 | return; |
---|
814 | } /*endif*/ |
---|
815 | fclose( fp ); |
---|
816 | compressed = TRUE; |
---|
817 | sprintf( syscmd, "cp %s %s", fname, TMPNAMEGZ ); |
---|
818 | system( syscmd ); |
---|
819 | sprintf( syscmd, "gzip -d %s", TMPNAME ); |
---|
820 | system( syscmd ); |
---|
821 | /*# ifdef SH_SETUP_LINUX*/ |
---|
822 | strcpy( uname, TMPNAME ); |
---|
823 | /* |
---|
824 | # else |
---|
825 | strcpy( uname, filename ); |
---|
826 | # endif |
---|
827 | */ |
---|
828 | fp = fopen( uname, "r" ); |
---|
829 | if (fp == NULL) { |
---|
830 | fprintf( stderr, "%s: cannot open decompressed file of %s (%s)\n", |
---|
831 | mmv_pname, fname, uname ); |
---|
832 | return; |
---|
833 | } /*endif*/ |
---|
834 | } else { |
---|
835 | compressed = FALSE; |
---|
836 | } /*endif*/ |
---|
837 | |
---|
838 | /* read off comments and get relpow and peakqual if specified */ |
---|
839 | mmv_cmtcnt = 0; |
---|
840 | mmv_relpow = 0.5; |
---|
841 | mmv_peakqual = 0.0; |
---|
842 | while (fgets(line,BC_LINELTH,fp) != NULL) { |
---|
843 | if (*line != '!') break; |
---|
844 | if (strncmp(line,"!* rel. power :",20) == 0) { |
---|
845 | sscanf( line+20, "%f", &mmv_relpow ); |
---|
846 | if (mmv_relpow < 0.0) { |
---|
847 | mmv_colscale = 0.0; |
---|
848 | } else if (mmv_relpow > 0.5) { |
---|
849 | mmv_colscale = 1.0; |
---|
850 | } else { |
---|
851 | mmv_colscale = 2.0 * mmv_relpow; |
---|
852 | } /*endif*/ |
---|
853 | } else if (strncmp(line,"!* peakqual :",20) == 0) { |
---|
854 | sscanf( line+20, "%f", &mmv_peakqual ); |
---|
855 | } /*endif*/ |
---|
856 | if (line[1] == '*' && mmv_cmtcnt < MmcMAXCMT) { |
---|
857 | strcpy( mmv_cmt[mmv_cmtcnt], line+2 ); |
---|
858 | i = strlen( mmv_cmt[mmv_cmtcnt] ) - 1; |
---|
859 | if (mmv_cmt[mmv_cmtcnt][i] == '\n') |
---|
860 | mmv_cmt[mmv_cmtcnt][i] = '\0'; |
---|
861 | if (mmv_cmtcnt == 0 && i < (cBcLineLth-10)) |
---|
862 | sprintf( mmv_cmt[0]+i, " (#%d)", mmv_fcnt ); |
---|
863 | mmv_cmtcnt++; |
---|
864 | } /*endif*/ |
---|
865 | } /*endwhile*/ |
---|
866 | |
---|
867 | if (sscanf(line,"%d %d",&(mat->width),&(mat->height)) != 2) { |
---|
868 | fprintf( stderr, "%s: read error on input file %s\n", |
---|
869 | mmv_pname, fname ); |
---|
870 | exit( 1 ); |
---|
871 | } /*endif*/ |
---|
872 | |
---|
873 | /* allocate pointers */ |
---|
874 | if (mat->val != NULL) free( mat->val ); |
---|
875 | mat->val = (float **)malloc( sizeof(float *) * mat->height ); |
---|
876 | if (mat->val == NULL) { |
---|
877 | fprintf( stderr, "%s: allocation error (pointers)\n", mmv_pname ); |
---|
878 | exit( 1 ); |
---|
879 | } /*endif*/ |
---|
880 | /* allocate rows */ |
---|
881 | for (i=0; i<(mat->height); i++) { |
---|
882 | mat->val[i] = (float *)malloc( sizeof(float) * mat->width ); |
---|
883 | if (mat->val[i] == NULL) { |
---|
884 | fprintf( stderr, "%s: allocation error (row %d)\n", mmv_pname, i ); |
---|
885 | exit( 1 ); |
---|
886 | } /*endif*/ |
---|
887 | } /*endfor*/ |
---|
888 | |
---|
889 | /* read in data */ |
---|
890 | for (i=0; i<(mat->height); i++) |
---|
891 | for (j=0; j<(mat->width); j++) { |
---|
892 | fscanf( fp, "%f\n", (mat->val[i])+j ); |
---|
893 | if (sqr) mat->val[i][j] = (mat->val[i][j])*(mat->val[i][j]); |
---|
894 | } /*endfor*/ |
---|
895 | |
---|
896 | fclose( fp ); |
---|
897 | if (compressed) { |
---|
898 | sprintf( syscmd, "\\rm %s", uname ); |
---|
899 | system( syscmd ); |
---|
900 | } /*endif*/ |
---|
901 | |
---|
902 | /* find min & max, test output */ |
---|
903 | mat->minval = mat->maxval = mat->val[0][0]; |
---|
904 | for (i=0; i<(mat->height); i++) { |
---|
905 | for (j=0; j<(mat->width); j++) { |
---|
906 | /* printf( "%f ", mat->val[i][j] ); */ |
---|
907 | if (mat->val[i][j] > mat->maxval) mat->maxval = mat->val[i][j]; |
---|
908 | if (mat->val[i][j] < mat->minval) mat->minval = mat->val[i][j]; |
---|
909 | } /*endfor*/ |
---|
910 | /* printf( "\n" ); */ |
---|
911 | } /*endfor*/ |
---|
912 | |
---|
913 | /*printf( "--> min, max: %f %f\n", mat->minval, mat->maxval );*/ |
---|
914 | |
---|
915 | } /* end of mm_read_matrix */ |
---|
916 | |
---|
917 | |
---|
918 | |
---|
919 | /*--------------------------------------------------------------------------*/ |
---|
920 | |
---|
921 | |
---|
922 | |
---|
923 | |
---|
924 | static void mm_prepare_gc( Widget w, MmtDSP_SETUP *setup, GC gc[] ) |
---|
925 | |
---|
926 | /* creates GC's for display |
---|
927 | * |
---|
928 | * parameters of routine |
---|
929 | * Widget w; input; widget of drawing area |
---|
930 | * MmtDSP_SETUP *setup; input; display setup |
---|
931 | * GC gc[]; output; array of GC's |
---|
932 | */ |
---|
933 | { |
---|
934 | /* local variables */ |
---|
935 | static char *visual_class[] = { |
---|
936 | "StaticGray", "GrayScale", "StaticColor", "PseudoColor", |
---|
937 | "TrueColor", "DirectColor" |
---|
938 | }; |
---|
939 | int default_depth; /* default depth */ |
---|
940 | Visual *default_visual; /* default visual */ |
---|
941 | XColor color; /* color */ |
---|
942 | Colormap default_cmap; /* default colormap */ |
---|
943 | XVisualInfo visual_info; /* visual info */ |
---|
944 | unsigned i; /* counter */ |
---|
945 | float frac; /* color fraction */ |
---|
946 | float frac_x, c; /* scratch */ |
---|
947 | int screen_num; /* screen number */ |
---|
948 | Font out_font; /* font for text */ |
---|
949 | |
---|
950 | /* executable code */ |
---|
951 | |
---|
952 | screen_num = 0; |
---|
953 | |
---|
954 | default_depth = DefaultDepth( XtDisplay(w), screen_num ); |
---|
955 | default_visual = DefaultVisual( XtDisplay(w), screen_num ); |
---|
956 | default_cmap = DefaultColormap( XtDisplay(w), screen_num ); |
---|
957 | if (default_depth == 1) { |
---|
958 | fprintf( stderr, "%s: StaticGray visual not supported\n", |
---|
959 | mmv_pname ); |
---|
960 | exit( 1 ); |
---|
961 | } /*endif*/ |
---|
962 | |
---|
963 | i = 5; |
---|
964 | while (!XMatchVisualInfo(XtDisplay(w),screen_num,default_depth, |
---|
965 | i--,&visual_info)) |
---|
966 | ; |
---|
967 | |
---|
968 | #ifdef XXX |
---|
969 | printf( "%s: found a %s class visual at default depth %d\n", |
---|
970 | mmv_pname, visual_class[++i] ); |
---|
971 | #endif |
---|
972 | if (i < StaticColor) { |
---|
973 | fprintf( stderr, "%s: visual class %s is not supported\n", |
---|
974 | mmv_pname, visual_class[i] ); |
---|
975 | exit( 1 ); |
---|
976 | } /*endif*/ |
---|
977 | |
---|
978 | #ifdef XXX |
---|
979 | if (visual_info.visual != default_visual) |
---|
980 | printf( "%s: %s class visual at default depth is not default visual\n", |
---|
981 | mmv_pname, visual_class[i] ); |
---|
982 | #endif |
---|
983 | |
---|
984 | if (setup->colnum > MmcMAX_COLOR-1) { |
---|
985 | fprintf( stderr, "%s: too many colors. Only %d permitted\n", |
---|
986 | mmv_pname, MmcMAX_COLOR-1 ); |
---|
987 | exit( 1 ); |
---|
988 | } /*endif*/ |
---|
989 | |
---|
990 | for (i=0; i<(setup->colnum); i++) { |
---|
991 | frac = (float)i / (float)((setup->colnum)-1); |
---|
992 | /* red increases from 0 to c and then stays 1 */ |
---|
993 | c = 0.5; /*0.4;*/ |
---|
994 | frac_x = (frac < c) ? frac/c : 1.0; |
---|
995 | color.red = Nint( frac_x * 65535.0 ); |
---|
996 | /* green increases from c to 1 and is zero before c */ |
---|
997 | c = 0.5; |
---|
998 | frac_x = (frac > c) ? (frac-c)/(1.0-c) : 0.0; |
---|
999 | color.green = Nint( frac_x * 65535.0 ); |
---|
1000 | /* blue decreases from 1 to 0 between 0 and c and then stays 0 */ |
---|
1001 | c = 0.5; /*0.8;*/ |
---|
1002 | frac_x = (frac < c) ? (1.0-frac/c) : 0.0; |
---|
1003 | color.blue = Nint( frac_x * 65535.0 ); |
---|
1004 | color.flags = DoRed | DoGreen | DoBlue; |
---|
1005 | if (!XAllocColor(XtDisplay(w),default_cmap,&color)) { |
---|
1006 | fprintf( stderr, "%s: error allocating color\n", mmv_pname ); |
---|
1007 | exit( 1 ); |
---|
1008 | } /*endif*/ |
---|
1009 | gc[i] = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
1010 | XSetForeground( XtDisplay(w), gc[i], color.pixel ); |
---|
1011 | XSetBackground( XtDisplay(w), gc[i], |
---|
1012 | WhitePixel(XtDisplay(w),screen_num) ); |
---|
1013 | } /*endfor*/ |
---|
1014 | |
---|
1015 | out_font = XLoadFont( XtDisplay(w), |
---|
1016 | "-b&h-lucidatypewriter-bold-r-normal-sans-*-100-75-*-*-*-*-1" ); |
---|
1017 | |
---|
1018 | i = setup->colnum; |
---|
1019 | gc[i] = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
1020 | XSetForeground( XtDisplay(w), gc[i], BlackPixel(XtDisplay(w),screen_num) ); |
---|
1021 | XSetBackground( XtDisplay(w), gc[i], WhitePixel(XtDisplay(w),screen_num) ); |
---|
1022 | XSetFont( XtDisplay(w), gc[i], out_font ); |
---|
1023 | |
---|
1024 | } /* end of mm_prepare_gc */ |
---|
1025 | |
---|
1026 | |
---|
1027 | |
---|
1028 | /*--------------------------------------------------------------------------*/ |
---|
1029 | |
---|
1030 | |
---|
1031 | |
---|
1032 | static void mm_display_matrix( Widget w, GC gc[], MmtDSP_SETUP *setup, |
---|
1033 | MmtMATRIX *mat, int power ) |
---|
1034 | |
---|
1035 | /* displays matrix on screen |
---|
1036 | * |
---|
1037 | * parameters of routine |
---|
1038 | * Widget w; input; widget of drawing area |
---|
1039 | * GC gc[]; input; GC's |
---|
1040 | * MmtDSP_SETUP *setup; input; display setup |
---|
1041 | * MmtMATRIX *mat; input; matrix |
---|
1042 | * int power; input; power on amplitudes |
---|
1043 | */ |
---|
1044 | { |
---|
1045 | /* local variables */ |
---|
1046 | Window root; /* root window */ |
---|
1047 | int w_x, w_y; /* position of window */ |
---|
1048 | unsigned w_w, w_h; /* size of window */ |
---|
1049 | unsigned border; /* border width */ |
---|
1050 | unsigned depth; /* depth of window */ |
---|
1051 | float rect_width; /* width of rectangle */ |
---|
1052 | float rect_height; /* height of rectangle */ |
---|
1053 | unsigned i, j; /* counters */ |
---|
1054 | float rect_x, rect_y; /* position of rectangle */ |
---|
1055 | float frac; /* scratch */ |
---|
1056 | unsigned colstep; /* color number */ |
---|
1057 | int cmt_x, cmt_y;/* comment position */ |
---|
1058 | |
---|
1059 | /* executable code */ |
---|
1060 | |
---|
1061 | XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h, |
---|
1062 | &border, &depth ); |
---|
1063 | |
---|
1064 | /* get width and height of rectangle */ |
---|
1065 | rect_width = (float)(w_w-(setup->margin_l)-(setup->margin_r)) |
---|
1066 | / (float)(mat->width); |
---|
1067 | #ifdef XXX |
---|
1068 | if (rect_width <= 1.0) { |
---|
1069 | fprintf( stderr, "%s: illegal window size\n", mmv_pname ); |
---|
1070 | exit( 1 ); |
---|
1071 | } /*endif*/ |
---|
1072 | #endif |
---|
1073 | rect_height = (float)(w_h-(setup->margin_t)-(setup->margin_b)) |
---|
1074 | / (float)(mat->height); |
---|
1075 | #ifdef XXX |
---|
1076 | if (rect_height <= 1.0) { |
---|
1077 | fprintf( stderr, "%s: illegal window size\n", mmv_pname ); |
---|
1078 | exit( 1 ); |
---|
1079 | } /*endif*/ |
---|
1080 | #endif |
---|
1081 | |
---|
1082 | cmt_x = w_w - setup->margin_r + 10; |
---|
1083 | cmt_y = MmcCHARHEIGHT; |
---|
1084 | if (mmv_relpow > mmv_minrelpow && mmv_peakqual > mmv_minpeakqual) { |
---|
1085 | pix_FillRectangle( XtDisplay(w), XtWindow(w), gc[mmv_setup.colnum-1], |
---|
1086 | cmt_x, cmt_y-MmcCHARHEIGHT, 300, 550 ); |
---|
1087 | } else { |
---|
1088 | pix_FillRectangle( XtDisplay(w), XtWindow(w), mmv_cleargc, |
---|
1089 | cmt_x, cmt_y-MmcCHARHEIGHT, 300, 550 ); |
---|
1090 | } /*endif*/ |
---|
1091 | for (i=0; i<mmv_cmtcnt; i++) { |
---|
1092 | pix_DrawString( XtDisplay(w), XtWindow(w), gc[setup->colnum], cmt_x, |
---|
1093 | cmt_y, mmv_cmt[i], strlen(mmv_cmt[i]) ); |
---|
1094 | cmt_y += MmcCHARHEIGHT; |
---|
1095 | } /*endfor*/ |
---|
1096 | |
---|
1097 | for (i=0; i<(mat->height); i++) { |
---|
1098 | for (j=0; j<(mat->width); j++) { |
---|
1099 | # ifdef XXX /* this is original */ |
---|
1100 | /* rect_x = (float)(mat->width-1-i) * rect_width; this is mirrored */ |
---|
1101 | rect_x = (float)i * rect_width; |
---|
1102 | rect_y = (float)j * rect_height; |
---|
1103 | # endif |
---|
1104 | rect_x = (float)j * rect_width; |
---|
1105 | rect_y = (float)(mat->height-1-i) * rect_height; |
---|
1106 | frac = (mat->val[i][j]-mat->minval) / (mat->maxval-mat->minval); |
---|
1107 | if (mmv_powscale) frac *= mmv_colscale; |
---|
1108 | if (power == 0) { |
---|
1109 | frac = log( 1.0 + (MY_E-1.0)*frac ); |
---|
1110 | } else if (power > 1) { |
---|
1111 | frac = pow( frac, (float)power ); |
---|
1112 | } else if (power < 0) { |
---|
1113 | frac = pow( frac, 1.0/(float)(-power+1) ); |
---|
1114 | } /*endif*/ |
---|
1115 | colstep = Nint( frac * (float)(setup->colnum-1) ); |
---|
1116 | pix_FillRectangle( XtDisplay(w), XtWindow(w), gc[colstep], |
---|
1117 | Nint(rect_x)+setup->margin_l, Nint(rect_y)+setup->margin_t, |
---|
1118 | Nint(rect_width)+1, Nint(rect_height)+1 ); |
---|
1119 | } /*endfor*/ |
---|
1120 | } /*endfor*/ |
---|
1121 | |
---|
1122 | XFlush( XtDisplay(w) ); |
---|
1123 | |
---|
1124 | } /* end of mm_display_matrix */ |
---|
1125 | |
---|
1126 | |
---|
1127 | |
---|
1128 | /*--------------------------------------------------------------------------*/ |
---|
1129 | |
---|
1130 | |
---|
1131 | |
---|
1132 | static void mm_draw_radial_grid( Widget w ) |
---|
1133 | |
---|
1134 | /* Draws radial grid into the map. |
---|
1135 | * |
---|
1136 | * parameters of routine |
---|
1137 | * Widget w; input; widget ID |
---|
1138 | */ |
---|
1139 | { |
---|
1140 | /* local variables */ |
---|
1141 | Window root; /* root window */ |
---|
1142 | int w_x, w_y; /* position of window */ |
---|
1143 | unsigned w_w, w_h; /* size of window */ |
---|
1144 | unsigned border; /* border width */ |
---|
1145 | unsigned depth; /* depth of window */ |
---|
1146 | unsigned eff_w, eff_h;/* effective width and height */ |
---|
1147 | int center_x; /* center of coordinate system in pixel */ |
---|
1148 | int center_y; /* center of coordinate system in pixel */ |
---|
1149 | int nice_num_i; /* integer nice number */ |
---|
1150 | float nice_num; /* nice number of grid */ |
---|
1151 | float radius; /* radius */ |
---|
1152 | float azimuth; /* azimuth */ |
---|
1153 | int pix_radius_x;/* length of x-radius in pixel */ |
---|
1154 | int pix_radius_y;/* length of y-radius in pixel */ |
---|
1155 | float fx, fy; /* coordinate position */ |
---|
1156 | int cx, cy; /* pixel position */ |
---|
1157 | char str[BC_LINELTH+1]; /* scratch string */ |
---|
1158 | |
---|
1159 | /* executable code */ |
---|
1160 | |
---|
1161 | XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h, |
---|
1162 | &border, &depth ); |
---|
1163 | |
---|
1164 | /* eff_w and eff_h (both are usually the same) tell how many pixels |
---|
1165 | * are used for two times mmv_scale. |
---|
1166 | */ |
---|
1167 | eff_w = w_w - mmv_setup.margin_l - mmv_setup.margin_r; |
---|
1168 | eff_h = w_h - mmv_setup.margin_t - mmv_setup.margin_b; |
---|
1169 | center_x = eff_w/2 + mmv_setup.margin_l; |
---|
1170 | center_y = eff_h/2 + mmv_setup.margin_t; |
---|
1171 | |
---|
1172 | nice_num_i = 1; |
---|
1173 | while (mmv_scale/(float)nice_num_i > 8.0) { |
---|
1174 | sprintf( str, " %d", nice_num_i ); |
---|
1175 | switch (str[1]) { |
---|
1176 | case '1': str[1] = '2'; break; |
---|
1177 | case '2': str[1] = '5'; break; |
---|
1178 | case '5': str[0] = '1'; str[1] = '0'; break; |
---|
1179 | default: strcpy( str, "1000000" ); break; |
---|
1180 | } /*endswitch*/ |
---|
1181 | sscanf( str, "%d", &nice_num_i ); |
---|
1182 | } /*endwhile*/ |
---|
1183 | nice_num = (float)nice_num_i; |
---|
1184 | |
---|
1185 | for (radius=nice_num; radius<=mmv_scale; radius += nice_num) { |
---|
1186 | pix_radius_x = Nint( radius / mmv_scale * (float)(eff_w/2) ); |
---|
1187 | pix_radius_y = Nint( radius / mmv_scale * (float)(eff_h/2) ); |
---|
1188 | pix_DrawArc( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], |
---|
1189 | center_x-pix_radius_x, center_y-pix_radius_y, |
---|
1190 | 2*pix_radius_x, 2*pix_radius_y, 0, 360*64 ); |
---|
1191 | } /*endfor*/ |
---|
1192 | |
---|
1193 | radius -= nice_num; |
---|
1194 | for (azimuth=0.0; azimuth<360.0; azimuth += 30.0) { |
---|
1195 | fx = radius * cos( azimuth/180.0*MY_PI ); |
---|
1196 | fy = radius * sin( azimuth/180.0*MY_PI ); |
---|
1197 | cx = center_x + Nint( fx / mmv_scale * (float)(eff_w/2) ); |
---|
1198 | cy = center_y + Nint( fy / mmv_scale * (float)(eff_h/2) ); |
---|
1199 | pix_DrawLine( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], |
---|
1200 | center_x, center_y, cx, cy ); |
---|
1201 | } /*endfor*/ |
---|
1202 | |
---|
1203 | sprintf( str, " radial grid step %g", nice_num ); |
---|
1204 | cx = w_w - mmv_setup.margin_r + 10; |
---|
1205 | cy = (mmv_cmtcnt+1) * MmcCHARHEIGHT; |
---|
1206 | pix_DrawString( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], cx, cy, |
---|
1207 | str, strlen(str) ); |
---|
1208 | |
---|
1209 | XFlush( XtDisplay(w) ); |
---|
1210 | |
---|
1211 | } /* end of mm_draw_radial_grid */ |
---|
1212 | |
---|
1213 | |
---|
1214 | |
---|
1215 | /*--------------------------------------------------------------------------*/ |
---|
1216 | |
---|
1217 | |
---|
1218 | |
---|
1219 | static void mm_change_gc( Widget w, int mode, MmtDSP_SETUP *setup, GC gc[] ) |
---|
1220 | |
---|
1221 | /* changes gc's to other colors |
---|
1222 | * |
---|
1223 | * parameters of routine |
---|
1224 | * Widget w; input; widget ID |
---|
1225 | * int mode; input; which colors |
---|
1226 | * MmtDSP_SETUP *setup; input; setup |
---|
1227 | * GC gc[]; modify; GC's to change |
---|
1228 | */ |
---|
1229 | { |
---|
1230 | /* local variables */ |
---|
1231 | int i; /* counter */ |
---|
1232 | float frac; /* color fraction */ |
---|
1233 | float frac_x; /* scratch */ |
---|
1234 | float c, c1; /* scratch */ |
---|
1235 | XColor color; /* color info */ |
---|
1236 | Colormap default_cmap;/* default colormap */ |
---|
1237 | int screen_num; /* screen number */ |
---|
1238 | |
---|
1239 | /* executable code */ |
---|
1240 | |
---|
1241 | screen_num = 0; |
---|
1242 | |
---|
1243 | default_cmap = DefaultColormap( XtDisplay(w), screen_num ); |
---|
1244 | |
---|
1245 | for (i=0; i<(setup->colnum); i++) { |
---|
1246 | frac = (float)i / (float)((setup->colnum)-1); |
---|
1247 | switch (mode) { |
---|
1248 | case MmcCOLORS_GREEN_RED: |
---|
1249 | color.red = Nint(frac*65535.0); |
---|
1250 | color.green = Nint((1-frac)*65535.0); |
---|
1251 | color.blue = 0; |
---|
1252 | break; |
---|
1253 | case MmcCOLORS_BLUE_RED: |
---|
1254 | color.red = Nint(frac*65535.0); |
---|
1255 | color.green = 0; |
---|
1256 | color.blue = Nint((1-frac)*65535.0); |
---|
1257 | break; |
---|
1258 | case MmcCOLORS_BLUE_YELLOW: |
---|
1259 | #ifdef XXX |
---|
1260 | frac_x = (frac < 0.5) ? 2.0*frac : 1.0; |
---|
1261 | color.red = Nint( frac_x * 65535.0 ); |
---|
1262 | frac_x = (frac > 0.5) ? 2.0*(frac-0.5) : 0.0; |
---|
1263 | color.green = Nint( frac_x * 65535.0 ); |
---|
1264 | frac_x = (frac < 0.5) ? (1.0-2.0*frac) : 0.0; |
---|
1265 | color.blue = Nint( frac_x * 65535.0 ); |
---|
1266 | #endif |
---|
1267 | /* red increases from 0 to c and then stays 1 */ |
---|
1268 | c = 0.5; /*0.4;*/ |
---|
1269 | frac_x = (frac < c) ? frac/c : 1.0; |
---|
1270 | color.red = Nint( frac_x * 65535.0 ); |
---|
1271 | /* green increases from c to 1 and is zero before c */ |
---|
1272 | c = 0.5; |
---|
1273 | frac_x = (frac > c) ? (frac-c)/(1.0-c) : 0.0; |
---|
1274 | color.green = Nint( frac_x * 65535.0 ); |
---|
1275 | /* blue decreases from 1 to 0 between 0 and c and then stays 0 */ |
---|
1276 | c = 0.5; /*0.8;*/ |
---|
1277 | frac_x = (frac < c) ? (1.0-frac/c) : 0.0; |
---|
1278 | color.blue = Nint( frac_x * 65535.0 ); |
---|
1279 | break; |
---|
1280 | default: |
---|
1281 | color.red = Nint((1-frac)*65535.0); |
---|
1282 | color.green = color.blue = color.red; |
---|
1283 | break; |
---|
1284 | } /*endswitch*/ |
---|
1285 | color.flags = DoRed | DoGreen | DoBlue; |
---|
1286 | if (!XAllocColor(XtDisplay(w),default_cmap,&color)) { |
---|
1287 | fprintf( stderr, "%s: error allocating color\n", mmv_pname ); |
---|
1288 | exit( 1 ); |
---|
1289 | } /*endif*/ |
---|
1290 | XSetForeground( XtDisplay(w), gc[i], color.pixel ); |
---|
1291 | XSetBackground( XtDisplay(w), gc[i], |
---|
1292 | WhitePixel(XtDisplay(w),screen_num) ); |
---|
1293 | } /*endfor*/ |
---|
1294 | |
---|
1295 | } /* end of mm_change_gc */ |
---|
1296 | |
---|
1297 | |
---|
1298 | |
---|
1299 | /*--------------------------------------------------------------------------*/ |
---|