NLSL: pltx.c Source File

NLSL

- Main Page
- Modules
- Data Types List
- Files

- File List
- File Members

pltx.c
Go to the documentation of this file.
1 /* Pltx.c is an XWindows application capable of handling several
2 independant windows and their contents simultaneously. Each
3 window contains a plot of two spectra (experimental and simulated).
4 A line representing the difference of these two spectra can also
5 be plotted, plus an axes box (without labels) drawn enclosing
6 the plot.
7
8 While running, the function will perform certain operations on the
9 plotted data in each window as follows:
10
11 KEYSTROKE OPERATIONS:
12
13 "a": Turns the axes box on or off, switch-fashion.
14
15 "o": Displays the graphs of the two arrays sent to the function,
16 the original plot. The simulation curve is shown in green,
17 the experimental in orange.
18
19 "d": Displays the curve that represents the difference between
20 the simulation and the difference. Shown in magenta.
21
22 "s": Displays the simulation curve only.
23
24 "e": Displays the experimental curve only.
25
26 "b": Displays all three curves.
27
28 "q": Exits the function and returns to the calling program.
29
30 MOUSE-BUTTON PRESSES:
31
32 Right button: When pressed, the rightheand mouse button will highlight
33 a pixel point and display the data coordinates (x, y).
34
35 Left button: When pressed, moved, and released, the lefthand mouse
36 button will highlight the pixel points at the spots where the
37 button was pressed and released, and will display the difference
38 between the two points (x, y).
39
40 The function will also automatically rescale the data if the
41 window size is changed.
42
43 Written by Diane Crepeau
44 MODIFIED by David Budil 2/8/93 */
45
46 /* Structure definitions */
47
48 #include <X11/Xlib.h>
49 #include <X11/Xutil.h>
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53 #include "fortrancall.h"
54
55 #define MAX_WINDOWS 5
56
57 struct wstruct /* Structure to contain window information */
58 {
59 Display *dspy; /* Connection between workstation and window */
60 Drawable wndw; /* Window ID */
61 GC gc, gc1, gc2, gc3; /* Graphics context IDs */
62 Colormap map; /* Window colormap */
63 XPoint xye[4096], xys[4096], ydif[4096]; /* Pixel arrays */
64 float ye[4096], ys[4096]; /* Data arrays associated with the window */
65 float xmin, xmax, xstep, ymin, ymax; /* Minima, maxima, and X step size */
66 int indx; /* Number of data points in arrays */
67 int scrn; /* Screen number */
68 int mode; /* Plotting mode, origin is corner of screen */
69 unsigned int fgnd, bgnd; /* Default foregraound and background */
70 int flag, flag2; /* Flags determining which spectra to plot */
71 int yzer; /* Pixel y-coordinate of zero data value */
72 int nx, ny; /* Dimensions of window in pixels */
73 float er, el, et, eb; /* Fractions of screen for edges (blank) */
74 int led, red, bed, ted; /* Pixel coordinates of window inner edges */
75 };
76
77 struct xarry /* Structure for linked list of x-values */
78 {
79 float x; /* Data value */
80 struct xarry *next; /* Pointer to next 'node' in list */
81 };
82
83 typedef char word[20]; /* Defined sting type word */
84
85 /* Global variable declarations */
86 struct wstruct wds[MAX_WINDOWS + 1]; /* Maximum 5 windows */
87 int numwndws = 0; /* Initialize number of windows to 0 */
88 int done = 0; /* Initialize "done" to "not done" */
89 int displayOK = 0; /* Variable to keep wpoll from attempting to
90 check events for nonexistant windows */
91
92 /********************************/
93 /* Function findzero */
94 /* Calculates pixel value for '0' data value */
95 int
96 findzero (wn, ymax, ymin)
97 float ymax, ymin; /* Max and min for calculating value */
98 int wn; /* Window number */
99 { /* Begin findzero */
100 int yzer1; /* yzer contains the pixel y-coordinate of the
101 data value closest to zero, i is the loop
102 control index */
103
104 yzer1 = (wds[wn].ny * (1 - wds[wn].eb) - wds[wn].ny * wds[wn].et) /
105 (ymin - ymax) * (-ymax) + (wds[wn].ny * wds[wn].et);
106 /* Calculate zero pixel value */
107
108 return yzer1; /* Return pixel coordinate of zero */
109
110 } /* End findzero */
111
112 /********************************/
113 /* Function drawln */
114 /* Accesses external variables to draw spectra in window */
115 void
116 drawln (int wn) /* wn=Window number */
117 { /* Begin drawln */
118 /* Access variables needed */
119 XClearWindow (wds[wn].dspy, wds[wn].wndw); /* Clear window */
120
121 if (wds[wn].flag2 == 1) /* Check flag2 for axes on or off */
122 { /* Begin if */
123 XDrawLine (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, wds[wn].led,
124 wds[wn].ted, wds[wn].red, wds[wn].ted);
125 XDrawLine (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, wds[wn].led,
126 wds[wn].bed, wds[wn].red, wds[wn].bed);
127 XDrawLine (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, wds[wn].led,
128 wds[wn].ted, wds[wn].led, wds[wn].bed);
129 XDrawLine (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, wds[wn].red,
130 wds[wn].ted, wds[wn].red, wds[wn].bed);
131 XDrawLine (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, wds[wn].led,
132 wds[wn].yzer, wds[wn].red, wds[wn].yzer);
133 } /* End if */
134
135 switch (wds[wn].flag) /* Check which spectrum to draw */
136 { /* Begin switch */
137 case 0: /* Draw experimental and simulated spectra */
138 XDrawLines (wds[wn].dspy, wds[wn].wndw, wds[wn].gc1, wds[wn].xye,
139 wds[wn].indx, wds[wn].mode);
140 XDrawLines (wds[wn].dspy, wds[wn].wndw, wds[wn].gc2, wds[wn].xys,
141 wds[wn].indx, wds[wn].mode);
142 break;
143 case 1: /* Draw difference line */
144 XDrawLines (wds[wn].dspy, wds[wn].wndw, wds[wn].gc3, wds[wn].ydif,
145 wds[wn].indx, wds[wn].mode);
146 break;
147 case 2: /* Draw all three spectra */
148 XDrawLines (wds[wn].dspy, wds[wn].wndw, wds[wn].gc1, wds[wn].xye,
149 wds[wn].indx, wds[wn].mode);
150 XDrawLines (wds[wn].dspy, wds[wn].wndw, wds[wn].gc2, wds[wn].xys,
151 wds[wn].indx, wds[wn].mode);
152 XDrawLines (wds[wn].dspy, wds[wn].wndw, wds[wn].gc3, wds[wn].ydif,
153 wds[wn].indx, wds[wn].mode);
154 break;
155 case 3: /* Draw experimental spectrum */
156 XDrawLines (wds[wn].dspy, wds[wn].wndw, wds[wn].gc1, wds[wn].xye,
157 wds[wn].indx, wds[wn].mode);
158 break;
159 case 4: /* Draw simulated spectrum */
160 XDrawLines (wds[wn].dspy, wds[wn].wndw, wds[wn].gc2, wds[wn].xys,
161 wds[wn].indx, wds[wn].mode);
162 break;
163 } /* End switch */
164 XFlush (wds[wn].dspy); /* Clear event queue */
165
166 } /* End drawln */
167
168 /********************************/
169 /* Function xnew */
170 /* Dynamically allocates space for the next node of the linked
171 list, initializes the values to zero, and returns a pointer
172 to the new node. */
173 struct xarry *
174 xnew (struct xarry *list)
175 { /* Begin xnew */
176 list = (struct xarry *) malloc (sizeof (struct xarry));
177 /* Allocate new node */
178 list->x = 0.0f; /* Set internal values to zero */
179 list->next = NULL; /* Set next pointer to end of list */
180 return list; /* Return pointer to calling function */
181
182 } /* End xnew */
183
184 /********************************/
185 void
186 xdump (struct xarry *list)
187 { /* Begin xdump */
188 struct xarry *ptr;
189
190 while (list != NULL)
191 {
192 ptr = list;
193 list = list->next;
194 free (ptr);
195 }
196 } /* End xdump */
197
198 /********************************/
199 /* Function findmin */
200 /* Searches array for smallest value */
201 float
202 findmin (float *ary, int indx)
203 { /* Begin findmin */
204 float min; /* Minimum */
205 int i; /* Loop index */
206
207 min = ary[0]; /* Initialize min */
208
209 for (i = 1; i < indx; i++) /* Loop control */
210 { /* Begin for */
211 if (min > ary[i]) /* Compare min with next array value */
212 min = ary[i]; /* Assign smallest value to min */
213 } /* End for */
214
215 return min; /* Return smallest value in array */
216 } /* End findmin */
217
218 /********************************/
219 /* Function findmax */
220 /* Searches array for largest value */
221 float
222 findmax (float *ary, int indx)
223 { /* Begin findmax */
224 float max; /* Maximum */
225 int i; /* Loop index */
226
227 max = ary[0]; /* Initialize max */
228
229 for (i = 1; i < indx; i++) /* Loop control */
230 { /* Begin for */
231 if (max < ary[i]) /* Compare max with next array value */
232 max = ary[i]; /* Assign largest to max */
233 } /* End for */
234
235 return max; /* Return largest value in array */
236
237 } /* End findmax */
238
239 /********************************/
240 /* Function differnce */
241
242 /*** Calculates difference spectrum pixel values
243 given pixel values for the data and experimental curves ***/
244
245 void
246 differnce (XPoint * xy1, XPoint * xy2, int indx, XPoint * ydif, int yzer)
247 /* XPoint *xy1, *xy2, *ydif; Pixel arrays to calculate with
248 int indx, yzer; Array index and zero coordinate */
249 { /* Begin differnce */
250 int i; /* Loop index */
251
252 for (i = 0; i < indx; ++i) /* Loop control */
253 { /* Begin for */
254 ydif[i].x = xy1[i].x; /* Set x-coordinates the same */
255 ydif[i].y = (xy1[i].y - xy2[i].y) + yzer;
256 /* Set y-coordinates by taking difference of
257 xy1 and xy2 and adding zero coordinate */
258 } /* End for */
259
260 } /* End differnce */
261
262 /********************************/
263 /* Function pixary */
264 /* Translates data array into pixel array */
265 void
266 pixary (float *y, float min, float step, int n, XPoint * xy, float ymax,
267 float ymin, int wn)
268 /* XPoint *xy; Pixel coordinate array to fill
269 float *y, min, step, ymax, ymin;
270 Y-array,x-values,and y-maximum and minimum
271 int n, wn; Index to arrays, window number */
272 { /* Begin pixary */
273 int i = 0, xer, xel, yet, yeb; /* "For" loop index */
274 float xmin, temp; /* X minimum,and temp holding variable */
275 struct xarry *xlist, *list; /* 2 linked list pointers to a list for x */
276
277 /* Assign values to xer, xel, yet, and yeb */
278 xer = wds[wn].nx * (1 - wds[wn].er); /* Right edge coordinate */
279 xel = wds[wn].nx * wds[wn].el; /* Left edge coordinate */
280 yet = wds[wn].ny * wds[wn].et; /* Top edge coordinate */
281 yeb = wds[wn].ny * (1 - wds[wn].eb); /* Bottom edge coordinate */
282
283 /* translate min, step, and n into array of X values */
284 xlist = xnew (xlist); /* Initialize xlist with new node */
285 list = xlist; /* Set list to indicate same node */
286
287 for (i = 0; i <= n; i++) /* Loop control */
288 { /* Begin for */
289 (*list).x = min + (i * step); /* Calculate next x and assign to list */
290 temp = (*list).x; /* Set temp to the newest x value */
291 (*list).next = xnew ((*list).next); /* Get new node in list */
292 list = (*list).next; /* Increment list to point to new node */
293 } /* End for */
294
295 wds[wn].xmax = temp; /* Assign highest x value to xmax */
296 xmin = (*xlist).x; /* Assign 1st value in linked list to xmin */
297 i = 0; /* Re-initialize i */
298 list = xlist; /* Reset list to beginning of linked list */
299
300 /* loop translates 2 data arrays into 1 */
301 while (xlist != NULL) /* Loop control */
302 { /* Begin while */
303 xy[i].x =
304 ((xer - xel) / (wds[wn].xmax - xmin)) * ((*xlist).x - xmin) + xel;
305 /* Calculate x-coordinate */
306 xy[i].y = (yeb - yet) / (ymin - ymax) * (y[i] - ymax) + yet;
307 /* Calculate y-coordinate */
308 xlist = (*xlist).next; /* Increment list pointer to next node */
309 ++i; /* Increment loop index */
310 } /* End while */
311 xdump (xlist);
312
313 } /* End pixary */
314
315 /********************************/
316 /* Function calcul */
317 /* Calls other functions to calculate the pixel values from the
318 data arrays, adjust for vertical offset, and calculate the
319 difference between them */
320 void
321 calcul (int wn) /* wn=window number */
322 { /* Begin calcul */
323 float y1max, y1min, y2max, y2min;
324 /* Y array maxima and minima */
325
326 y1max = findmax (wds[wn].ye, wds[wn].indx); /* Get maximum value of y1 array */
327 y2max = findmax (wds[wn].ys, wds[wn].indx); /* Get maximum value of y2 array */
328 y1min = findmin (wds[wn].ye, wds[wn].indx); /* Get minimum value of y1 array */
329 y2min = findmin (wds[wn].ys, wds[wn].indx); /* Get minimum value of y2 array */
330
331 wds[wn].ymax = (y1max > y2max) ? y1max : y2max;
332 wds[wn].ymin = (y1min < y2min) ? y1min : y2min;
333
334 pixary (wds[wn].ye, wds[wn].xmin, wds[wn].xstep, wds[wn].indx,
335 wds[wn].xye, wds[wn].ymax, wds[wn].ymin, wn);
336 /* Calculate pixel coordinates for y1 */
337 pixary (wds[wn].ys, wds[wn].xmin, wds[wn].xstep, wds[wn].indx,
338 wds[wn].xys, wds[wn].ymax, wds[wn].ymin, wn);
339 /* Calculate pixel coordinates for y1 */
340
341 wds[wn].yzer = findzero (wn, wds[wn].ymax, wds[wn].ymin);
342 /* Get zero coordinate for y1 */
343
344 differnce (wds[wn].xye, wds[wn].xys, wds[wn].indx, wds[wn].ydif,
345 wds[wn].yzer);
346 /* Calculate difference curve */
347 } /* End calcul */
348
349 /********************************/
350 void
351 calcpt (int xpt, int ypt, float *xpt1, float *ypt1, int wn)
352 { /* Begin calcpt */
353 int xer, xel, yet, yeb; /* Edge-of-plot coordinate variables */
354
355 /* Assign values to xer, xel, yet, and yeb */
356 xer = wds[wn].nx * (1 - wds[wn].er); /* Right edge coordinate */
357 xel = wds[wn].nx * wds[wn].el; /* Left edge coordinate */
358 yet = wds[wn].ny * wds[wn].et; /* Top edge coordinate */
359 yeb = wds[wn].ny * (1 - wds[wn].eb); /* Bottom edge coordinate */
360
361 *xpt1 =
362 ((wds[wn].xmax - wds[wn].xmin) / (xer - xel)) * (xpt - xel) +
363 wds[wn].xmin;
364 /* Calculate X data value of pixel coord. */
365 *ypt1 =
366 ((wds[wn].ymax - wds[wn].ymin) / (yet - yeb) * (ypt - yet) +
367 wds[wn].ymax);
368 /* Calculate Y data value of pixel coord. */
369 } /* End calcpt */
370
371 /********************************/
372 void
373 setxpts (XPoint * xypts, int xpt, int ypt)
374 { /* Begin setxpts */
375 xypts[0].x = xpt;
376 xypts[0].y = ypt;
377 xypts[1].x = xpt;
378 xypts[1].y = ypt + 1;
379 xypts[2].x = xpt;
380 xypts[2].y = ypt - 1;
381 xypts[3].x = xpt + 1;
382 xypts[3].y = ypt;
383 xypts[4].x = xpt - 1;
384 xypts[4].y = ypt;
385 } /* End setxpts */
386
387 /********************************/
388 void
389 getstr (char *pltstr, float xpt, float ypt)
390 { /* Begin getstr */
391 char cxstr[10], cystr[10];
392
393 sprintf (cxstr, "%0.2f", xpt);
394 sprintf (cystr, "%0.2e", ypt);
395
396 strcpy (pltstr, "( ");
397 strcat (pltstr, cxstr);
398 strcat (pltstr, ", ");
399 strcat (pltstr, cystr);
400 strcat (pltstr, " ) ");
401 } /* End getstr */
402
403 /********************************/
404 void
405 doevnt (int wn)
406 { /* Begin doevnt */
407 /* declarations */
408 XEvent myevent;
409 KeySym mykey;
410 XWindowAttributes myattribs;
411 char txt[10];
412 int i;
413 float xpt1, xpt2, xptd, ypt1, ypt2, yptd;
414 int xpt, xptr, ypt, yptr, xlow, ylow;
415 XPoint pts1[5], pts2[5];
416 char cpltstr[34];
417
418 XNextEvent (wds[wn].dspy, &myevent); /* read the next event */
419
420 switch (myevent.type) /* Determine type of event */
421 { /* Begin switch */
422
423 /* Repaint window on expose events */
424 case Expose: /* moved, resized, uncovered etc. window */
425 if (myevent.xexpose.count == 0)
426 { /* Begin if */
427 XGetWindowAttributes (wds[wn].dspy, wds[wn].wndw, &myattribs);
428 /* Get information about window configuration */
429 wds[wn].ny = myattribs.height; /* Set ny to window height in pixels */
430 wds[wn].nx = myattribs.width; /* Set nx to window width in pixels */
431
432 calcul (wn);
433 /* Call calcul to fill pixel arrays */
434 wds[wn].led = wds[wn].nx * wds[wn].el;
435 /* Set left edge */
436 wds[wn].red = wds[wn].nx - (wds[wn].nx * wds[wn].er);
437 /* Set right edge */
438 wds[wn].ted = wds[wn].ny * wds[wn].et;
439 /* Set top edge */
440 wds[wn].bed = wds[wn].ny - (wds[wn].ny * wds[wn].eb);
441 /* Set bottom edge */
442 drawln (wn); /* Call drawln to plot spectra */
443 } /* End if */
444 break; /* End case Expose */
445
446 /* Process keyboard mapping changes */
447 case MappingNotify: /* changes in layout of windows on screen */
448 XRefreshKeyboardMapping ((XMappingEvent *) & myevent); /* make necessary changes */
449 break; /* End case MappingNotify */
450
451 /* Process mouse-button presses */
452 case ButtonPress: /* any mouse-button pressed */
453 drawln (wn);
454 if (myevent.xbutton.button == 1)
455 {
456 xpt = myevent.xbutton.x;
457 ypt = myevent.xbutton.y;
458
459 calcpt (xpt, ypt, &xpt1, &ypt1, wn);
460 setxpts (pts1, xpt, ypt);
461
462 XDrawPoints (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, pts1, 5,
463 wds[wn].mode);
464 }
465 if (myevent.xbutton.button == 3)
466 {
467 xpt = myevent.xbutton.x;
468 ypt = myevent.xbutton.y;
469
470 calcpt (xpt, ypt, &xpt1, &ypt1, wn);
471 setxpts (pts1, xpt, ypt);
472
473 getstr (cpltstr, xpt1, ypt1);
474
475 XDrawPoints (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, pts1, 5,
476 wds[wn].mode);
477 if ((xpt + (strlen (cpltstr) * 6)) < wds[wn].nx)
478 /* Doesn't overlap right edge */
479 XDrawString (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, xpt + 6,
480 ypt + 3, cpltstr, strlen (cpltstr));
481 else if ((xpt - (strlen (cpltstr) * 6)) > 0)
482 {
483 XDrawString (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, xpt -
484 (strlen (cpltstr) * 6) + 6, ypt + 3, cpltstr,
485 strlen (cpltstr));
486 }
487 else if ((ypt + 10) > wds[wn].ny)
488 {
489 XDrawString (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, xpt -
490 (strlen (cpltstr) * 6) / 2 + 6,
491 ypt + 10, cpltstr, strlen (cpltstr));
492 }
493 else
494 {
495 XDrawString (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, xpt -
496 (strlen (cpltstr) * 6) / 2 + 6,
497 ypt - 10, cpltstr, strlen (cpltstr));
498 }
499 }
500 break; /* End case ButtonPress */
501
502 case ButtonRelease: /* any mouse-button released */
503 if (myevent.xbutton.button == 1)
504 {
505 xptr = myevent.xbutton.x;
506 yptr = myevent.xbutton.y;
507
508 xlow = (xpt - xptr) / 2 + xptr;
509 ylow = (ypt - yptr) / 2 + yptr;
510
511 calcpt (xptr, yptr, &xpt2, &ypt2, wn);
512 setxpts (pts2, xptr, yptr);
513
514 xptd = xpt1 - xpt2;
515 yptd = ypt1 - ypt2;
516
517 getstr (cpltstr, xptd, yptd);
518
519 XDrawPoints (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, pts2, 5,
520 wds[wn].mode);
521
522 if ((xlow + 250) < wds[wn].nx)
523 XDrawString (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, xlow + 6,
524 ylow + 3, cpltstr, strlen (cpltstr));
525 else if ((xlow - 250) > 0)
526 XDrawString (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, xlow -
527 (strlen (cpltstr) * 6) + 6,
528 ylow + 3, cpltstr, strlen (cpltstr));
529 else if ((ylow + 10) > wds[wn].ny)
530 XDrawString (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, xlow -
531 (strlen (cpltstr) * 6) / 2 + 6,
532 ylow + 10, cpltstr, strlen (cpltstr));
533 else
534 XDrawString (wds[wn].dspy, wds[wn].wndw, wds[wn].gc, xlow -
535 (strlen (cpltstr) * 6) / 2 + 6,
536 ylow - 10, cpltstr, strlen (cpltstr));
537 }
538 break;
539
540 /* Process keyboard input */
541 case KeyPress: /* any key pressed */
542 i = XLookupString ((XKeyEvent *) & myevent, txt, 10, &mykey, 0); /* get i and txt */
543 if (i == 1) /* number of characters returned equals 1 */
544 { /* Begin if */
545
546 switch (txt[0]) /* Determine key pressed */
547 { /* Begin switch */
548
549 case 'q': /* Lowercase 'q' pressed */
550 done = 1; /* End of loop */
551 break; /* End case 'q' */
552
553 case 'o': /* Lowercase 'o' pressed */
554 wds[wn].flag = 0; /* Flag set to 'original 2 spectra' */
555 break; /* End case 'o' */
556
557 case 'd': /* Lowercase 'd' pressed */
558 wds[wn].flag = 1; /* Flag set to 'difference spectrum' */
559 break; /* End case 'd' */
560
561 case 'b': /* Lowercase 'b' pressed */
562 wds[wn].flag = 2; /* Flag set to 'all three spectra' */
563 break; /* End case 'b' */
564
565 case 'e': /* Lowercase 'e' pressed */
566 wds[wn].flag = 3; /* Flag set to 'exp. spectrum only' */
567 break; /* End case 'e' */
568
569 case 's': /* Lowercase 's' pressed */
570 wds[wn].flag = 4; /* Flag set to 'sim. spectrum only' */
571 break; /* End case 's' */
572
573 case 'a': /* Lowercase 'a' pressed */
574 wds[wn].flag2 = wds[wn].flag2 * -1; /* Switch flag2 off or on */
575 break; /* End case 'a' */
576
577 } /* End switch (txt[0]) */
578
579 drawln (wn); /* Redraw spectra */
580 } /* End if */
581
582 break; /* End case KeyPress */
583
584 } /* End switch (myevent.type) */
585 XFlush (wds[wn].dspy);
586 } /* End doevnt */
587
588 /********************************/
589 void FORTRAN (getwndws) (int *n, word * title)
590 { /* Begin getwndws */
591 /* declarations */
592 XSizeHints myhint;
593 XColor orng, grn, mgnt, blk, wht;
594 Font myfont;
595 Status resultb, resultba, resultw, resultwa;
596 Status result1a, result1, result2a;
597 Status result2, result3a, result3;
598 char *name1, *name2, *name3, *nameb, *namew;
599 int wn;
600
601 if (getenv ("DISPLAY"))
602 displayOK = 1;
603 if (!displayOK)
604 return;
605
606 if (*n != 0)
607 { /* Begin if */
608
609 /* Clear windows from screen */
610 for (wn = 1; wn <= numwndws; ++wn)
611 { /* Begin for */
612 XFreeGC (wds[wn].dspy, wds[wn].gc); /* Explicitly deallocates mygc */
613 XFreeGC (wds[wn].dspy, wds[wn].gc1); /* Explicitly deallocates mygc1 */
614 XFreeGC (wds[wn].dspy, wds[wn].gc2); /* Explicitly deallocates mygc2 */
615 XFreeGC (wds[wn].dspy, wds[wn].gc3); /* Explicitly deallocates mygc3 */
616 XDestroyWindow (wds[wn].dspy, wds[wn].wndw);
617 XCloseDisplay (wds[wn].dspy);
618 } /* End for */
619
620 numwndws = *n;
621
622 #ifdef DEBUG
623 printf ("Numwndws = %d\n", numwndws);
624 #endif
625
626 for (wn = 1; wn <= numwndws; ++wn)
627 { /* Begin for */
628 /* Initialization */
629 wds[wn].dspy = XOpenDisplay (""); /* Open display connection */
630 wds[wn].scrn = DefaultScreen (wds[wn].dspy); /* Get default screen */
631 wds[wn].map = XDefaultColormap (wds[wn].dspy, wds[wn].scrn);
632 /* Get colormap ID */
633 wds[wn].mode = CoordModeOrigin;
634
635 #ifdef DEBUG
636 printf ("Getwndws: Wds[%d].dspy = %d\n", wn, wds[wn].dspy);
637 #endif
638
639 /* Set default program-specified window position and size */
640 #if 0
641 myhint.x = 650;
642 myhint.y = (wn - 1) * 400;
643 myhint.width = 500;
644 myhint.height = 400;
645 #endif
646 myhint.x = (wn - 1) * 400;
647 myhint.y = 0;
648 myhint.width = 400;
649 myhint.height = 300;
650 myhint.flags = PPosition | PSize;
651
652 /* Create window with properties set in myhint */
653 wds[wn].wndw = XCreateSimpleWindow (wds[wn].dspy,
654 DefaultRootWindow (wds[wn].
655 dspy),
656 myhint.x, myhint.y,
657 myhint.width, myhint.height, 5,
658 wds[wn].fgnd, wds[wn].bgnd);
659 XSetStandardProperties (wds[wn].dspy, wds[wn].wndw, title[wn - 1],
660 title[wn - 1], None, NULL, 0, &myhint);
661
662 /* Set name variables to color names */
663 name1 = "orange";
664 name2 = "green";
665 name3 = "magenta";
666 nameb = "black";
667 namew = "white";
668
669 /* Find color values */
670 result1 = XParseColor (wds[wn].dspy, wds[wn].map, name1, &orng);
671 result2 = XParseColor (wds[wn].dspy, wds[wn].map, name2, &grn);
672 result3 = XParseColor (wds[wn].dspy, wds[wn].map, name3, &mgnt);
673 resultb = XParseColor (wds[wn].dspy, wds[wn].map, nameb, &blk);
674 resultw = XParseColor (wds[wn].dspy, wds[wn].map, namew, &wht);
675
676 /* Allocate color cells */
677 result1a = XAllocColor (wds[wn].dspy, wds[wn].map, &orng);
678 result2a = XAllocColor (wds[wn].dspy, wds[wn].map, &grn);
679 result3a = XAllocColor (wds[wn].dspy, wds[wn].map, &mgnt);
680 resultba = XAllocColor (wds[wn].dspy, wds[wn].map, &blk);
681 resultwa = XAllocColor (wds[wn].dspy, wds[wn].map, &wht);
682
683 /* Access apropriate font for strings */
684 myfont = XLoadFont (wds[wn].dspy, "6x13");
685
686 /* GC creation and initialization */
687 /* Set GC for axes */
688 wds[wn].gc = XCreateGC (wds[wn].dspy, wds[wn].wndw, 0, 0);
689 /* Create GC mygc */
690 XSetBackground (wds[wn].dspy, wds[wn].gc, blk.pixel);
691 /* Set background to black */
692 XSetForeground (wds[wn].dspy, wds[wn].gc, wht.pixel);
693 /* Set foreground to white */
694 XSetFont (wds[wn].dspy, wds[wn].gc, myfont);
695 /* Set font */
696
697 /* Set GC for experimental spectrum */
698 if ((result1 != 0) && (result1a != 0)) /* Check if colors were
699 successfully allocated */
700 { /* Begin if */
701 wds[wn].gc1 = XCreateGC (wds[wn].dspy, wds[wn].wndw, 0, 0);
702 /* Create GC mygc1 */
703 XSetBackground (wds[wn].dspy, wds[wn].gc1, blk.pixel);
704 /* Set background to black */
705 XSetForeground (wds[wn].dspy, wds[wn].gc1, orng.pixel);
706 /* Set foreground to orange */
707 } /* End if */
708 else
709 { /* Begin else */
710 wds[wn].gc1 = XCreateGC (wds[wn].dspy, wds[wn].wndw, 0, 0);
711 /* Create GC mygc1 */
712 XSetBackground (wds[wn].dspy, wds[wn].gc1, blk.pixel);
713 /* Set background to black */
714 XSetForeground (wds[wn].dspy, wds[wn].gc1, wht.pixel);
715 /* Set foreground to white */
716 } /* End else */
717
718 /* Set GC for simulated spectrum */
719 if ((result2 != 0) && (result2a != 0))
720 { /* Begin if */
721 wds[wn].gc2 = XCreateGC (wds[wn].dspy, wds[wn].wndw, 0, 0);
722 /* Create GC mygc2 */
723 XSetBackground (wds[wn].dspy, wds[wn].gc2, blk.pixel);
724 /* Set background to black */
725 XSetForeground (wds[wn].dspy, wds[wn].gc2, grn.pixel);
726 /* Set foreground to green */
727 } /* End if */
728 else
729 { /* Begin else */
730 wds[wn].gc2 = XCreateGC (wds[wn].dspy, wds[wn].wndw, 0, 0);
731 /* Create GC mygc2 */
732 XSetBackground (wds[wn].dspy, wds[wn].gc2, blk.pixel);
733 /* Set background to black */
734 XSetForeground (wds[wn].dspy, wds[wn].gc2, wht.pixel);
735 /* Set foreground to white */
736 } /* End else */
737
738 /* Set GC for difference graph */
739 if ((result3 != 0) && (result3a != 0))
740 { /* Begin if */
741 wds[wn].gc3 = XCreateGC (wds[wn].dspy, wds[wn].wndw, 0, 0);
742 /* Create GC mygc3 */
743 XSetBackground (wds[wn].dspy, wds[wn].gc3, blk.pixel);
744 /* Set background to black */
745 XSetForeground (wds[wn].dspy, wds[wn].gc3, mgnt.pixel);
746 /* Set foreground to magenta */
747 } /* End if */
748 else
749 { /* Begin else */
750 wds[wn].gc3 = XCreateGC (wds[wn].dspy, wds[wn].wndw, 0, 0);
751 /* Create GC mygc3 */
752 XSetBackground (wds[wn].dspy, wds[wn].gc3, blk.pixel);
753 /* Set background to black */
754 XSetForeground (wds[wn].dspy, wds[wn].gc3, wht.pixel);
755 /* Set foreground to white */
756 } /* End else */
757
758 /* input event selection */
759 XSelectInput (wds[wn].dspy, wds[wn].wndw,
760 /* Accept key or mouse button presses */
761 /* or window exposures as event types */
762 ButtonPressMask | ButtonReleaseMask |
763 OwnerGrabButtonMask | KeyPressMask | ExposureMask);
764
765 /* window mapping */
766 XMapRaised (wds[wn].dspy, wds[wn].wndw);
767 /* Map window "above" existing windows */
768
769 /* Initialize external variables */
770 wds[wn].er = 0.1; /* Set right edge to be .1 of window */
771 wds[wn].el = 0.1; /* Set left edge to be .1 of window */
772 wds[wn].et = 0.1; /* Set top edge to be .1 of window */
773 wds[wn].eb = 0.1; /* Set bottom edge to be .1 of window */
774
775 /* Initialize indx and flags */
776 wds[wn].flag = 0; /* Set spectra-to-plot to "original" */
777 wds[wn].flag2 = 1; /* Set axes to "on" */
778
779 #ifdef DEBUG
780 printf ("Getwndws: End of for, wds[%d].dspy = %d\n", wn,
781 wds[wn].dspy);
782 #endif
783 } /* End for */
784 } /* End if */
785 } /* End getwndws */
786
787 /********************************/
788
789 /* NOTE: Modified by DEB to accept experimental spectrum in y1
790 and difference spectrum (simulated - experimental) in y2
791 */
792 void
793 putary (double *y1, double *y2, int wn)
794 { /* Begin putary */
795 int i;
796
797 for (i = 0; i < wds[wn].indx; ++i)
798 {
799 wds[wn].ye[i] = y1[i];
800 wds[wn].ys[i] = (y1[i] - y2[i]);
801 }
802 } /* End putary */
803
804 /********************************/
805 void FORTRAN (fstplt) (double *y1, double *y2, double *xmin1,
806 double *xstep1, int *indx1, int *wnum)
807 /* double *y1, *y2; y1 is the experimental, y2 is the
808 double *xmin1, *xstep1; difference (experimental-simulated)
809 int *indx1, *wnum; */
810 { /* Begin fstplt */
811 /* declarations */
812 XWindowAttributes myattribs;
813 int wn;
814
815 #ifdef DEBUG
816 printf ("Wnum = %d\n", *wnum);
817 printf ("Fstplt: Before setting variables to parameters\n");
818 #endif
819 if (!displayOK)
820 return;
821 wn = *wnum;
822
823 #ifdef DEBUG
824 printf ("After wn, wn = %d, before indx\n", wn);
825 #endif
826 wds[wn].indx = *indx1; /* Set global indx to equal parameter indx1 */
827
828 #ifdef DEBUG
829 printf ("After indx, before xmin\n");
830 #endif
831 wds[wn].xmin = *xmin1;
832
833 #ifdef DEBUG
834 printf ("After xmin, before xstep\n");
835 #endif
836 wds[wn].xstep = *xstep1;
837
838 #ifdef DEBUG
839 printf ("Before XGetWindowAttributes, dspy = %d, wndw = %d\n",
840 wds[wn].dspy, wds[wn].wndw);
841 #endif
842
843 XGetWindowAttributes (wds[wn].dspy, wds[wn].wndw, &myattribs);
844 /* Get information about window configuration */
845
846 wds[wn].ny = myattribs.height; /* Set ny to window height in pixels */
847 wds[wn].nx = myattribs.width; /* Set nx to window width in pixels */
848
849 putary (y1, y2, wn);
850 calcul (wn); /* Call calcul to fill pixel arrays */
851
852 wds[wn].led = wds[wn].nx * wds[wn].el; /* Set left edge */
853 wds[wn].red = wds[wn].nx - (wds[wn].nx * wds[wn].er); /* Set right edge */
854 wds[wn].ted = wds[wn].ny * wds[wn].et; /* Set top edge */
855 wds[wn].bed = wds[wn].ny - (wds[wn].ny * wds[wn].eb); /* Set bottom edge */
856 drawln (wn); /* Call drawln to plot spectra */
857 } /* End fstplt */
858
859 /********************************/
860 void FORTRAN (wpoll) ()
861 { /* Begin wpoll */
862 int wn;
863
864 if (displayOK == 1)
865 {
866 for (wn = 1; wn <= numwndws; ++wn)
867 {
868 while (XEventsQueued (wds[wn].dspy, QueuedAfterReading) > 0)
869 doevnt (wn);
870 }
871 }
872 } /* End wpoll */
873
874 /********************************/
875 void FORTRAN (shtwndws) ()
876 { /* Begin shtwndws */
877 /* declarations */
878 int wn;
879 if (displayOK)
880 {
881 for (wn = 1; wn <= numwndws; ++wn)
882 {
883 /* Terminate window */
884 XFreeGC (wds[wn].dspy, wds[wn].gc); /* Explicitly deallocates mygc */
885 XFreeGC (wds[wn].dspy, wds[wn].gc1); /* Explicitly deallocates mygc1 */
886 XFreeGC (wds[wn].dspy, wds[wn].gc2); /* Explicitly deallocates mygc2 */
887 XFreeGC (wds[wn].dspy, wds[wn].gc3); /* Explicitly deallocates mygc3 */
888 XDestroyWindow (wds[wn].dspy, wds[wn].wndw);
889 XCloseDisplay (wds[wn].dspy);
890 }
891 numwndws = 0;
892 }
893 } /* End shtwndws */
894
895 /********************************/
displayOK
int displayOK
Definition: pltx.c:89
wstruct::ymax
float ymax
Definition: pltx.c:65
wstruct
Definition: pltx.c:57
wstruct::red
int red
Definition: pltx.c:74
wstruct::flag
int flag
Definition: pltx.c:70
MAX_WINDOWS
#define MAX_WINDOWS
Definition: pltx.c:55
wpoll
void FORTRAN() wpoll()
Definition: pltx.c:860
doevnt
void doevnt(int wn)
Definition: pltx.c:405
wstruct::bed
int bed
Definition: pltx.c:74
findzero
int findzero(int wn, float ymax, float ymin)
Definition: pltx.c:96
fstplt
void FORTRAN() fstplt(double *y1, double *y2, double *xmin1, double *xstep1, int *indx1, int *wnum)
Definition: pltx.c:805
calcul
void calcul(int wn)
Definition: pltx.c:321
findmin
float findmin(float *ary, int indx)
Definition: pltx.c:202
wstruct::xys
XPoint xys[4096]
Definition: pltx.c:63
wstruct::gc
GC gc
Definition: pltx.c:61
wstruct::xstep
float xstep
Definition: pltx.c:65
tridag::y
double complex, dimension(mxdim), save y
Definition: tridag.f90:32
xarry::x
float x
Definition: pltx.c:79
wstruct::ymin
float ymin
Definition: pltx.c:65
wstruct::dspy
Display * dspy
Definition: pltx.c:59
wstruct::fgnd
unsigned int fgnd
Definition: pltx.c:69
FORTRAN
#define FORTRAN(n)
Definition: fortrancall.h:8
wstruct::map
Colormap map
Definition: pltx.c:62
wstruct::ydif
XPoint ydif[4096]
Definition: pltx.c:63
xarry::next
struct xarry * next
Definition: pltx.c:80
wstruct::xmax
float xmax
Definition: pltx.c:65
wstruct::ys
float ys[4096]
Definition: pltx.c:64
pixary
void pixary(float *y, float min, float step, int n, XPoint *xy, float ymax, float ymin, int wn)
Definition: pltx.c:266
wstruct::ted
int ted
Definition: pltx.c:74
wstruct::wndw
Drawable wndw
Definition: pltx.c:60
wstruct::el
float el
Definition: pltx.c:73
wstruct::et
float et
Definition: pltx.c:73
wstruct::bgnd
unsigned int bgnd
Definition: pltx.c:69
word
char word[20]
Definition: pltx.c:83
wds
struct wstruct wds[MAX_WINDOWS+1]
Definition: pltx.c:86
wstruct::mode
int mode
Definition: pltx.c:68
wstruct::nx
int nx
Definition: pltx.c:72
wstruct::led
int led
Definition: pltx.c:74
eprprm::bed
double precision, pointer, save bed
Definition: eprprm.f90:58
numwndws
int numwndws
Definition: pltx.c:87
wstruct::gc2
GC gc2
Definition: pltx.c:61
drawln
void drawln(int wn)
Definition: pltx.c:116
getwndws
void FORTRAN() getwndws(int *n, word *title)
Definition: pltx.c:589
wstruct::xmin
float xmin
Definition: pltx.c:65
xarry
Definition: pltx.c:77
calcpt
void calcpt(int xpt, int ypt, float *xpt1, float *ypt1, int wn)
Definition: pltx.c:351
done
int done
Definition: pltx.c:88
wstruct::yzer
int yzer
Definition: pltx.c:71
wstruct::ye
float ye[4096]
Definition: pltx.c:64
wstruct::flag2
int flag2
Definition: pltx.c:70
fortrancall.h
wstruct::er
float er
Definition: pltx.c:73
xnew
struct xarry * xnew(struct xarry *list)
Definition: pltx.c:174
xdump
void xdump(struct xarry *list)
Definition: pltx.c:186
wstruct::ny
int ny
Definition: pltx.c:72
getstr
void getstr(char *pltstr, float xpt, float ypt)
Definition: pltx.c:389
differnce
void differnce(XPoint *xy1, XPoint *xy2, int indx, XPoint *ydif, int yzer)
Definition: pltx.c:246
putary
void putary(double *y1, double *y2, int wn)
Definition: pltx.c:793
setxpts
void setxpts(XPoint *xypts, int xpt, int ypt)
Definition: pltx.c:373
wstruct::gc1
GC gc1
Definition: pltx.c:61
shtwndws
void FORTRAN() shtwndws()
Definition: pltx.c:875
wstruct::scrn
int scrn
Definition: pltx.c:67
wstruct::xye
XPoint xye[4096]
Definition: pltx.c:63
lmcom::mode
integer, pointer, save mode
Definition: lmcom.f90:32
wstruct::indx
int indx
Definition: pltx.c:66
wstruct::gc3
GC gc3
Definition: pltx.c:61
findmax
float findmax(float *ary, int indx)
Definition: pltx.c:222
wstruct::eb
float eb
Definition: pltx.c:73