1 | |
---|
2 | /* file mapmatrix.c |
---|
3 | * =========== |
---|
4 | * |
---|
5 | * version 2, 11-Oct-2006 |
---|
6 | * |
---|
7 | * maps spectrograms |
---|
8 | * K. Stammler, 7-Oct-2006 |
---|
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 MmcMAX_WIDGET 100 |
---|
47 | |
---|
48 | #define MmcMAX_COLOR 101 |
---|
49 | #define MmcMAXCMT 10 |
---|
50 | |
---|
51 | #define MmcCHARHEIGHT 12 |
---|
52 | |
---|
53 | #define MmcCOLORS_GREEN_RED 1 |
---|
54 | #define MmcCOLORS_BLUE_RED 2 |
---|
55 | #define MmcCOLORS_BLACK_WHITE 3 |
---|
56 | #define MmcCOLORS_BLUE_YELLOW 4 |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | /* local types */ |
---|
61 | |
---|
62 | typedef struct { |
---|
63 | float **val; /* pointer to matrix */ |
---|
64 | int width; /* width of matrix */ |
---|
65 | int height; /* height of matrix */ |
---|
66 | float minval; /* minimum value */ |
---|
67 | float maxval; /* maximum value */ |
---|
68 | } MmtMATRIX; |
---|
69 | |
---|
70 | typedef struct { |
---|
71 | int colnum; /* number of colors */ |
---|
72 | unsigned margin_l; /* left margin */ |
---|
73 | unsigned margin_r; /* right margin */ |
---|
74 | unsigned margin_t; /* top margin */ |
---|
75 | unsigned margin_b; /* bottom margin */ |
---|
76 | } MmtDSP_SETUP; |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | /* global variables */ |
---|
81 | static char *mmv_vec[]={"mapspec.uid"}; /* MRM database file list */ |
---|
82 | static Display *mmv_display; /* display */ |
---|
83 | static Widget mmv_w[MmcMAX_WIDGET]; /* widget array */ |
---|
84 | static char mmv_pname[BC_FILELTH+1]; /* program name */ |
---|
85 | static MmtMATRIX mmv_matrix; /* matrix */ |
---|
86 | static MmtDSP_SETUP mmv_setup; /* display setup */ |
---|
87 | static GC mmv_gc[MmcMAX_COLOR]; /* color gc's */ |
---|
88 | |
---|
89 | static char mmv_cmt[MmcMAXCMT][BC_LINELTH+1]; /* comment lines */ |
---|
90 | static int mmv_cmtcnt; /* comment counter */ |
---|
91 | static float mmv_scale; /* scale factor */ |
---|
92 | static float mmv_yscale; /* y-scale factor (cart.) */ |
---|
93 | static float mmv_df; /* frequency sampling */ |
---|
94 | static BOOLEAN mmv_pixinit=FALSE; /* pixel buffer initialized */ |
---|
95 | static float mmv_ymin; /* y start value (cart) */ |
---|
96 | static BOOLEAN mmv_logdsp=TRUE; /* logarithmic display */ |
---|
97 | static char mmv_starttime[cBcLineLth+1]=""; /* start time */ |
---|
98 | static char mmv_inpfile[BC_FILELTH+1]; /* name of input file */ |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | /* prototypes */ |
---|
104 | static void cb_call_create_widget( Widget widget, int *tag, |
---|
105 | XmAnyCallbackStruct *data ); |
---|
106 | static void cb_call_activate( Widget widget, int *tag, |
---|
107 | XmToggleButtonCallbackStruct *data ); |
---|
108 | void cb_action_motion_cart( Widget w, XEvent *ev, String *params, |
---|
109 | Cardinal *parno ); |
---|
110 | static void cb_call_expose( Widget widget, char *tag, |
---|
111 | XmDrawingAreaCallbackStruct *data ); |
---|
112 | static void mm_draw_labels( Widget w ); |
---|
113 | |
---|
114 | static void mm_prepare_gc( Widget w, MmtDSP_SETUP *setup, GC gc[] ); |
---|
115 | static void mm_read_matrix( char filename[], MmtMATRIX *mat ); |
---|
116 | static void mm_display_matrix( Widget w, GC gc[], MmtDSP_SETUP *setup, |
---|
117 | MmtMATRIX *mat, int power ); |
---|
118 | static void mm_change_gc( Widget w, int mode, MmtDSP_SETUP *setup, GC gc[] ); |
---|
119 | |
---|
120 | |
---|
121 | /* routines to register */ |
---|
122 | static MrmCount mmv_regnum = 3 ; |
---|
123 | static MrmRegisterArg mmv_regvec[] = { |
---|
124 | { "call_create_widget", (caddr_t)cb_call_create_widget }, |
---|
125 | { "call_activate", (caddr_t)cb_call_activate }, |
---|
126 | { "call_expose", (caddr_t)cb_call_expose } |
---|
127 | }; |
---|
128 | |
---|
129 | /* action routines */ |
---|
130 | static XtActionsRec mmv_new_actions_cart[] = { |
---|
131 | {"cb_action_motion_cart", cb_action_motion_cart} |
---|
132 | }; |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | int main( int argc, char *argv[] ) |
---|
137 | { |
---|
138 | /* local variables */ |
---|
139 | MrmHierarchy hierarchy; /* hierarchy */ |
---|
140 | MrmCode class; /* class */ |
---|
141 | XtAppContext app_context; /* application contex */ |
---|
142 | Arg arglist[2]; |
---|
143 | int n; |
---|
144 | int pix_w, pix_h; /* size of window in pixel */ |
---|
145 | TSyStatus locstat; /* local status */ |
---|
146 | |
---|
147 | /* executable code */ |
---|
148 | |
---|
149 | pa_init( argc, argv ); |
---|
150 | pix_w = pix_h = 0; |
---|
151 | |
---|
152 | if (pa_pnumber() != 2) { |
---|
153 | fprintf( stderr, "*** Usage: %s <file> <colnum> ***\n", argv[0] ); |
---|
154 | fprintf( stderr, " qualifiers:\n" ); |
---|
155 | fprintf( stderr, " -w=<pixwidth> width of window in pixel\n" ); |
---|
156 | fprintf( stderr, " -h=<pixheight> height of window in pixel\n" ); |
---|
157 | return 1; |
---|
158 | } /*endif*/ |
---|
159 | |
---|
160 | /* set margins */ |
---|
161 | mmv_setup.margin_l = 40; |
---|
162 | mmv_setup.margin_r = 20; |
---|
163 | mmv_setup.margin_t = 30; |
---|
164 | mmv_setup.margin_b = 40; |
---|
165 | |
---|
166 | mmv_matrix.val = NULL; |
---|
167 | |
---|
168 | /* strcpy( mmv_pname, argv[0] ); */ |
---|
169 | strcpy( mmv_pname, "mapspec" ); |
---|
170 | strcpy( mmv_inpfile, pa_pvalue(1) ); |
---|
171 | sscanf( pa_pvalue(2), "%d", &mmv_setup.colnum ); |
---|
172 | mmv_scale = 1.0; |
---|
173 | if (mmv_setup.colnum < 2) mmv_setup.colnum = 2; |
---|
174 | if (mmv_setup.colnum > 500) mmv_setup.colnum = 500; |
---|
175 | if (pa_qspecified("-w")) { |
---|
176 | sscanf( pa_qvalue("-w"), "%d", &pix_w ); |
---|
177 | if (pix_w < 400) pix_w = 400; |
---|
178 | } /*endif*/ |
---|
179 | if (pa_qspecified("-h")) { |
---|
180 | sscanf( pa_qvalue("-h"), "%d", &pix_h ); |
---|
181 | if (pix_h < 400) pix_h = 400; |
---|
182 | } /*endif*/ |
---|
183 | if (pa_qspecified("-r")) |
---|
184 | sscanf( pa_qvalue("-r"), "%d", &mmv_setup.margin_r ); |
---|
185 | if (pa_qspecified("-ymax")) { |
---|
186 | sscanf( pa_qvalue("-ymax"), "%f", &mmv_yscale ); |
---|
187 | } /*endif*/ |
---|
188 | mmv_ymin = 0.0; |
---|
189 | if (pa_qspecified("-ymin")) |
---|
190 | sscanf( pa_qvalue("-ymin"), "%f", &mmv_ymin ); |
---|
191 | |
---|
192 | if (mmv_ymin != 0.0) |
---|
193 | mmv_yscale -= mmv_ymin; |
---|
194 | |
---|
195 | MrmInitialize (); |
---|
196 | XtToolkitInitialize(); |
---|
197 | app_context = XtCreateApplicationContext(); |
---|
198 | mmv_display = XtOpenDisplay(app_context, NULL, mmv_pname, "mapmatrix", |
---|
199 | NULL, 0, &argc, argv); |
---|
200 | if (mmv_display == NULL) { |
---|
201 | fprintf(stderr, "%s: Can't open display\n", mmv_pname ); |
---|
202 | exit(1); |
---|
203 | } /*endif*/ |
---|
204 | |
---|
205 | XtAppAddActions( app_context, mmv_new_actions_cart, 1 ); |
---|
206 | |
---|
207 | n = 0; |
---|
208 | /* XtSetArg(arglist[n], XmNallowShellResize, True); n++; */ |
---|
209 | mmv_w[w_toplevel] = XtAppCreateShell( mmv_pname, NULL, |
---|
210 | applicationShellWidgetClass, mmv_display, arglist, n); |
---|
211 | |
---|
212 | if (MrmOpenHierarchy(1,mmv_vec,NULL,&hierarchy) != MrmSUCCESS) { |
---|
213 | fprintf ( stderr, "can't open hierarchy\n" ); |
---|
214 | exit( 1 ); |
---|
215 | } /*endif*/ |
---|
216 | |
---|
217 | if (MrmRegisterNames(mmv_regvec,mmv_regnum) != MrmSUCCESS) { |
---|
218 | fprintf( stderr, "can't register names\n" ); |
---|
219 | exit( 1 ); |
---|
220 | } /*endif*/ |
---|
221 | |
---|
222 | if (MrmFetchWidget(hierarchy,"main_window",mmv_w[w_toplevel], |
---|
223 | mmv_w+w_main,&class) != MrmSUCCESS) { |
---|
224 | fprintf( stderr, "can't fetch widget\n" ); |
---|
225 | exit( 1 ); |
---|
226 | } /*endif*/ |
---|
227 | |
---|
228 | n = 0; |
---|
229 | if (pix_w > 0) {XtSetArg( arglist[n], XmNwidth, pix_w ); n++;} |
---|
230 | if (pix_h > 0) {XtSetArg( arglist[n], XmNheight, pix_h ); n++;} |
---|
231 | if (n > 0) XtSetValues( mmv_w[w_draw], arglist, n ); |
---|
232 | /*if (n > 0) XtSetValues( mmv_w[w_main], arglist, n );*/ |
---|
233 | |
---|
234 | XtManageChild( mmv_w[w_main] ); |
---|
235 | XtRealizeWidget( mmv_w[w_toplevel] ); |
---|
236 | |
---|
237 | /* read in data file */ |
---|
238 | mm_read_matrix( mmv_inpfile, &mmv_matrix ); |
---|
239 | mm_prepare_gc( mmv_w[w_draw], &mmv_setup, mmv_gc ); |
---|
240 | |
---|
241 | if (!mmv_pixinit) { |
---|
242 | locstat = BC_NOERROR; |
---|
243 | pix_create_window_buffer( XtDisplay(mmv_w[w_draw]), |
---|
244 | XtWindow(mmv_w[w_draw]), TRUE, &locstat ); |
---|
245 | if (Severe(&locstat)) { |
---|
246 | fprintf( stderr, "mapmatrix: error creating window buffer\n" ); |
---|
247 | exit( 1 ); |
---|
248 | } /*endif*/ |
---|
249 | mmv_pixinit = TRUE; |
---|
250 | } /*endif*/ |
---|
251 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 1 ); |
---|
252 | |
---|
253 | XtAppMainLoop(app_context); |
---|
254 | |
---|
255 | return 0; |
---|
256 | |
---|
257 | } /* end of main */ |
---|
258 | |
---|
259 | |
---|
260 | |
---|
261 | /*--------------------------------------------------------------------------*/ |
---|
262 | |
---|
263 | |
---|
264 | |
---|
265 | static void cb_call_create_widget( Widget widget, int *tag, |
---|
266 | XmAnyCallbackStruct *data ) |
---|
267 | |
---|
268 | /* Callback routine on createing widgets |
---|
269 | * |
---|
270 | * parameters of routine |
---|
271 | * Widget widget; input; widget number of drawing area |
---|
272 | * int *tag; input; widget number |
---|
273 | * XmAnyCallbackStruct *data; input; not used here |
---|
274 | */ |
---|
275 | { |
---|
276 | /* local variables */ |
---|
277 | int wno = *tag; /* widget number */ |
---|
278 | char acttable[BC_LONGSTRLTH+1]; /* action table */ |
---|
279 | XtTranslations new_table; /* translated table */ |
---|
280 | Arg al[1]; |
---|
281 | |
---|
282 | /* executable code */ |
---|
283 | |
---|
284 | if (wno >= MmcMAX_WIDGET || wno < 0) { |
---|
285 | fprintf( stderr, "--> illegal widget number %d\n", wno ); |
---|
286 | return; |
---|
287 | } /*endif*/ |
---|
288 | |
---|
289 | /* printf( "[%d]", wno ); */ |
---|
290 | mmv_w[wno] = widget; |
---|
291 | |
---|
292 | if (wno == w_draw) { |
---|
293 | strcpy( acttable, "<Motion>: cb_action_motion_cart()\n" ); |
---|
294 | strcat( acttable, "<Btn1Down>: cb_action_motion_cart()\n" ); |
---|
295 | strcat( acttable, "<Btn1Up>: cb_action_motion_cart()\n" ); |
---|
296 | strcat( acttable, "<Btn2Down>: cb_action_motion_cart()\n" ); |
---|
297 | strcat( acttable, "<Btn2Up>: cb_action_motion_cart()\n" ); |
---|
298 | strcat( acttable, "<Btn3Down>: cb_action_motion_cart()\n" ); |
---|
299 | strcat( acttable, "<Btn3Up>: cb_action_motion_cart()\n" ); |
---|
300 | new_table = XtParseTranslationTable( acttable ); |
---|
301 | XtSetArg( al[0], XmNtranslations, new_table ); |
---|
302 | XtSetValues( mmv_w[w_draw], al, 1 ); |
---|
303 | } /*endif*/ |
---|
304 | |
---|
305 | } /* end of cb_call_create_widget */ |
---|
306 | |
---|
307 | |
---|
308 | |
---|
309 | /*--------------------------------------------------------------------------*/ |
---|
310 | |
---|
311 | |
---|
312 | |
---|
313 | static void cb_call_activate( Widget widget, int *tag, |
---|
314 | XmToggleButtonCallbackStruct *data ) |
---|
315 | |
---|
316 | /* Callback routine on button selection |
---|
317 | * |
---|
318 | * parameters of routine |
---|
319 | * Widget widget; input; widget number of drawing area |
---|
320 | * int *tag; input; tag entry |
---|
321 | * XmPushButtonCallbackStruct *data; input; |
---|
322 | */ |
---|
323 | { |
---|
324 | /* local variables */ |
---|
325 | static int power=1; /* current power */ |
---|
326 | STATUS locstat; /* local status */ |
---|
327 | |
---|
328 | /* executable code */ |
---|
329 | |
---|
330 | if (!mmv_pixinit) { |
---|
331 | locstat = BC_NOERROR; |
---|
332 | pix_create_window_buffer( XtDisplay(mmv_w[w_draw]), |
---|
333 | XtWindow(mmv_w[w_draw]), TRUE, &locstat ); |
---|
334 | if (Severe(&locstat)) { |
---|
335 | fprintf( stderr, "mapmatrix: error creating window buffer\n" ); |
---|
336 | exit( 1 ); |
---|
337 | } /*endif*/ |
---|
338 | mmv_pixinit = TRUE; |
---|
339 | } /*endif*/ |
---|
340 | |
---|
341 | switch (*tag) { |
---|
342 | case w_entry_quit: |
---|
343 | exit( 0 ); |
---|
344 | case w_entry_plot: |
---|
345 | power=1; |
---|
346 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 1 ); |
---|
347 | break; |
---|
348 | case w_entry_plot_log: |
---|
349 | /*power = 0;*/ |
---|
350 | mmv_logdsp = !mmv_logdsp; |
---|
351 | mm_read_matrix( mmv_inpfile, &mmv_matrix ); |
---|
352 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, 0 ); |
---|
353 | break; |
---|
354 | case w_entry_plot_p2: |
---|
355 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, |
---|
356 | ++power ); |
---|
357 | break; |
---|
358 | case w_entry_plot_p4: |
---|
359 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, |
---|
360 | --power ); |
---|
361 | break; |
---|
362 | case w_entry_colors_green_red: |
---|
363 | mm_change_gc( mmv_w[w_draw], MmcCOLORS_GREEN_RED, &mmv_setup, mmv_gc ); |
---|
364 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, power); |
---|
365 | break; |
---|
366 | case w_entry_colors_blue_red: |
---|
367 | mm_change_gc( mmv_w[w_draw], MmcCOLORS_BLUE_RED, &mmv_setup, mmv_gc ); |
---|
368 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, power); |
---|
369 | break; |
---|
370 | case w_entry_colors_black_white: |
---|
371 | mm_change_gc( mmv_w[w_draw], MmcCOLORS_BLACK_WHITE, &mmv_setup, mmv_gc ); |
---|
372 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, power); |
---|
373 | break; |
---|
374 | case w_entry_colors_blue_yellow: |
---|
375 | mm_change_gc( mmv_w[w_draw], MmcCOLORS_BLUE_YELLOW, &mmv_setup, mmv_gc ); |
---|
376 | mm_display_matrix( mmv_w[w_draw], mmv_gc, &mmv_setup, &mmv_matrix, power); |
---|
377 | break; |
---|
378 | default: |
---|
379 | fprintf( stderr, "illegal widget activated (%d)\n", *tag ); |
---|
380 | return; |
---|
381 | } /*endswitch*/ |
---|
382 | |
---|
383 | } /* end of cb_call_activate */ |
---|
384 | |
---|
385 | |
---|
386 | |
---|
387 | /*--------------------------------------------------------------------------*/ |
---|
388 | |
---|
389 | |
---|
390 | |
---|
391 | static void cb_call_expose( Widget widget, char *tag, |
---|
392 | XmDrawingAreaCallbackStruct *data ) |
---|
393 | |
---|
394 | /* Callback routine on creation of drawing area |
---|
395 | * |
---|
396 | * parameters of routine |
---|
397 | * Widget widget; input; widget number of drawing area |
---|
398 | * char *tag; input; not used here |
---|
399 | * XmDrawingAreaCallbackStruct *data; input; |
---|
400 | */ |
---|
401 | { |
---|
402 | /* local variables */ |
---|
403 | |
---|
404 | /* executable code */ |
---|
405 | |
---|
406 | if (mmv_pixinit) |
---|
407 | pix_manage_exposure( &(data->event->xexpose) ); |
---|
408 | |
---|
409 | } /* end of cb_call_expose */ |
---|
410 | |
---|
411 | |
---|
412 | |
---|
413 | /*--------------------------------------------------------------------------*/ |
---|
414 | |
---|
415 | |
---|
416 | #define POSTEXT_X 0 |
---|
417 | #define POSTEXT_Y 8 |
---|
418 | |
---|
419 | |
---|
420 | |
---|
421 | void cb_action_motion_cart( Widget w, XEvent *ev, String *params, |
---|
422 | Cardinal *parno ) |
---|
423 | |
---|
424 | /* action routine for pointer motion |
---|
425 | * |
---|
426 | * parameters of routine |
---|
427 | * Widget w; input; widget ID |
---|
428 | * XEvent *ev; input; current event |
---|
429 | * ... (don't know much about it) |
---|
430 | */ |
---|
431 | { |
---|
432 | /* local variables */ |
---|
433 | static BOOLEAN is_init=FALSE; /* already initialized */ |
---|
434 | static int pos_x, pos_y; /* draw position */ |
---|
435 | static GC xgc; /* clear GC */ |
---|
436 | static char oldstr[BC_LINELTH+1];/* old string */ |
---|
437 | static char oldstr2[BC_LINELTH+1];/* old string */ |
---|
438 | static int eff_w, eff_h; /* effective size of window */ |
---|
439 | char postext[BC_LINELTH+1]; /* position text */ |
---|
440 | char postext2[BC_LINELTH+1]; /* position text */ |
---|
441 | Window root; /* root window */ |
---|
442 | int w_x, w_y; /* window position */ |
---|
443 | unsigned w_w, w_h; /* size of window */ |
---|
444 | unsigned border, depth; /* window pars (not used) */ |
---|
445 | float slow_x, frequ; /* slowness position */ |
---|
446 | char ctime[cBcTimeLth+1]; /* current absolute time */ |
---|
447 | STATUS locstat; /* local status */ |
---|
448 | |
---|
449 | /* executable code */ |
---|
450 | |
---|
451 | if (w != mmv_w[w_draw]) {printf("--> motion: ill wdw\n"); return;} |
---|
452 | |
---|
453 | XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h, |
---|
454 | &border, &depth ); |
---|
455 | pos_x = mmv_setup.margin_l + POSTEXT_X; |
---|
456 | pos_y = w_h - POSTEXT_Y; |
---|
457 | eff_w = w_w - mmv_setup.margin_l - mmv_setup.margin_r; |
---|
458 | eff_h = w_h - mmv_setup.margin_t - mmv_setup.margin_b; |
---|
459 | if (!is_init) { |
---|
460 | xgc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
461 | /* XSetForeground( XtDisplay(w), xgc, BlackPixel(XtDisplay(w),0) ); */ |
---|
462 | /* XSetBackground( XtDisplay(w), xgc, WhitePixel(XtDisplay(w),0) ); */ |
---|
463 | XCopyGC( XtDisplay(w), mmv_gc[mmv_setup.colnum], GCFont, xgc ); |
---|
464 | XSetForeground( XtDisplay(w), xgc, WhitePixel(XtDisplay(w),0) ); |
---|
465 | XSetBackground( XtDisplay(w), xgc, BlackPixel(XtDisplay(w),0) ); |
---|
466 | /* XSetFunction( XtDisplay(w), xgc, GXxor ); */ |
---|
467 | is_init = TRUE; |
---|
468 | } /*endif*/ |
---|
469 | |
---|
470 | if (ev->type == MotionNotify) { |
---|
471 | if (ev->xmotion.x < mmv_setup.margin_l |
---|
472 | || ev->xmotion.y < mmv_setup.margin_t |
---|
473 | || ev->xmotion.x > mmv_setup.margin_l+eff_w |
---|
474 | || ev->xmotion.y > mmv_setup.margin_t+eff_h) { |
---|
475 | *postext = *postext2 = '\0'; |
---|
476 | } else { |
---|
477 | slow_x = (float)(ev->xmotion.x - mmv_setup.margin_l); |
---|
478 | frequ = (float)(ev->xmotion.y - mmv_setup.margin_t); |
---|
479 | slow_x = slow_x / (float)eff_w * mmv_scale; |
---|
480 | frequ = mmv_ymin + mmv_yscale - (frequ / (float)eff_h * mmv_yscale); |
---|
481 | locstat = cBcNoError; |
---|
482 | tc_tadd( mmv_starttime, slow_x, ctime, &locstat ); |
---|
483 | sprintf( postext, "time: %s, %6.2f s", ctime, slow_x ); |
---|
484 | if (mmv_logdsp) { |
---|
485 | frequ /= mmv_yscale; |
---|
486 | frequ = log(mmv_df) + frequ*(log(mmv_yscale)-log(mmv_df)); |
---|
487 | frequ = exp( frequ ); |
---|
488 | } /*endif*/ |
---|
489 | sprintf( postext2, "freq: %6.2f Hz", frequ ); |
---|
490 | } /*endif*/ |
---|
491 | if (*oldstr != '\0') { |
---|
492 | pix_DrawString( XtDisplay(w), XtWindow(w), xgc, |
---|
493 | pos_x, pos_y, oldstr, strlen(oldstr) ); |
---|
494 | pix_DrawString( XtDisplay(w), XtWindow(w), xgc, |
---|
495 | pos_x+260, pos_y, oldstr2, strlen(oldstr2) ); |
---|
496 | } /*endif*/ |
---|
497 | if (*postext != '\0') { |
---|
498 | pix_DrawString( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], |
---|
499 | pos_x, pos_y, postext, strlen(postext) ); |
---|
500 | pix_DrawString( XtDisplay(w), XtWindow(w), mmv_gc[mmv_setup.colnum], |
---|
501 | pos_x+260, pos_y, postext2, strlen(postext2) ); |
---|
502 | } /*endif*/ |
---|
503 | strcpy( oldstr, postext ); |
---|
504 | strcpy( oldstr2, postext2 ); |
---|
505 | XFlush( XtDisplay(w) ); |
---|
506 | } /*endif*/ |
---|
507 | |
---|
508 | } /* end of cb_action_motion_cart */ |
---|
509 | |
---|
510 | |
---|
511 | |
---|
512 | /*--------------------------------------------------------------------------*/ |
---|
513 | |
---|
514 | |
---|
515 | #define LNCONV 2.30258509 |
---|
516 | |
---|
517 | |
---|
518 | static void mm_draw_labels( Widget w ) |
---|
519 | |
---|
520 | /* Draws labels to spectrogram |
---|
521 | * |
---|
522 | * parameters of routine |
---|
523 | * Widget w; input; drawing widget |
---|
524 | */ |
---|
525 | { |
---|
526 | /* local variables */ |
---|
527 | static BOOLEAN l_is_init=FALSE; /* already initialized */ |
---|
528 | int pos_x, pos_y; /* draw position */ |
---|
529 | static int eff_w, eff_h; /* effective size of window */ |
---|
530 | static GC wgc; /* write GC */ |
---|
531 | static float nicenum[] = { /* nice numbers */ |
---|
532 | 1.0,2.0,5.0,10.0,20.0,50.0,100.0,200.0,500.0, |
---|
533 | 1000.0,2000.0,5000.0,10000.0,0.0 |
---|
534 | }; |
---|
535 | Window root; /* root window */ |
---|
536 | int w_x, w_y; /* window position */ |
---|
537 | unsigned w_w, w_h; /* size of window */ |
---|
538 | unsigned border, depth; /* window pars (not used) */ |
---|
539 | float t_inc; /* time increment for labels */ |
---|
540 | int i, j; /* counters */ |
---|
541 | float tmp; /* scratch */ |
---|
542 | char label[cBcShortStrLth+1]; /* label string */ |
---|
543 | int itmp; /* int scratch */ |
---|
544 | float ylogscale; /* log scale */ |
---|
545 | |
---|
546 | /* executable code */ |
---|
547 | |
---|
548 | XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h, |
---|
549 | &border, &depth ); |
---|
550 | eff_w = w_w - mmv_setup.margin_l - mmv_setup.margin_r; |
---|
551 | eff_h = w_h - mmv_setup.margin_t - mmv_setup.margin_b; |
---|
552 | if (!l_is_init) { |
---|
553 | wgc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
554 | XCopyGC( XtDisplay(w), mmv_gc[mmv_setup.colnum], GCFont, wgc ); |
---|
555 | XSetForeground( XtDisplay(w), wgc, BlackPixel(XtDisplay(w),0) ); |
---|
556 | XSetBackground( XtDisplay(w), wgc, WhitePixel(XtDisplay(w),0) ); |
---|
557 | l_is_init = TRUE; |
---|
558 | } /*endif*/ |
---|
559 | |
---|
560 | /* get label distance on time */ |
---|
561 | t_inc = mmv_scale / 4.0; |
---|
562 | tmp = t_inc; |
---|
563 | i = j = 0; |
---|
564 | while (nicenum[i] > 0.0) { |
---|
565 | if (fabs(t_inc-nicenum[i]) < tmp) { |
---|
566 | tmp = fabs(t_inc-nicenum[i]); |
---|
567 | j = i; |
---|
568 | } /*endif*/ |
---|
569 | i++; |
---|
570 | } /*endif*/ |
---|
571 | t_inc = nicenum[j]; |
---|
572 | |
---|
573 | tmp = 0.0; |
---|
574 | while (tmp < mmv_scale) { |
---|
575 | sprintf( label, "%g", tmp ); |
---|
576 | pos_x = mmv_setup.margin_l + (int)(tmp/mmv_scale*(float)eff_w); |
---|
577 | pos_y = w_h - mmv_setup.margin_b; |
---|
578 | pix_DrawLine( XtDisplay(w), XtWindow(w), wgc, pos_x, pos_y, pos_x, pos_y+5 ); |
---|
579 | pix_DrawString( XtDisplay(w), XtWindow(w), wgc, |
---|
580 | pos_x-5, pos_y+MmcCHARHEIGHT+5, label, strlen(label) ); |
---|
581 | tmp += t_inc; |
---|
582 | } /*endwhile*/ |
---|
583 | |
---|
584 | if (mmv_logdsp) { |
---|
585 | pos_x = mmv_setup.margin_l; |
---|
586 | itmp = (int)(log(mmv_df)/LNCONV); |
---|
587 | if (itmp > 0) itmp++; |
---|
588 | ylogscale = (log(mmv_yscale)-log(mmv_df))/LNCONV; |
---|
589 | while (pow((float)itmp,10.0) < mmv_yscale*1.01) { |
---|
590 | pos_y = w_h - mmv_setup.margin_b |
---|
591 | - ((float)itmp-(log(mmv_df)/LNCONV))/ylogscale*(float)eff_h; |
---|
592 | sprintf( label, "%d", itmp ); |
---|
593 | pix_DrawLine( XtDisplay(w), XtWindow(w), wgc, |
---|
594 | pos_x, pos_y, pos_x-5, pos_y ); |
---|
595 | pix_DrawString( XtDisplay(w), XtWindow(w), wgc, |
---|
596 | pos_x-20, pos_y-(MmcCHARHEIGHT/2)+6, label, strlen(label) ); |
---|
597 | pix_DrawString( XtDisplay(w), XtWindow(w), wgc, |
---|
598 | pos_x-33, pos_y+5, "10", 2 ); |
---|
599 | itmp++; |
---|
600 | } /*endwhile*/ |
---|
601 | } else { |
---|
602 | pos_x = mmv_setup.margin_l; |
---|
603 | itmp = 0; |
---|
604 | while ((float)itmp < mmv_yscale*1.01) { |
---|
605 | pos_y = w_h - mmv_setup.margin_b |
---|
606 | - ((float)itmp/mmv_yscale)*(float)eff_h; |
---|
607 | pix_DrawLine( XtDisplay(w), XtWindow(w), wgc, |
---|
608 | pos_x, pos_y, pos_x-5, pos_y ); |
---|
609 | sprintf( label, "%d", itmp ); |
---|
610 | pix_DrawString( XtDisplay(w), XtWindow(w), wgc, |
---|
611 | pos_x-20, pos_y+4, label, strlen(label) ); |
---|
612 | itmp += 5; |
---|
613 | } /*endwhile*/ |
---|
614 | } /*endif*/ |
---|
615 | |
---|
616 | /* legend */ |
---|
617 | pos_x = 5; |
---|
618 | pos_y = 13; |
---|
619 | strcpy( label, "frq in Hz" ); |
---|
620 | pix_DrawString( XtDisplay(w), XtWindow(w), wgc, |
---|
621 | pos_x, pos_y, label, strlen(label) ); |
---|
622 | pos_x = w_w-80; |
---|
623 | pos_y = w_h-10; |
---|
624 | strcpy( label, "time in s" ); |
---|
625 | pix_DrawString( XtDisplay(w), XtWindow(w), wgc, |
---|
626 | pos_x, pos_y, label, strlen(label) ); |
---|
627 | |
---|
628 | } /* end of mm_draw_labels */ |
---|
629 | |
---|
630 | |
---|
631 | |
---|
632 | /*--------------------------------------------------------------------------*/ |
---|
633 | |
---|
634 | |
---|
635 | |
---|
636 | static void mm_read_matrix( char filename[], MmtMATRIX *mat ) |
---|
637 | |
---|
638 | /* Allocates memory for matrix and reads it from file |
---|
639 | * |
---|
640 | * parameters of routine |
---|
641 | * char filename[]; input; name of input file |
---|
642 | * MmtMATRIX *mat; output; matrix |
---|
643 | */ |
---|
644 | { |
---|
645 | /* local variables */ |
---|
646 | FILE *fp; /* pointer to input file */ |
---|
647 | char line[BC_LINELTH+1]; /* current line in input file */ |
---|
648 | int i, j; /* counters */ |
---|
649 | float *lfrq; /* scratch array */ |
---|
650 | float logmin; /* log frq minimum */ |
---|
651 | float logmax; /* log frq maximum */ |
---|
652 | float logdf; /* logarithmic difference */ |
---|
653 | float logf; /* current logarithmic frq */ |
---|
654 | float tmp; /* scratch */ |
---|
655 | int idx; /* index number */ |
---|
656 | |
---|
657 | /* executable code */ |
---|
658 | |
---|
659 | fp = fopen( filename, "r" ); |
---|
660 | if (fp == NULL) { |
---|
661 | fprintf( stderr, "%s: couldn't open input file %s\n", |
---|
662 | mmv_pname, filename ); |
---|
663 | exit( 1 ); |
---|
664 | } /*endif*/ |
---|
665 | |
---|
666 | /* read off comments */ |
---|
667 | mmv_cmtcnt = 0; |
---|
668 | while (fgets(line,BC_LINELTH,fp) != NULL) { |
---|
669 | if (*line != '!') break; |
---|
670 | if (line[1] == '*' && mmv_cmtcnt < MmcMAXCMT) { |
---|
671 | strcpy( mmv_cmt[mmv_cmtcnt], line+2 ); |
---|
672 | i = strlen( mmv_cmt[mmv_cmtcnt] ) - 1; |
---|
673 | if (mmv_cmt[mmv_cmtcnt][i] == '\n') |
---|
674 | mmv_cmt[mmv_cmtcnt][i] = '\0'; |
---|
675 | mmv_cmtcnt++; |
---|
676 | } /*endif*/ |
---|
677 | if (strncmp(line,"! LENGTH:",10) == 0) { |
---|
678 | if (sscanf( line+10, "%d", &(mat->height) ) != 1) { |
---|
679 | fprintf( stderr, "%s: error reading LENGTH\n", mmv_pname ); |
---|
680 | exit( 1 ); |
---|
681 | } /*endif*/ |
---|
682 | } else if (strncmp(line,"! LINES:",9) == 0) { |
---|
683 | if (sscanf( line+9, "%d", &(mat->width) ) != 1) { |
---|
684 | fprintf( stderr, "%s: error reading LINES\n", mmv_pname ); |
---|
685 | exit( 1 ); |
---|
686 | } /*endif*/ |
---|
687 | } else if (strncmp(line,"! DELTA:",9) == 0) { |
---|
688 | if (sscanf( line+9, "%f", &mmv_scale ) != 1) { |
---|
689 | fprintf( stderr, "%s: error reading DELTA\n", mmv_pname ); |
---|
690 | exit( 1 ); |
---|
691 | } /*endif*/ |
---|
692 | } else if (strncmp(line,"! DF:",6) == 0) { |
---|
693 | if (sscanf( line+6, "%f", &mmv_df ) != 1) { |
---|
694 | fprintf( stderr, "%s: error reading DF\n", mmv_pname ); |
---|
695 | exit( 1 ); |
---|
696 | } /*endif*/ |
---|
697 | } else if (strncmp(line,"! START:",9) == 0) { |
---|
698 | if (sscanf( line+9, "%s", &mmv_starttime ) != 1) { |
---|
699 | fprintf( stderr, "%s: error reading START\n", mmv_pname ); |
---|
700 | exit( 1 ); |
---|
701 | } /*endif*/ |
---|
702 | } /*endif*/ |
---|
703 | } /*endwhile*/ |
---|
704 | |
---|
705 | if (mmv_starttime[0] != '\0' && mmv_cmtcnt > 0) { |
---|
706 | strcat( mmv_cmt[0], " " ); |
---|
707 | strcat( mmv_cmt[0], mmv_starttime ); |
---|
708 | } /*endif*/ |
---|
709 | |
---|
710 | mmv_scale *= (float)(mat->width); |
---|
711 | mmv_yscale = mmv_df * (float)(mat->height); |
---|
712 | |
---|
713 | /* allocate pointers if not yet done */ |
---|
714 | if (mat->val == NULL) { |
---|
715 | mat->val = (float **)malloc( sizeof(float *) * mat->height ); |
---|
716 | if (mat->val == NULL) { |
---|
717 | fprintf( stderr, "%s: allocation error (pointers)\n", mmv_pname ); |
---|
718 | exit( 1 ); |
---|
719 | } /*endif*/ |
---|
720 | /* allocate rows */ |
---|
721 | for (i=0; i<(mat->height); i++) { |
---|
722 | mat->val[i] = (float *)malloc( sizeof(float) * mat->width ); |
---|
723 | if (mat->val[i] == NULL) { |
---|
724 | fprintf( stderr, "%s: allocation error (row %d)\n", mmv_pname, i ); |
---|
725 | exit( 1 ); |
---|
726 | } /*endif*/ |
---|
727 | } /*endfor*/ |
---|
728 | } /*endif*/ |
---|
729 | |
---|
730 | /* read in data */ |
---|
731 | for (j=0; j<(mat->width); j++) { |
---|
732 | for (i=0; i<(mat->height); i++) |
---|
733 | fscanf( fp, "%f\n", (mat->val[i])+j ); |
---|
734 | } /*endfor*/ |
---|
735 | |
---|
736 | fclose( fp ); |
---|
737 | |
---|
738 | /* make logarithmic frequency */ |
---|
739 | if (mmv_logdsp) { |
---|
740 | |
---|
741 | lfrq = (float *)malloc( sizeof(float) * mat->height ); |
---|
742 | if (lfrq == NULL) { |
---|
743 | fprintf( stderr, "%s: allocation error (lfrq)\n", mmv_pname ); |
---|
744 | exit( 1 ); |
---|
745 | } /*endif*/ |
---|
746 | |
---|
747 | logmax = log( mmv_df * (float)(mat->height) ); |
---|
748 | logmin = log( mmv_df ); |
---|
749 | logdf = (logmax-logmin) / (float)((mat->height)-1); |
---|
750 | |
---|
751 | for (j=0; j<(mat->width); j++) { |
---|
752 | for (i=0; i<(mat->height); i++) { |
---|
753 | logf = exp( logmin + (float)i*logdf ); |
---|
754 | tmp = logf / mmv_df; |
---|
755 | idx = (int)tmp; |
---|
756 | tmp -= (float)idx; |
---|
757 | if (idx >= (mat->height)-1) { |
---|
758 | lfrq[i] = mat->val[(mat->height)-1][j]; |
---|
759 | } else { |
---|
760 | lfrq[i] = mat->val[idx][j] |
---|
761 | + tmp * (mat->val[idx+1][j]-mat->val[idx][j]); |
---|
762 | } /*endif*/ |
---|
763 | /*printf( "--> %d: %d,%d,%f\n", j, i, idx, tmp );*/ |
---|
764 | } /*endfor*/ |
---|
765 | for (i=0; i<(mat->height); i++) { |
---|
766 | mat->val[i][j] = lfrq[i]; |
---|
767 | } /*endfor*/ |
---|
768 | } /*endfor*/ |
---|
769 | |
---|
770 | free( lfrq ); |
---|
771 | |
---|
772 | } /*endif*/ |
---|
773 | |
---|
774 | /* find min & max, test output */ |
---|
775 | mat->minval = mat->maxval = mat->val[0][0]; |
---|
776 | for (i=0; i<(mat->height); i++) { |
---|
777 | for (j=0; j<(mat->width); j++) { |
---|
778 | /* printf( "%f ", mat->val[i][j] ); */ |
---|
779 | if (mat->val[i][j] > mat->maxval) mat->maxval = mat->val[i][j]; |
---|
780 | if (mat->val[i][j] < mat->minval) mat->minval = mat->val[i][j]; |
---|
781 | } /*endfor*/ |
---|
782 | /* printf( "\n" ); */ |
---|
783 | } /*endfor*/ |
---|
784 | |
---|
785 | /*printf( "--> min, max: %f %f\n", mat->minval, mat->maxval );*/ |
---|
786 | |
---|
787 | } /* end of mm_read_matrix */ |
---|
788 | |
---|
789 | |
---|
790 | |
---|
791 | /*--------------------------------------------------------------------------*/ |
---|
792 | |
---|
793 | |
---|
794 | |
---|
795 | |
---|
796 | static void mm_prepare_gc( Widget w, MmtDSP_SETUP *setup, GC gc[] ) |
---|
797 | |
---|
798 | /* creates GC's for display |
---|
799 | * |
---|
800 | * parameters of routine |
---|
801 | * Widget w; input; widget of drawing area |
---|
802 | * MmtDSP_SETUP *setup; input; display setup |
---|
803 | * GC gc[]; output; array of GC's |
---|
804 | */ |
---|
805 | { |
---|
806 | /* local variables */ |
---|
807 | static char *visual_class[] = { |
---|
808 | "StaticGray", "GrayScale", "StaticColor", "PseudoColor", |
---|
809 | "TrueColor", "DirectColor" |
---|
810 | }; |
---|
811 | int default_depth; /* default depth */ |
---|
812 | Visual *default_visual; /* default visual */ |
---|
813 | XColor color; /* color */ |
---|
814 | Colormap default_cmap; /* default colormap */ |
---|
815 | XVisualInfo visual_info; /* visual info */ |
---|
816 | unsigned i; /* counter */ |
---|
817 | float frac; /* color fraction */ |
---|
818 | float frac_x, c; /* scratch */ |
---|
819 | int screen_num; /* screen number */ |
---|
820 | Font out_font; /* font for text */ |
---|
821 | |
---|
822 | /* executable code */ |
---|
823 | |
---|
824 | screen_num = 0; |
---|
825 | |
---|
826 | default_depth = DefaultDepth( XtDisplay(w), screen_num ); |
---|
827 | default_visual = DefaultVisual( XtDisplay(w), screen_num ); |
---|
828 | default_cmap = DefaultColormap( XtDisplay(w), screen_num ); |
---|
829 | if (default_depth == 1) { |
---|
830 | fprintf( stderr, "%s: StaticGray visual not supported\n", |
---|
831 | mmv_pname ); |
---|
832 | exit( 1 ); |
---|
833 | } /*endif*/ |
---|
834 | |
---|
835 | i = 5; |
---|
836 | while (!XMatchVisualInfo(XtDisplay(w),screen_num,default_depth, |
---|
837 | i--,&visual_info)) |
---|
838 | ; |
---|
839 | |
---|
840 | printf( "%s: found a %s class visual at default depth %d\n", |
---|
841 | mmv_pname, visual_class[++i] ); |
---|
842 | if (i < StaticColor) { |
---|
843 | fprintf( stderr, "%s: visual class %s is not supported\n", |
---|
844 | mmv_pname, visual_class[i] ); |
---|
845 | exit( 1 ); |
---|
846 | } /*endif*/ |
---|
847 | |
---|
848 | if (visual_info.visual != default_visual) |
---|
849 | printf( "%s: %s class visual at default depth is not default visual\n", |
---|
850 | mmv_pname, visual_class[i] ); |
---|
851 | |
---|
852 | if (setup->colnum > MmcMAX_COLOR-1) { |
---|
853 | fprintf( stderr, "%s: too many colors. Only %d permitted\n", |
---|
854 | mmv_pname, MmcMAX_COLOR-1 ); |
---|
855 | exit( 1 ); |
---|
856 | } /*endif*/ |
---|
857 | |
---|
858 | for (i=0; i<(setup->colnum); i++) { |
---|
859 | frac = (float)i / (float)((setup->colnum)-1); |
---|
860 | /* red increases from 0 to c and then stays 1 */ |
---|
861 | c = 0.5; /*0.4;*/ |
---|
862 | frac_x = (frac < c) ? frac/c : 1.0; |
---|
863 | color.red = Nint( frac_x * 65535.0 ); |
---|
864 | /* green increases from c to 1 and is zero before c */ |
---|
865 | c = 0.5; |
---|
866 | frac_x = (frac > c) ? (frac-c)/(1.0-c) : 0.0; |
---|
867 | color.green = Nint( frac_x * 65535.0 ); |
---|
868 | /* blue decreases from 1 to 0 between 0 and c and then stays 0 */ |
---|
869 | c = 0.5; /*0.8;*/ |
---|
870 | frac_x = (frac < c) ? (1.0-frac/c) : 0.0; |
---|
871 | color.blue = Nint( frac_x * 65535.0 ); |
---|
872 | # ifdef XXX |
---|
873 | color.red = Nint(frac*65535.0); |
---|
874 | color.green = Nint((1-frac)*65535.0); |
---|
875 | color.blue = 0; |
---|
876 | # endif |
---|
877 | color.flags = DoRed | DoGreen | DoBlue; |
---|
878 | if (!XAllocColor(XtDisplay(w),default_cmap,&color)) { |
---|
879 | fprintf( stderr, "%s: error allocating color\n", mmv_pname ); |
---|
880 | exit( 1 ); |
---|
881 | } /*endif*/ |
---|
882 | gc[i] = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
883 | XSetForeground( XtDisplay(w), gc[i], color.pixel ); |
---|
884 | XSetBackground( XtDisplay(w), gc[i], |
---|
885 | WhitePixel(XtDisplay(w),screen_num) ); |
---|
886 | } /*endfor*/ |
---|
887 | |
---|
888 | out_font = XLoadFont( XtDisplay(w), |
---|
889 | "-b&h-lucidatypewriter-bold-r-normal-sans-*-100-*-*-*-*-*-1" ); |
---|
890 | |
---|
891 | i = setup->colnum; |
---|
892 | gc[i] = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
893 | XSetForeground( XtDisplay(w), gc[i], BlackPixel(XtDisplay(w),screen_num) ); |
---|
894 | XSetBackground( XtDisplay(w), gc[i], WhitePixel(XtDisplay(w),screen_num) ); |
---|
895 | XSetFont( XtDisplay(w), gc[i], out_font ); |
---|
896 | |
---|
897 | } /* end of mm_prepare_gc */ |
---|
898 | |
---|
899 | |
---|
900 | |
---|
901 | /*--------------------------------------------------------------------------*/ |
---|
902 | |
---|
903 | |
---|
904 | |
---|
905 | static void mm_display_matrix( Widget w, GC gc[], MmtDSP_SETUP *setup, |
---|
906 | MmtMATRIX *mat, int power ) |
---|
907 | |
---|
908 | /* displays matrix on screen |
---|
909 | * |
---|
910 | * parameters of routine |
---|
911 | * Widget w; input; widget of drawing area |
---|
912 | * GC gc[]; input; GC's |
---|
913 | * MmtDSP_SETUP *setup; input; display setup |
---|
914 | * MmtMATRIX *mat; input; matrix |
---|
915 | * int power; input; power on amplitudes |
---|
916 | */ |
---|
917 | { |
---|
918 | /* local variables */ |
---|
919 | static GC cgc; /* clear GC */ |
---|
920 | static BOOLEAN d_is_init=FALSE; /* GC is initialised */ |
---|
921 | Window root; /* root window */ |
---|
922 | int w_x, w_y; /* position of window */ |
---|
923 | unsigned w_w, w_h; /* size of window */ |
---|
924 | unsigned border; /* border width */ |
---|
925 | unsigned depth; /* depth of window */ |
---|
926 | float rect_width; /* width of rectangle */ |
---|
927 | float rect_height; /* height of rectangle */ |
---|
928 | unsigned i, j; /* counters */ |
---|
929 | float rect_x, rect_y; /* position of rectangle */ |
---|
930 | float frac; /* scratch */ |
---|
931 | unsigned colstep; /* color number */ |
---|
932 | int cmt_x, cmt_y;/* comment position */ |
---|
933 | |
---|
934 | /* executable code */ |
---|
935 | |
---|
936 | XGetGeometry( XtDisplay(w), XtWindow(w), &root, &w_x, &w_y, &w_w, &w_h, |
---|
937 | &border, &depth ); |
---|
938 | |
---|
939 | if (!d_is_init) { |
---|
940 | cgc = XCreateGC( XtDisplay(w), XtWindow(w), 0, NULL ); |
---|
941 | XCopyGC( XtDisplay(w), mmv_gc[mmv_setup.colnum], GCFont, cgc ); |
---|
942 | XSetForeground( XtDisplay(w), cgc, WhitePixel(XtDisplay(w),0) ); |
---|
943 | XSetBackground( XtDisplay(w), cgc, BlackPixel(XtDisplay(w),0) ); |
---|
944 | d_is_init = TRUE; |
---|
945 | } /*endif*/ |
---|
946 | pix_FillRectangle( XtDisplay(w), XtWindow(w), cgc, 0, 0, w_w, w_h ); |
---|
947 | |
---|
948 | /* get width and height of rectangle */ |
---|
949 | rect_width = (float)(w_w-(setup->margin_l)-(setup->margin_r)) |
---|
950 | / (float)(mat->width); |
---|
951 | rect_height = (float)(w_h-(setup->margin_t)-(setup->margin_b)) |
---|
952 | / (float)(mat->height); |
---|
953 | |
---|
954 | cmt_x = setup->margin_l + 50; |
---|
955 | cmt_y = MmcCHARHEIGHT + 3; |
---|
956 | for (i=0; i<mmv_cmtcnt; i++) { |
---|
957 | pix_DrawString( XtDisplay(w), XtWindow(w), gc[setup->colnum], cmt_x, |
---|
958 | cmt_y, mmv_cmt[i], strlen(mmv_cmt[i]) ); |
---|
959 | cmt_y += MmcCHARHEIGHT; |
---|
960 | } /*endfor*/ |
---|
961 | |
---|
962 | for (i=0; i<(mat->height); i++) { |
---|
963 | for (j=0; j<(mat->width); j++) { |
---|
964 | rect_x = (float)j * rect_width; |
---|
965 | rect_y = (float)(mat->height-1-i) * rect_height; |
---|
966 | frac = (mat->val[i][j]-mat->minval) / (mat->maxval-mat->minval); |
---|
967 | if (power == 0) { |
---|
968 | frac = log( 1.0 + (MY_E-1.0)*frac ); |
---|
969 | } else if (power > 1) { |
---|
970 | frac = pow( frac, (float)power ); |
---|
971 | } else if (power < 0) { |
---|
972 | frac = pow( frac, 1.0/(float)(-power+1) ); |
---|
973 | } /*endif*/ |
---|
974 | colstep = Nint( frac * (float)(setup->colnum-1) ); |
---|
975 | pix_FillRectangle( XtDisplay(w), XtWindow(w), gc[colstep], |
---|
976 | Nint(rect_x)+setup->margin_l, Nint(rect_y)+setup->margin_t, |
---|
977 | Nint(rect_width)+1, Nint(rect_height)+1 ); |
---|
978 | } /*endfor*/ |
---|
979 | } /*endfor*/ |
---|
980 | |
---|
981 | mm_draw_labels( w ); |
---|
982 | |
---|
983 | XFlush( XtDisplay(w) ); |
---|
984 | |
---|
985 | } /* end of mm_display_matrix */ |
---|
986 | |
---|
987 | |
---|
988 | |
---|
989 | /*--------------------------------------------------------------------------*/ |
---|
990 | |
---|
991 | |
---|
992 | |
---|
993 | static void mm_change_gc( Widget w, int mode, MmtDSP_SETUP *setup, GC gc[] ) |
---|
994 | |
---|
995 | /* changes gc's to other colors |
---|
996 | * |
---|
997 | * parameters of routine |
---|
998 | * Widget w; input; widget ID |
---|
999 | * int mode; input; which colors |
---|
1000 | * MmtDSP_SETUP *setup; input; setup |
---|
1001 | * GC gc[]; modify; GC's to change |
---|
1002 | */ |
---|
1003 | { |
---|
1004 | /* local variables */ |
---|
1005 | int i; /* counter */ |
---|
1006 | float frac; /* color fraction */ |
---|
1007 | float frac_x; /* scratch */ |
---|
1008 | float c, c1; /* scratch */ |
---|
1009 | XColor color; /* color info */ |
---|
1010 | Colormap default_cmap;/* default colormap */ |
---|
1011 | int screen_num; /* screen number */ |
---|
1012 | |
---|
1013 | /* executable code */ |
---|
1014 | |
---|
1015 | screen_num = 0; |
---|
1016 | |
---|
1017 | default_cmap = DefaultColormap( XtDisplay(w), screen_num ); |
---|
1018 | |
---|
1019 | for (i=0; i<(setup->colnum); i++) { |
---|
1020 | frac = (float)i / (float)((setup->colnum)-1); |
---|
1021 | switch (mode) { |
---|
1022 | case MmcCOLORS_GREEN_RED: |
---|
1023 | color.red = Nint(frac*65535.0); |
---|
1024 | color.green = Nint((1-frac)*65535.0); |
---|
1025 | color.blue = 0; |
---|
1026 | break; |
---|
1027 | case MmcCOLORS_BLUE_RED: |
---|
1028 | color.red = Nint(frac*65535.0); |
---|
1029 | color.green = 0; |
---|
1030 | color.blue = Nint((1-frac)*65535.0); |
---|
1031 | break; |
---|
1032 | case MmcCOLORS_BLUE_YELLOW: |
---|
1033 | #ifdef XXX |
---|
1034 | frac_x = (frac < 0.5) ? 2.0*frac : 1.0; |
---|
1035 | color.red = Nint( frac_x * 65535.0 ); |
---|
1036 | frac_x = (frac > 0.5) ? 2.0*(frac-0.5) : 0.0; |
---|
1037 | color.green = Nint( frac_x * 65535.0 ); |
---|
1038 | frac_x = (frac < 0.5) ? (1.0-2.0*frac) : 0.0; |
---|
1039 | color.blue = Nint( frac_x * 65535.0 ); |
---|
1040 | #endif |
---|
1041 | /* red increases from 0 to c and then stays 1 */ |
---|
1042 | c = 0.5; /*0.4;*/ |
---|
1043 | frac_x = (frac < c) ? frac/c : 1.0; |
---|
1044 | color.red = Nint( frac_x * 65535.0 ); |
---|
1045 | /* green increases from c to 1 and is zero before c */ |
---|
1046 | c = 0.5; |
---|
1047 | frac_x = (frac > c) ? (frac-c)/(1.0-c) : 0.0; |
---|
1048 | color.green = Nint( frac_x * 65535.0 ); |
---|
1049 | /* blue decreases from 1 to 0 between 0 and c and then stays 0 */ |
---|
1050 | c = 0.5; /*0.8;*/ |
---|
1051 | frac_x = (frac < c) ? (1.0-frac/c) : 0.0; |
---|
1052 | color.blue = Nint( frac_x * 65535.0 ); |
---|
1053 | break; |
---|
1054 | default: |
---|
1055 | color.red = Nint((1-frac)*65535.0); |
---|
1056 | color.green = color.blue = color.red; |
---|
1057 | break; |
---|
1058 | } /*endswitch*/ |
---|
1059 | color.flags = DoRed | DoGreen | DoBlue; |
---|
1060 | if (!XAllocColor(XtDisplay(w),default_cmap,&color)) { |
---|
1061 | fprintf( stderr, "%s: error allocating color\n", mmv_pname ); |
---|
1062 | exit( 1 ); |
---|
1063 | } /*endif*/ |
---|
1064 | XSetForeground( XtDisplay(w), gc[i], color.pixel ); |
---|
1065 | XSetBackground( XtDisplay(w), gc[i], |
---|
1066 | WhitePixel(XtDisplay(w),screen_num) ); |
---|
1067 | } /*endfor*/ |
---|
1068 | |
---|
1069 | } /* end of mm_change_gc */ |
---|
1070 | |
---|
1071 | |
---|
1072 | |
---|
1073 | /*--------------------------------------------------------------------------*/ |
---|