Linuxpops  3.01.04
Spectral Anaysis Package for Single Dish Data
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xgr.c
Go to the documentation of this file.
1 
2 #define TRUE 1
3 #define FALSE 0
4 
5 #define DEFINE_COLORS TRUE
6 #include "ds_extern.h"
7 #include "ds_proto.h"
8 
9 static int font0 = FONT_SIZE_SMALL;
10 static int font1 = FONT_SIZE_NORMAL;
11 static int font2 = FONT_SIZE_BIG;
12 
14 int mcount = 0;
15 
17 int doFocal = 0;
18 int noXTick = 0;
19 int noYTick = 0;
20 int noPlot = 0;
21 int xgr_hardFont = 0;
22 int fixedZero = 0;
23 
24 static float xtickb, xticke, xinterval, ytickb, yticke, yinterval;
25 
28 
30 
31 int lockScale = 0;
32 
33 static int local_malloc();
34 extern int focalTicks;
35 
37 
38 char prgName[80];
39 
40 static unsigned long getColor();
41 static int drawXticks(), drawYticks(), tickGet(), find_ticks();
42 static int setColor(), allocColors();
43 
44 /*
45  * insque( entry, predecessor ) macro
46  *
47  * The queue entry specified by the entry pointer "e" is inserted following
48  * the member specified by the predecessor pointer "p".
49  *
50  */
51 #define insque(e,p) (e)->next=((e)->prev=(p))->next; \
52  (p)->next=(p)->next->prev=(e)
53 
54 /*
55  * remque( entry ) macro
56  *
57  * The queue entry specified by the entry pointer "e" is removed.
58  *
59  */
60 #define remque(e) (e)->prev->next=(e)->next; \
61  (e)->next->prev=(e)->prev; \
62  (e)->next = (e)->prev = (e)
63 
64 #define MAX_GRAY_SCALE 256
65 
68 
70 
72 struct XGR_ *s;
73 {
75 
76  allocColors(s);
77 
78  XSetWindowBackground(s->dpy, s->cur->win, s->colors[s->cur->background]);
79 
80  XSetBackground(s->dpy, s->cur->gc, s->colors[s->cur->background]);
81 
82  XClearWindow(s->dpy, s->cur->win);
83 
84  globalScale = 1;
85  globalStart = 1.0;
86  globalStop = (double)MAX_GRAY_SCALE;
87 
88  return(0);
89 }
90 
91 
92 
94 int n;
95 {
96  if( n == 16 || n == 32 || n == 64 || n == 128 || n == 256)
97  {
98  newMaxGrayScale = n;
100  }
101 
102  return(0);
103 }
104 
105 
107 int c;
108 {
109  struct XGR_HEAD *p;
110  struct XGR_ *s;
111 
112  doColor = c;
113  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
114  {
115  s = (struct XGR_ *)p;
116  allocColors(s);
117  }
118 
119  return(0);
120 }
121 
122 
123 
124 static int allocColors(s)
125 struct XGR_ *s;
126 {
127  int i;
128 
129  if(s->def_cmap)
130  {
131  XFreeColors(s->dpy, s->def_cmap, s->grayScale, max_gray_scale, AllPlanes);
132  }
133 
135 
136  log_msg("allocColors(): Allocating %d colors for %s", max_gray_scale, DisplayString(s->dpy));
137 
138  if(!s->colors[0])
139  {
140  for(i=0;i<MAX_COLORS;i++)
141  {
142  s->colors[i] = getColor(s, colorsTxt[i], 1, 0, 0, 0);
143  }
144  }
145 
146  if(doColor == PSEUDO)
147  {
148  loadPseudoScale(s);
149  }
150  else
151  if(doColor >= FLAME1)
152  {
154  }
155  else
156  {
157  loadGrayScale(s);
158  }
159 
160  log_msg("allocColors(): Done");
161 
162  return(0);
163 }
164 
165 
166 
167 
169 struct XGR_ *s;
170 {
171  int i, r, g, b;
172  char buf[80];
173  int fac;
174 
175  fac = 256 / max_gray_scale;
176  for(i=0;i<max_gray_scale;i++)
177  {
178  r = i*fac;
179  g = i*fac;
180  b = i*fac;
181 
182  sprintf(buf, "gray%d", i*fac);
183  s->grayScale[i] = getColor(s, buf, 0, i*fac, i*fac, i*fac);
184 
185  colormap[i].r = r;
186  colormap[i].g = g;
187  colormap[i].b = b;
188  }
189 
190  return(0);
191 }
192 
193 
194 
195 int flame(a, b, x)
196 double a, b, x;
197 {
198  int ret=0;
199 
200  if( x > b)
201  {
202  ret = (int)rint(a * sqrt(x-b));
203 
204  if(ret > 255)
205  {
206  ret = 255;
207  }
208  }
209 
210  return(ret);
211 }
212 
213 
214 
215 int loadFlameScale(s, cindx)
216 struct XGR_ *s;
217 int cindx;
218 {
219  int r,g,b, i, k, dx;
220  char buf[80];
221  static double aa[] = { 17.084, 18.80, 29.456 };
222  static double bb[] = { 0.0, 115.0, 202.0 };
223 
224  k = 0;
226 
227  for(i=0;i<MAX_GRAY_SCALE;i+=dx)
228  {
229  switch(cindx) {
230  case FLAME1:
231  r = flame(aa[0], bb[0], (double)i);
232  g = flame(aa[1], bb[1], (double)i);
233  b = flame(aa[2], bb[2], (double)i);
234  break;
235 
236  case FLAME2:
237  r = flame(aa[0], bb[0], (double)i);
238  b = flame(aa[1], bb[1], (double)i);
239  g = flame(aa[2], bb[2], (double)i);
240  break;
241 
242  case FLAME3:
243  g = flame(aa[0], bb[0], (double)i);
244  r = flame(aa[1], bb[1], (double)i);
245  b = flame(aa[2], bb[2], (double)i);
246  break;
247 
248  case FLAME4:
249  b = flame(aa[0], bb[0], (double)i);
250  g = flame(aa[1], bb[1], (double)i);
251  r = flame(aa[2], bb[2], (double)i);
252  break;
253 
254  case FLAME5:
255  g = flame(aa[0], bb[0], (double)i);
256  b = flame(aa[1], bb[1], (double)i);
257  r = flame(aa[2], bb[2], (double)i);
258  break;
259 
260  case FLAME6:
261  b = flame(aa[0], bb[0], (double)i);
262  r = flame(aa[1], bb[1], (double)i);
263  g = flame(aa[2], bb[2], (double)i);
264  break;
265  }
266 
267  colormap[i].r = r;
268  colormap[i].g = g;
269  colormap[i].b = b;
270 
271  sprintf(buf, "color%d", i);
272  s->grayScale[k++] = getColor(s, buf, 0, r, g, b);
273  }
274 
275  return(0);
276 }
277 
278 
280 struct XGR_ *s;
281 {
282  int r,g,b, i, k=0, dx;
283  int b1, b2;
284  char buf[80];
285 
286  b1 = 85;
287  b2 = 180;
288  dx = 256 / max_gray_scale;
289 
290  for(i=0;i<MAX_GRAY_SCALE;i+=dx)
291  {
292  if(i <= b1)
293  {
294  r = 0;
295  b = 255;
296  g = (int)((float)i * 255.0 / (float)b1);
297  }
298  else
299  if(i > b1 && i < b2)
300  {
301  r = (int)((float)(i-b1) * 255.0 / (float)(b2-b1));
302  g = 255;
303  b = 255 - r;
304  }
305  else
306  {
307  r = 255;
308  g = 255 - (int)((float)(i-b2) * 255.0 / (float)(255-b2));
309  b = 0;
310  }
311 
312  colormap[i].r = r;
313  colormap[i].g = g;
314  colormap[i].b = b;
315 
316  sprintf(buf, "color%d", i);
317  s->grayScale[k++] = getColor(s, buf, 0, r, g, b);
318  }
319 
320  return(0);
321 }
322 
323 
324 static int loadFont(s, fn)
325 struct XGR_ *s;
326 int fn;
327 {
328  char errBuf[256];
329 
330  if(s->invalidServerFonts)
331  return(0);
332 
333  setFrameFooter("Stand-by, Loading Fonts", LEFT);
334  if(( s->fontInfo[fn] = XLoadQueryFont(s->dpy, s->fontNames[fn])) == NULL)
335  {
336  sprintf( errBuf,"Cannot open %s font", s->fontNames[fn]);
337  log_msg("loadFont(): %s", DisplayString(s->dpy), errBuf);
338  setFrameFooter(errBuf, RIGHT);
339  s->invalidServerFonts = 1;
340  return(0);
341  }
342  setFrameFooter("", LEFT);
343 
344  return(1);
345 }
346 
347 
349 struct XGR_ *s;
350 {
351  struct WINDOW_HEAD *p2;
352  struct WINDOW *w;
353 
354  if(!s)
355  return(1);
356 
357  if(s->userXimage)
358  XDestroyImage(s->userXimage);
359 
360  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
361  {
362  w = (struct WINDOW *)p2;
363  if(w->usPixmap && w->pixmap)
364  {
365  XFreePixmap(s->dpy, w->pixmap);
366  }
367 
368  free((char *)w);
369  }
370  if(s->numFonts)
371  if(s->fontNames)
372  free((char *)s->fontNames);
373 
374  free((char *)s);
375 
376  return(0);
377 }
378 
379 
380 
381 int xgr_setWindowSize(name, x, y)
382 char *name;
383 float x, y;
384 {
385  struct XGR_HEAD *p;
386  struct XGR_ *s;
387  struct WINDOW_HEAD *p2;
388  struct WINDOW *s2;
389  int w, h, ww, x1, yy1;
390  float fac;
391  XSizeHints size_hints;
392  static int oldw=-1, oldh=-1;
393 
394  log_msg("xgr_setWindowSize(): X = %f, y = %f", x, y);
395 
396  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
397  {
398  s = (struct XGR_ *)p;
399 
400  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
401  {
402  s2 = (struct WINDOW *)p2;
403 
404  if(!strcmp(s2->frameTitle, name))
405  {
406  ww = WidthOfScreen(XDefaultScreenOfDisplay(s->dpy));
407 
408  log_msg("WidthOfScreen(): returns %d", ww);
409 
410 
411  if( x == 1.0 && y == 1.0)
412  {
413  w = 450;
414  h = 400;
415  x1 = ww -w -6;
416  yy1 = 23;
417  }
418  else
419  {
420  fac = x / y;
421 
422  if( fac < 1.0 ) /* tall narrow map */
423  {
424  h = 600;
425  w = (int)((float)h * fac);
426  }
427  else /* wide short map */
428  {
429  w = 800;
430  h = (int)((float)w / fac);
431  }
432 
433  x1 = ww -w -6;
434  yy1 = 23;
435  }
436 
437  if(!strcmp(name, "Spectral Plot Window"))
438  {
439  x1 = 800;
440  yy1 = 0;
441  w = (int)x;
442  h = (int)y;
443  }
444 
445  if(!strcmp(name, "OTF Gridder"))
446  {
447  x1 = 1000;
448  yy1 = 100;
449 // w = (int)x;
450 // h = (int)y;
451  }
452 
453  if(w != s2->canw || h != s2->canh)
454  {
455  if(w != oldw && h != oldh)
456  {
457  log_msg("xgr_setWindowSize(): Setting %s window to %d %d %d %d", name, x1, yy1, w, h);
458  oldw = w; oldh = h;
459  }
460 
461  size_hints.flags = PMinSize | PSize;
462  size_hints.min_width = w / 4;
463  size_hints.min_height = h / 4;
464  size_hints.width = w;
465  size_hints.height = h;
466 
467  XSetWMNormalHints(s->dpy, s2->win, &size_hints);
468 
469  XResizeWindow(s->dpy, s2->win, w, h);
470 
471  XFlush(s->dpy);
472  }
473 
474  break;
475  }
476  }
477  }
478 
479  return(0);
480 }
481 
482 
484 int win;
485 int which;
486 {
487  struct XGR_HEAD *p;
488  struct XGR_ *s;
489  struct WINDOW_HEAD *p2;
490 
491  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
492  {
493  s = (struct XGR_ *)p;
494 
495  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
496  {
497  switch(win)
498  {
499  case XGR_MAIN_WIN: s->cur = s->plotwin; break;
500  case XGR_OTF_WIN: s->cur = s->otfwin; break;
501  case XGR_SPEC_WIN: s->cur = s->specwin; break;
502  case XGR_STAT_WIN: s->cur = s->statwin; break;
503 
504  default:
505  fprintf(stderr, "Unknown Window: %d; exiting\n", win);
506  exit(1);
507  break;
508  }
509 
510  if(which == XGR_SET_PIXMAP && s->cur->usPixmap)
511  {
512  s->cur->act = s->cur->pixmap;
513 // log_msg("xgr_setCurWindow(): Setting Pixmap %p Active for Window %p", s->cur->pixmap, s->cur->act);
514  }
515  else
516  {
517  s->cur->act = s->cur->win;
518 // log_msg("xgr_setCurWindow(): Setting Window %p Active for Window %p", s->cur->win, s->cur->act);
519  }
520 
521  break;
522  }
523  }
524 
525  return(0);
526 }
527 
528 
529 
531 char *name;
532 {
533  int ret = 1;
534  struct XGR_HEAD *p;
535  struct XGR_ *s;
536  struct WINDOW_HEAD *p2;
537  struct WINDOW *s2;
538 
539  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
540  {
541  s = (struct XGR_ *)p;
542 
543  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
544  {
545  s2 = (struct WINDOW *)p2;
546 
547  if(!strcmp(s2->frameTitle, name) && s2->usPixmap)
548  {
549 // log_msg("xgr_pixmapToWindow(): Copying Pixmap %p to Window %p", s2->pixmap, s2->win);
550 
551  XCopyArea(s->dpy, s2->pixmap, s2->win, s2->gc,
552  0, 0, (unsigned int)s2->canw,
553  (unsigned int)s2->canh,
554  0, 0);
555  s->cur->act = s->cur->win;
556 
557  ret = 0;
558 
559  break;
560  }
561  }
562  }
563 
564  return(ret);
565 }
566 
567 
568 int xgr_mapUnmapWindow(name, map)
569 char *name;
570 int map;
571 {
572  struct XGR_HEAD *p;
573  struct XGR_ *s;
574  struct WINDOW_HEAD *p2;
575  struct WINDOW *s2;
576 
577  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
578  {
579  s = (struct XGR_ *)p;
580  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
581  {
582  s2 = (struct WINDOW *)p2;
583  if(!strcasecmp(s2->frameTitle, name))
584  {
585  if(map == 0)
586  XIconifyWindow(s->dpy, s2->win, s->scr_num);
587  else
588  {
589  XMapWindow(s->dpy, s2->win);
590  XMapRaised(s->dpy, s2->win);
591  }
592  break;
593  }
594  }
595  }
596 
597  return(0);
598 }
599 
600 
601 
602 int xgr_findWindow(dpy, win, w)
603 Display *dpy;
604 Window win;
605 struct WINDOW **w;
606 {
607  struct XGR_HEAD *p;
608  struct XGR_ *s;
609  struct WINDOW_HEAD *p2;
610  struct WINDOW *s2;
611 
612  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
613  {
614  s = (struct XGR_ *)p;
615 
616  if(s->dpy == dpy)
617  {
618  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
619  {
620  s2 = (struct WINDOW *)p2;
621 
622  if(s2->win == win)
623  {
624  *w = s2;
625 
626  return(0);
627  }
628  }
629  }
630  }
631 
632  w = (struct WINDOW **)NULL;
633 
634  return(1);
635 }
636 
637 
638 
639 int xgr_putXimage(win_name, fx, fy, w, h, data)
640 char *win_name;
641 float fx, fy;
642 int w, h;
643 unsigned char *data;
644 {
645  struct XGR_HEAD *p;
646  struct XGR_ *s;
647  struct WINDOW_HEAD *p2;
648  struct WINDOW *s2;
649  int i, x, y;
650 
651  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
652  {
653  s = (struct XGR_ *)p;
654 
655  if(s->userXimage)
656  {
657  XDestroyImage(s->userXimage);
658  s->userXimage = NULL;
659  }
660 
661  if(!(s->userXimage=createXimage(s->dpy, w, h, s->depth)))
662  {
663  log_msg("xgr_putXimage(): Error in create of pixmap for %s\n", DisplayString(s->dpy));
664  s->userXimage = NULL;
665  return(1);
666  }
667 
668  if(s->depth == 8)
669  {
670  for(i=0;i<w*h;i++)
671  s->userXimage->data[i] = (unsigned char)s->grayScale[(int)data[i]];
672  }
673  else
674  {
675  for(i=0,y=0;y<h;y++)
676  for(x=0;x<w;x++,i++)
677  XPutPixel(s->userXimage, x, y, s->grayScale[(int)data[i]]);
678  }
679 
680  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
681  {
682  s2 = (struct WINDOW *)p2;
683  if(strstr(s2->frameTitle, win_name) && s2->act)
684  {
685  x = (int)(fx * (float)s2->canw);
686  y = (int)(fy * (float)s2->canh);
687  XPutImage(s->dpy, s2->act, s2->gc, s->userXimage, 0, 0, x, y, w, h);
688  }
689  }
690  }
691 
692  return(0);
693 }
694 
695 
696 
697 
698 int xgr_reSizeProc(window, width, height)
699 Window window;
700 int width, height;
701 {
702  struct XGR_HEAD *p;
703  struct XGR_ *s;
704  struct WINDOW_HEAD *p2;
705  struct WINDOW *s2;
706 
707  log_msg("xgr_reSizeProc(): Window Resizing: %d x %d", width, height);
708 
709  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
710  {
711  s = (struct XGR_ *)p;
712  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
713  {
714  s2 = (struct WINDOW *)p2;
715  if(s2->win == window)
716  {
717  if(s2->canw != width || s2->canh != height)
718  {
719  if(s2->usPixmap)
720  {
721  if(s2->pixmap && s2->pixmap)
722  {
723  log_msg("xgr_reSizeProc(): Freeing Window %p, Pixmap %p", s2->win, s2->pixmap);
724 
725  XFreePixmap(s->dpy, s2->pixmap);
726 
727  s2->pixmap = 0;
728  }
729 
730  if(!(s2->pixmap=XCreatePixmap(s->dpy, s2->win, (unsigned int)width, (unsigned int)height, s->depth)))
731  {
732  log_msg("xgr_reSizeProc(): Error in create of pixmap for %s\n", DisplayString(s->dpy));
733  s2->usPixmap = 0;
734  }
735  else
736  {
737  XSetForeground(s->dpy, s->cur->gc, s->colors[BLACK]);
738  XFillRectangle(s->dpy, s2->pixmap, s->cur->gc, 0, 0, (unsigned int)s->cur->canw, (unsigned int)s->cur->canh);
739  log_msg("xgr_reSizeProc(): New Pixmap, %p for Window %p", s2->pixmap, s2->win);
740  }
741  }
742  }
743 
744  s2->canw = width;
745  s2->canh = height;
746  s2->invalid = 1;
747 
748  if(s2->resize_proc)
749  {
750  log_msg("xgr_reSizeProc(): Calling resize proc for win: %p", window);
751  return(s2->resize_proc(s2->win));
752  }
753  }
754  }
755  }
756 
757  return(1);
758 }
759 
760 
761 
762 int xgr_eventProc(event, window, mask)
763 XEvent *event;
764 Window window;
765 unsigned int mask;
766 {
767  struct XGR_HEAD *p;
768  struct XGR_ *s;
769  struct WINDOW_HEAD *p2;
770  struct WINDOW *s2;
771 
772  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
773  {
774  s = (struct XGR_ *)p;
775  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
776  {
777  s2 = (struct WINDOW *)p2;
778 
779  if(s2->win == window)
780  {
781  if(s2->event_proc)
782  {
783  return(s2->event_proc(event, mask));
784  }
785  }
786  }
787  }
788 
789  return(1);
790 }
791 
792 
793 
794 int xgr_rePaintProc(window)
795 Window window;
796 {
797  struct XGR_HEAD *p;
798  struct XGR_ *s;
799  struct WINDOW_HEAD *p2;
800  struct WINDOW *s2;
801 
802  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
803  {
804  s = (struct XGR_ *)p;
805  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
806  {
807  s2 = (struct WINDOW *)p2;
808  if(s2->win == window)
809  {
810  if(s2->first == 1)
811  {
812  s2->first=0;
813  return(0);
814  }
815  s2->invalid = 1;
816  return(s2->repaint_proc(s2->win));
817  }
818  }
819  }
820 
821  return(1);
822 }
823 
824 
825 
827 Window win;
828 {
829  struct XGR_HEAD *p;
830  struct XGR_ *s;
831  struct WINDOW_HEAD *p2;
832  struct WINDOW *s2;
833 
834  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
835  {
836  s = (struct XGR_ *)p;
837  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
838  {
839  s2 = (struct WINDOW *)p2;
840  if(s2->win == win)
841  {
842  return(s2);
843  }
844  }
845  }
846 
847  return((struct WINDOW *)NULL);
848 }
849 
850 
851 int xgr_hardCopy(win, land, rev, file)
852 char *win, *file;
853 int land, rev;
854 {
855  struct XGR_HEAD *p;
856  struct XGR_ *s;
857  struct WINDOW_HEAD *p2;
858  struct WINDOW *s2;
859 
860  if(win == NULL || file == NULL)
861  return(1);
862 
863  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
864  {
865  s = (struct XGR_ *)p;
866  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
867  {
868  s2 = (struct WINDOW *)p2;
869  if(!strncasecmp(s2->frameTitle, win, strlen(win)))
870  {
872  XFlush(s->dpy);
873 // writePS(s->dpy, s2->win, s->scr_num, 0, 0, s2->canw, s2->canh,
874 // land, rev, s2->frameTitle, file);
875 
876  fprintf(stderr,"PRINT_DONE\n");
877 
878  return(0);
879  }
880  }
881  }
882 
883  return(1);
884 }
885 
886 
887 int xgr_makeGif(win, file)
888 char *win, *file;
889 {
890  struct XGR_HEAD *p;
891  struct XGR_ *s;
892  struct WINDOW_HEAD *p2;
893  struct WINDOW *s2;
894 
895  if(win == NULL || file == NULL)
896  return(1);
897 
898  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
899  {
900  s = (struct XGR_ *)p;
901  for(p2=s->windows.next;p2!=&s->windows;p2=p2->next)
902  {
903  s2 = (struct WINDOW *)p2;
904  if(!strncasecmp(s2->frameTitle, win, strlen(win)))
905  {
907  XFlush(s->dpy);
908 // DumpScreen2Gif(file, GIF_DUMP_X_WINDOW, s2->win,
909 // (int)s->dpy, s->def_cmap, s2->canw, s2->canh);
910  fprintf(stderr,"GIF_DONE\n");
911 
912  return(0);
913  }
914  }
915  }
916 
917  return(1);
918 }
919 
920 
922 {
923  struct XGR_HEAD *p;
924  struct XGR_ *s;
925 
926  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
927  {
928  s = (struct XGR_ *)p;
929 
930  if(!s->cur->invalid)
931  {
932  continue;
933  }
934 
935  if(s->cur->act)
936  {
937 // log_msg("xgr_clearScreen(): Clearing Window: %p", s->cur->act);
938 
939  XSetForeground(s->dpy, s->cur->gc, s->colors[s->cur->background]);
940  XFillRectangle(s->dpy, s->cur->act, s->cur->gc, 0, 0,
941  (unsigned int)s->cur->canw, (unsigned int)s->cur->canh);
942  }
943  }
944 
945  return(0);
946 }
947 
948 
949 int xgr_clearArea(x, y, dx, dy)
950 float x, y, dx, dy;
951 {
952  struct XGR_HEAD *p;
953  struct XGR_ *s;
954  int x1, x2, yy1, w1, h1;
955 
956  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
957  {
958  s = (struct XGR_ *)p;
959  if(!s->cur->invalid)
960  continue;
961 
962  x1 = (int)( (float)s->cur->canw * x);
963  x2 = (int)( (float)s->cur->canw * dx);
964  w1 = x2 - x1;
965  yy1 = s->cur->canh - (int)( (float)s->cur->canh * dy);
966  h1 = yy1;
967 
968  if(s->cur->act)
969  {
970  XSetForeground(s->dpy, s->cur->gc, s->colors[s->cur->background]);
971  XFillRectangle(s->dpy, s->cur->act, s->cur->gc, x1, yy1,
972  (unsigned int)w1, (unsigned int)h1);
973  }
974  }
975 
976  return(0);
977 }
978 
979 
980  /* most of this code was shamelessly stolen from John Bradley's xv */
981 int find_close_color(dpy, cmap, exact_color, color)
982 Display *dpy;
983 Colormap cmap;
984 XColor *exact_color;
985 char *color;
986 {
987  int scn, ncells, i, j;
988  XColor ctab[256];
989  int dc, d, mdist, close;
990  int rd, gd, bd, ri, gi, bi;
991 
992  scn = DefaultScreen(dpy);
993  ncells = DisplayCells(dpy, scn);
994 
995  /* read entire colormap (or first 256 entries) into 'ctab' */
996  dc = (ncells<256) ? ncells : 256;
997  for(i=0;i<dc;i++)
998  ctab[i].pixel = (unsigned long)i;
999 
1000  XQueryColors(dpy, cmap, ctab, dc);
1001 
1002  mdist = 1000000;
1003  close = -1;
1004  ri = exact_color->red>>8;
1005  gi = exact_color->green>>8;
1006  bi = exact_color->blue>>8;
1007 
1008  for(j=0;j<dc;j++)
1009  {
1010  rd = ri - (ctab[j].red >>8);
1011  gd = gi - (ctab[j].green>>8);
1012  bd = bi - (ctab[j].blue >>8);
1013 
1014 
1015  d = rd*rd + gd*gd + bd*bd;
1016  if(d<mdist)
1017  {
1018  mdist=d;
1019  close=j;
1020  }
1021  }
1022  if(close<0) /* This Can't Happen! (How reassuring.) */
1023  {
1024  log_msg("find_close_color(): Can't allocate %s", color );
1025 
1026  if(strstr(color, "black"))
1027  return(XBlackPixel(dpy, scn));
1028  else
1029  return(XWhitePixel(dpy, scn));
1030  }
1031  if( XAllocColor( dpy, cmap, &ctab[close]))
1032  return(ctab[close].pixel);
1033  else
1034  {
1035  log_msg("find_close_color(): Can't allocate %s", color );
1036 
1037  if(strstr(color, "black"))
1038  return(XBlackPixel(dpy, scn));
1039  else
1040  return(XWhitePixel(dpy, scn));
1041  }
1042 
1043  return(0);
1044 }
1045 
1046 
1047 
1048 static unsigned long getColor(s, color, flag, red, green, blue)
1049 struct XGR_ *s;
1050 char *color;
1051 int flag, red, green, blue;
1052 {
1053  XColor exact_color;
1054 
1055  if(!s->def_cmap)
1056  {
1057  s->def_cmap = DefaultColormap(s->dpy, s->scr_num);
1058  }
1059 
1060  if(flag)
1061  {
1062  if( !XParseColor( s->dpy, s->def_cmap, color, &exact_color ) )
1063  {
1064  log_msg("getColor(): %s is not in %s color database", DisplayString(s->dpy), color);
1065 
1066  if(strstr(color, "black"))
1067  {
1068  return(XBlackPixel(s->dpy, s->scr_num));
1069  }
1070  else
1071  {
1072  return(XWhitePixel(s->dpy, s->scr_num));
1073  }
1074  }
1075  }
1076  else
1077  {
1078  exact_color.red = red * 255;
1079  exact_color.green = green * 255;
1080  exact_color.blue = blue * 255;
1081  exact_color.flags = DoRed | DoGreen | DoBlue;
1082  }
1083 
1084  if( !XAllocColor( s->dpy, s->def_cmap, &exact_color ) )
1085  {
1086  log_msg("getColor(): Can't allocate %s for %s\n", color, DisplayString(s->dpy));
1087 
1088  return(find_close_color(s->dpy, s->def_cmap, &exact_color, color));
1089  }
1090 
1091  return(exact_color.pixel);
1092 }
1093 
1094 
1095 
1096 static int setColor(s, color)
1097 struct XGR_ *s;
1098 int color;
1099 {
1100  if(!s->cur->invalid || s->cur->foreground == color)
1101  {
1102  return(0);
1103  }
1104 
1105  if(color>=0)
1106  {
1107  XSetForeground(s->dpy,s->cur->gc, s->colors[color] );
1108  }
1109  else
1110  {
1111  XSetForeground(s->dpy,s->cur->gc, s->grayScale[color * -1] );
1112  }
1113 
1114  s->cur->foreground = color;
1115 
1116  currentColor = color;
1117 
1118  return(0);
1119 }
1120 
1121 
1122 
1123 
1124 int xgr_drawLine(xdata, ydata, n, color)
1125 float *xdata;
1126 float *ydata;
1127 int n, color;
1128 {
1129  struct XGR_HEAD *p;
1130  struct XGR_ *s;
1131  static XPoint *temp=NULL;
1132  int i,nt;
1133  float MaxY, MinY, MaxX, MinX;
1134  float xmax, xmin, ymax, ymin;
1135  extern int zerodata;
1136 
1137  if(debug)
1138  {
1139  log_msg("xgr_drawLine()");
1140  }
1141 
1142  if( (temp = (XPoint *)malloc((unsigned)(n*sizeof(XPoint))) ) == NULL)
1143  {
1144  log_perror("malloc(temp)");
1145 
1146  return(1);
1147  }
1148 
1149  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1150  {
1151  s = (struct XGR_ *)p;
1152 
1153  if(!s->cur->invalid)
1154  {
1155  continue;
1156  }
1157 
1158  setColor(s, color);
1159 
1160  MaxY = (float)s->cur->plotye;
1161  MinY = (float)s->cur->plotyb;
1162  MaxX = (float)s->cur->plotxe;
1163  MinX = (float)s->cur->plotxb;
1164  nt = 4;
1165 
1166  if(lockScale)
1167  {
1168  lockScale = 0;
1169  }
1170  else
1171  {
1172  tickGet(xdata,n, &xtickb, &xticke, &xntick, &xinterval, &xmin, &xmax);
1173 
1174  if(!zerodata)
1175  {
1176  tickGet(ydata,n, &ytickb, &yticke, &yntick, &yinterval, &ymin, &ymax);
1177 
1178  globalYMin = ytickb;
1179  globalYMax = yticke;
1180  }
1181  else
1182  {
1183  ytickb = -1.0;
1184  yticke = 1.0;
1185  yntick = 4;
1186  yinterval = 2.0 / 6.0;
1187  ymin = -1.0;
1188  ymax = 1.0;
1189  }
1190 
1191  drawXticks(s, nt);
1192 
1193  doFocal = 0;
1194 
1195  drawYticks(s);
1196  }
1197 
1198  if(!noPlot)
1199  {
1200  for(i=0;i<n;i++)
1201  {
1202  temp[i].x = (int)(MinX+((MaxX-MinX)/(xmax -xmin ))*(xdata[i]-xmin ));
1203  temp[i].y = (int)(MaxY-((MaxY-MinY)/(yticke-ytickb))*(ydata[i]-ytickb));
1204  }
1205 
1206  XDrawLines(s->dpy, s->cur->act, s->cur->gc, temp, n, 0 );
1207 
1208  if((ytickb < 0.0 && yticke > 0.0) || ytickb == 0.0 || yticke == 0.0)
1209  {
1210  setColor(s, CYAN);
1211 
1212  for(i=0;i<n;i++)
1213  {
1214  temp[i].y = (int)(MaxY-((MaxY-MinY)/(yticke-ytickb))*(0.0-ytickb));
1215  }
1216 
1217  XDrawLines(s->dpy, s->cur->act, s->cur->gc, temp, n, 0 );
1218 
1219  setColor(s, GREEN);
1220  }
1221  }
1222  }
1223 
1224  noXTick = 0;
1225  noYTick = 0;
1226  noPlot = 0;
1227 
1228  free((char *)temp);
1229 
1230  return(0);
1231 }
1232 
1233 
1234 int xgr_drawLineDirect( xmin, xmax, ymin, ymax, xdata, ydata, n, color)
1235 float xmin, xmax, ymin, ymax;
1236 float *xdata;
1237 float *ydata;
1238 int n, color;
1239 {
1240  struct XGR_HEAD *p;
1241  struct XGR_ *s;
1242  static XPoint *temp=NULL;
1243  int i;
1244  float MaxY, MinY, MaxX, MinX;
1245 
1246  if( (temp = (XPoint *)malloc((unsigned)(n*sizeof(XPoint))) ) == NULL) {
1247  fprintf(stderr,"%s: Error in xgr_drawLineDirect(malloc())\n", prgName);
1248  return(1);
1249  }
1250 
1251  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1252  {
1253  s = (struct XGR_ *)p;
1254 
1255  if(!s->cur->invalid)
1256  continue;
1257 
1258  setColor(s, color);
1259  MaxY = (float)s->cur->plotye;
1260  MinY = (float)s->cur->plotyb;
1261  MaxX = (float)s->cur->plotxe;
1262  MinX = (float)s->cur->plotxb;
1263  for(i=0;i<n;i++)
1264  {
1265  temp[i].x = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xdata[i]-xmin));
1266  temp[i].y = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(ydata[i]-ymin));
1267  }
1268  XDrawLines(s->dpy, s->cur->act, s->cur->gc, temp, n, 0 );
1269  }
1270 
1271  free((char *)temp);
1272 
1273  return(0);
1274 }
1275 
1276 
1277 
1278 
1279 int xgr_drawPoints(xmin, xmax, ymin, ymax, xdata, ydata, n, color)
1280 float xmin, xmax, ymin, ymax;
1281 float *xdata;
1282 float *ydata;
1283 int n, color;
1284 {
1285  struct XGR_HEAD *p;
1286  struct XGR_ *s;
1287  static XPoint *temp=NULL;
1288  int i;
1289  float MaxY, MinY, MaxX, MinX;
1290 
1291  if( (temp = (XPoint *)malloc((unsigned)(n*sizeof(XPoint))) ) == NULL) {
1292  fprintf(stderr,"%s: Error in xgr_drawPoint( malloc() )\n", prgName);
1293  return(1);
1294  }
1295 
1296  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1297  {
1298  s = (struct XGR_ *)p;
1299 
1300  if(!s->cur->invalid)
1301  continue;
1302 
1303  setColor(s, color);
1304  MaxY = (float)s->cur->plotye;
1305  MinY = (float)s->cur->plotyb;
1306  MaxX = (float)s->cur->plotxe;
1307  MinX = (float)s->cur->plotxb;
1308 
1309  for(i=0;i<n;i++) {
1310  temp[i].x = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xdata[i]-xmin));
1311  temp[i].y = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(ydata[i]-ymin));
1312  }
1313  XDrawPoints(s->dpy, s->cur->act, s->cur->gc, temp, n, 0 );
1314  }
1315 
1316  free((char *)temp);
1317 
1318  return(0);
1319 }
1320 
1321 
1322 
1323 
1324 static int drawXticks(s, n)
1325 struct XGR_ *s;
1326 int n;
1327 {
1328  float f,f1, deltaF;
1329  char buf[256];
1330  int i, delta, sl, save_color;
1331 
1332  if(noXTick)
1333  {
1334  return(0);
1335  }
1336 
1337  xgr_setFont(s, font0);
1338 
1339  delta = (s->cur->plotxe-s->cur->plotxb)/(n);
1340 
1341  if(delta < 1)
1342  {
1343  delta = 1;
1344  }
1345 
1346  f = globalStart;
1347  f1 = globalStop;
1348  deltaF = (f1 - f) / (float)n;
1349 
1350  for(i=s->cur->plotxb;i<=s->cur->plotxe;i+=delta)
1351  {
1352  if(doFocal)
1353  sprintf(buf,"%.2f",f);
1354  else
1355  sprintf(buf,"%.0f",f);
1356 
1357  sl = strlen(buf);
1358 
1359  XDrawString(s->dpy, s->cur->act, s->cur->gc, i-(s->fontW*sl)/2,s->cur->plotye+s->fontH,buf,sl);
1360 
1361  if(drawGrid)
1362  {
1363  save_color = currentColor;
1364  setColor(s, GRAY32);
1365  XDrawLine( s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotyb, i, s->cur->plotye );
1366  setColor(s, save_color);
1367  }
1368  else
1369  {
1370  XDrawLine( s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotyb, i, s->cur->plotyb+5);
1371  XDrawLine( s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotye-5, i, s->cur->plotye );
1372  }
1373 
1374  f += deltaF;
1375  }
1376 
1377  return(0);
1378 }
1379 
1380 
1381 
1382 
1383 static int drawYticks(s)
1384 struct XGR_ *s;
1385 {
1386  float f;
1387  char buf[256];
1388  int i, delta, sl, save_color;
1389 
1390  if(noYTick)
1391  {
1392  return(0);
1393  }
1394 
1395  delta = (s->cur->plotye-s->cur->plotyb)/(yntick+2);
1396  if(delta < 1)
1397  {
1398  delta = 1;
1399  }
1400 
1401  f = ytickb;
1402 
1403  xgr_setFont(s, font0);
1404  for(i=s->cur->plotye;i>=s->cur->plotyb;i-=delta)
1405  {
1406  if( yinterval < 0.01)
1407  {
1408  sprintf(buf,"%4.3f",f);
1409  }
1410  else
1411  if( yinterval < 0.1)
1412  {
1413  sprintf(buf,"%4.2f",f);
1414  }
1415  else
1416  if( yinterval < 1.0)
1417  {
1418  sprintf(buf,"%4.1f",f);
1419  }
1420  else
1421  if( yinterval > 50.0)
1422  {
1423  sprintf(buf,"%.0f",f);
1424  }
1425  else
1426  {
1427  sprintf(buf,"%4.1f",f);
1428  }
1429 
1430  sl = strlen(buf);
1431 
1432  XDrawString(s->dpy,s->cur->act,s->cur->gc,s->cur->plotxb-(sl*s->fontW)-2,i+s->fontH/2-2,buf,sl);
1433 
1434  if(drawGrid)
1435  {
1436  save_color = currentColor;
1437  setColor(s, GRAY32);
1438  XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxb, i, s->cur->plotxe, i);
1439  setColor(s, save_color);
1440  }
1441  else
1442  {
1443  XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxb, i, s->cur->plotxb+5,i);
1444  XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxe-5, i, s->cur->plotxe, i);
1445  }
1446 
1447  f += yinterval;
1448  }
1449 
1450  return(0);
1451 }
1452 
1453 
1454 
1455 int xgr_drawBin( xdata, ydata, n, color)
1456 float *xdata;
1457 float *ydata;
1458 int n, color;
1459 {
1460  int i,j,k,l=0, m;
1461  static float *x=NULL,*y=NULL;
1462 
1463  if(debug)
1464  {
1465  log_msg("xgr_drawBin()");
1466  }
1467 
1468  if(n>100)
1469  k=2;
1470  else
1471  k=10;
1472 
1473  m = n*k;
1474  globalScale = k;
1475  globalStart = xdata[0];
1476  globalStop = xdata[n-1];
1477 
1478  if(local_malloc("xgr_drawBin", &x, &y, m))
1479  return(0);
1480 
1481  for(i=0;i<n;i++)
1482  {
1483  for(j=0;j<k;j++)
1484  {
1485  if(!(i != 0 && j == 0))
1486  l++;
1487  x[j+(i*k)] = (float)l;
1488  y[j+(i*k)] = ydata[i];
1489  }
1490  }
1491 
1492  xgr_drawLine(x, y, m, color);
1493 
1494  free((char *)x);
1495  free((char *)y);
1496 
1497  return(0);
1498 }
1499 
1500 
1501 
1502 
1503 
1504 int xgr_drawGrid(f1b, f1e, f2b, f2e, n1, n2, dx, dy, tick, label, clr1, clr2,format)
1505 float f1b,f1e,f2b,f2e;
1506 int n1, n2, dx, dy, tick, label, clr1, clr2, format;
1507 {
1508  struct XGR_HEAD *p;
1509  struct XGR_ *s;
1510  float i_delta, j, deltaF,f;
1511  char buf[256];
1512  int n, i, k, sl, ddx, ddy;
1513  int segIndx;
1514  XSegment *segments = NULL;
1515 
1516  if(tick >=0)
1517  {
1518  if(n1>n2)
1519  n = n1 * 2 + 10;
1520  else
1521  n = n2 * 2 + 10;
1522 
1523  if((segments = (XSegment *)malloc(n * sizeof(XSegment))) == NULL){
1524  log_msg("xgr_drawGrid: Error in (malloc(%d))", n * sizeof(XSegment));
1525  return(1);
1526  }
1527  }
1528 
1529  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1530  {
1531  s = (struct XGR_ *)p;
1532 
1533  if(!s->cur->invalid)
1534  continue;
1535 
1536  xgr_setFont(s, font0);
1537  /* draw x axis */
1538  i_delta = ((float)s->cur->plotxe - (float)s->cur->plotxb)/(float)n1;
1539  j = (float)s->cur->plotxb;
1540  i = (int)j;
1541  segIndx = 0;
1542  switch(tick)
1543  {
1544  case 0:
1545  for(k=0;k<=n1;k++)
1546  {
1547  segments[segIndx].x1 = (short)i;
1548  segments[segIndx].y1 = (short)s->cur->plotyb;
1549  segments[segIndx].x2 = (short)i;
1550  segments[segIndx++].y2 = (short)s->cur->plotye;
1551  j += i_delta;
1552  i = (int)j;
1553  }
1554  break;
1555 
1556  case 1:
1557  for(k=0;k<=n1;k++)
1558  {
1559  segments[segIndx].x1 = (short)i;
1560  segments[segIndx].y1 = (short)s->cur->plotyb;
1561  segments[segIndx].x2 = (short)i;
1562  segments[segIndx++].y2 = (short)s->cur->plotyb+5;
1563  segments[segIndx].x1 = (short)i;
1564  segments[segIndx].y1 = (short)s->cur->plotye-5;
1565  segments[segIndx].x2 = (short)i;
1566  segments[segIndx++].y2 = (short)s->cur->plotye;
1567  j += i_delta;
1568  i = (int)j;
1569  }
1570  break;
1571  }
1572  if(segIndx)
1573  {
1574  setColor(s, clr1);
1575  XDrawSegments(s->dpy, s->cur->act, s->cur->gc, segments, segIndx);
1576  }
1577 
1578  if(label&1) /* draw x axis labels if so desired */
1579  {
1580  f = f1b;
1581  deltaF = (f1e - f1b) / (float)n1;
1582  ddx = n1/dx;
1583  j = (float)s->cur->plotxb;
1584  i = (int)j;
1585  setColor(s, clr2);
1586 
1587  for(k=0;k<=dx;k++)
1588  {
1589  if(tick==1)
1590  {
1591  XDrawLine(s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotyb,
1592  i, s->cur->plotyb+10);
1593  XDrawLine(s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotye-10,
1594  i, s->cur->plotye);
1595  }
1596  else
1597  if(tick==0)
1598  {
1599  XDrawLine(s->dpy, s->cur->act, s->cur->gc, i, s->cur->plotyb,
1600  i, s->cur->plotye);
1601  }
1602 
1603  if(format == XGR_PLOT_DEGREES)
1604  {
1605  if(fabs(deltaF) < 0.100)
1606  sprintf(buf+4," %.3f ",f);
1607  else
1608  sprintf(buf+4," %.1f ",f);
1609  }
1610  else
1611  if(format == XGR_PLOT_SEX)
1612  sexagesimal((double)f, buf+4, DD_MM_SS);
1613  else
1614  sprintf(buf+4," ");
1615 
1616  sl = strlen(buf+4);
1617  XDrawImageString(s->dpy, s->cur->act, s->cur->gc,
1618  i-(s->fontW*sl)/2, s->cur->plotye+s->fontH+1, buf+4,sl);
1619 
1620  f += deltaF*(float)ddx;
1621  j += i_delta*ddx;
1622  i = (int)j;
1623  }
1624  }
1625  /* draw y axis */
1626  i_delta = ((float)s->cur->plotye - (float)s->cur->plotyb)/(float)n2;
1627  j = (float)s->cur->plotyb;
1628  i = (int)j;
1629  setColor(s, clr1);
1630  segIndx = 0;
1631  switch(tick)
1632  {
1633  case 0:
1634  for(k=0;k<=n2;k++)
1635  {
1636  segments[segIndx].x1 = (short)s->cur->plotxb;
1637  segments[segIndx].y1 = (short)i;
1638  segments[segIndx].x2 = (short)s->cur->plotxe;
1639  segments[segIndx++].y2 = (short)i;
1640  j += i_delta;
1641  i = (int)j;
1642  }
1643  break;
1644 
1645  case 1:
1646  for(k=0;k<=n2;k++)
1647  {
1648  segments[segIndx].x1 = (short)s->cur->plotxb;
1649  segments[segIndx].y1 = (short)i;
1650  segments[segIndx].x2 = (short)s->cur->plotxb+5;
1651  segments[segIndx++].y2 = (short)i;
1652  segments[segIndx].x1 = (short)s->cur->plotxe-5;
1653  segments[segIndx].y1 = (short)i;
1654  segments[segIndx].x2 = (short)s->cur->plotxe;
1655  segments[segIndx++].y2 = (short)i;
1656  j += i_delta;
1657  i = (int)j;
1658  }
1659  break;
1660  }
1661  if(segIndx)
1662  XDrawSegments(s->dpy, s->cur->act, s->cur->gc, segments, segIndx);
1663 
1664  if(label&2)
1665  {
1666  f = f2b;
1667  deltaF = (f2e - f2b) / (float)n2;
1668  ddy = n2/dy;
1669  j = (float)s->cur->plotyb;
1670  i = (int)j;
1671  setColor(s, clr2);
1672 
1673  for(k=0;k<=dy;k++)
1674  {
1675  if(tick==1)
1676  {
1677  XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxb, i,
1678  s->cur->plotxb+10, i);
1679  XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxe-10, i,
1680  s->cur->plotxe, i);
1681  }
1682  else
1683  if(tick==0)
1684  {
1685  XDrawLine(s->dpy, s->cur->act, s->cur->gc, s->cur->plotxb, i,
1686  s->cur->plotxe, i);
1687  }
1688 
1689  if(format == XGR_PLOT_DEGREES)
1690  {
1691  if(fabs(deltaF) < 0.100)
1692  sprintf(buf+4," %.3f ",f);
1693  else
1694  sprintf(buf+4," %.1f ",f);
1695  }
1696  else
1697  if(format == XGR_PLOT_SEX)
1698  sexagesimal((double)f, buf+4, DD_MM_SS);
1699  else
1700  sprintf(buf+4," ");
1701 
1702  sl = strlen(buf+4);
1703  XDrawImageString(s->dpy, s->cur->act, s->cur->gc,
1704  s->cur->plotxb-s->fontW*sl,i+s->fontH/2, buf+4,sl);
1705 
1706  f += deltaF*(float)ddy;
1707  j += i_delta*ddy;
1708  i = (int)j;
1709  }
1710  }
1711  }
1712 
1713  if(segments)
1714  free(segments);
1715 
1716  return(0);
1717 }
1718 
1719 
1720 
1721 static int local_malloc(who,xdata,ydata,dl)
1722 char *who;
1723 float **xdata, **ydata;
1724 int dl;
1725 {
1726  if( (*xdata = (float *)malloc((unsigned)(dl*sizeof(float))) ) == NULL) {
1727  fprintf(stderr,"%s: Error in %s( malloc() )\n", prgName, who);
1728  return(1);
1729  }
1730  if( (*ydata = (float *)malloc((unsigned)(dl*sizeof(float))) ) == NULL) {
1731  fprintf(stderr,"%s: Error in %s( malloc() )\n", prgName, who);
1732  return(1);
1733  }
1734 
1735  return(0);
1736 }
1737 
1738 
1739 
1740 int xgr_drawBox(x, y, x2, y2, color)
1741 float x, y, x2, y2;
1742 int color;
1743 {
1744  struct XGR_HEAD *p;
1745  struct XGR_ *s;
1746  int xb, xe, yb, ye;
1747  unsigned w, h;
1748 
1749 // log_msg("xgr_drawBox(): x = %f, y = %f, dx = %f, dy = %f", x, y, x2, y2);
1750 
1751  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1752  {
1753  s = (struct XGR_ *)p;
1754 
1755  if(!s->cur->invalid)
1756  {
1757  continue;
1758  }
1759 
1760  setColor(s, color);
1761 
1762  s->cur->plotxb = xb = (int)( (float)s->cur->canw * x );
1763  s->cur->plotxe = xe = (int)( (float)s->cur->canw * x2);
1764 
1765  /* Y is upside down; so, switch them here */
1766  s->cur->plotyb = yb = s->cur->canh - (int)( (float)s->cur->canh * y2);
1767  s->cur->plotye = ye = s->cur->canh - (int)( (float)s->cur->canh * y );
1768 
1769  w = (unsigned int)abs(xe-xb);
1770  h = (unsigned int)abs(ye-yb);
1771 
1772 // log_msg("xgr_drawBox(): canw = %d, canh = %d, x = %d, y = %d, w = %u, h = %u", s->cur->canw, s->cur->canh, xb, yb, w, h);
1773 
1774  XDrawRectangle(s->dpy, s->cur->act, s->cur->gc, xb, yb, w, h);
1775  }
1776 
1777  return(0);
1778 }
1779 
1780 
1781 
1782 int xgr_setBox(x,y,dx,dy)
1783 float x,y,dx,dy;
1784 {
1785  struct XGR_HEAD *p;
1786  struct XGR_ *s;
1787 
1788  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1789  {
1790  s = (struct XGR_ *)p;
1791  s->cur->plotxb = (int)( (float)s->cur->canw * x);
1792  s->cur->plotxe = (int)( (float)s->cur->canw * dx);
1793  s->cur->plotyb = s->cur->canh - (int)( (float)s->cur->canh * dy);
1794  s->cur->plotye = s->cur->canh - (int)( (float)s->cur->canh * y);
1795  }
1796 
1797  return(0);
1798 }
1799 
1800 
1801 
1802 int xgr_drawFillBox( xmin, xmax, ymin, ymax, xl, yt, xr, yb, color)
1803 float xmin, xmax, ymin, ymax;
1804 float xl, yt, xr, yb;
1805 int color;
1806 {
1807  struct XGR_HEAD *p;
1808  struct XGR_ *s;
1809  int x1, x2, yy1, y2;
1810  float MaxY, MinY, MaxX, MinX;
1811  unsigned int dx, dy;
1812 
1813  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1814  {
1815  s = (struct XGR_ *)p;
1816 
1817  if(!s->cur->invalid || !s->cur->act)
1818  continue;
1819 
1820  setColor(s, color);
1821  XSetFillStyle(s->dpy, s->cur->gc, FillSolid);
1822  MaxY = (float)s->cur->plotye;
1823  MinY = (float)s->cur->plotyb;
1824  MaxX = (float)s->cur->plotxe;
1825  MinX = (float)s->cur->plotxb;
1826  x1 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xl-xmin));
1827  x2 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xr-xmin));
1828  dx = (unsigned int)(x2 - x1);
1829  yy1 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(yb-ymin));
1830  y2 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(yt-ymin));
1831  dy = (unsigned int)(y2 - yy1);
1832 
1833 // log_msg("xgr_drawFillBox(): Drawing on Window: %p", s->cur->act);
1834 
1835  XFillRectangle(s->dpy, s->cur->act, s->cur->gc, x1, yy1, (unsigned int)dx, (unsigned int)dy);
1836  }
1837 
1838  return(0);
1839 }
1840 
1841 
1842 int xgr_drawRectangle( xmin, xmax, ymin, ymax, xl, yt, xr, yb, color, bold)
1843 float xmin, xmax, ymin, ymax;
1844 float xl, yt, xr, yb;
1845 int color, bold;
1846 {
1847  struct XGR_HEAD *p;
1848  struct XGR_ *s;
1849  int x1, x2, yy1, y2;
1850  float MaxY, MinY, MaxX, MinX;
1851  unsigned int dx, dy;
1852 
1853  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1854  {
1855  s = (struct XGR_ *)p;
1856 
1857  if(!s->cur->invalid || !s->cur->act)
1858  {
1859  continue;
1860  }
1861 
1862  setColor(s, color);
1863 
1864  MaxY = (float)s->cur->plotye;
1865  MinY = (float)s->cur->plotyb;
1866  MaxX = (float)s->cur->plotxe;
1867  MinX = (float)s->cur->plotxb;
1868 
1869  x1 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xl-xmin));
1870  x2 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(xr-xmin));
1871  dx = (unsigned int)(x2 - x1);
1872  yy1 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(yb-ymin));
1873  y2 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(yt-ymin));
1874  dy = (unsigned int)(y2 - yy1);
1875 
1876  if(debug)
1877  {
1878  log_msg("xgr_drawRectangle(): %d %d %d %d", x1, yy1, dx, dy);
1879  }
1880 
1881  XDrawRectangle(s->dpy, s->cur->act, s->cur->gc, x1, yy1, dx, dy);
1882 
1883  if(bold)
1884  {
1885  XDrawRectangle(s->dpy, s->cur->act, s->cur->gc, x1+1, yy1+1, dx, dy);
1886  }
1887  }
1888 
1889  return(0);
1890 }
1891 
1892 
1893 int xgr_drawTextInGrid( xmin, xmax, ymin, ymax, x, y, msg, color, f)
1894 float xmin, xmax, ymin, ymax;
1895 float x, y;
1896 char *msg;
1897 int color, f;
1898 {
1899  struct XGR_HEAD *p;
1900  struct XGR_ *s;
1901  int x1, yy1;
1902  float MaxY, MinY, MaxX, MinX;
1903 
1904  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1905  {
1906  s = (struct XGR_ *)p;
1907 
1908  if(!s->cur->invalid || !s->cur->act)
1909  {
1910  continue;
1911  }
1912 
1913  setColor(s, color);
1914  xgr_setFont(s, f);
1915 
1916 
1917  MaxY = (float)s->cur->plotye;
1918  MinY = (float)s->cur->plotyb;
1919  MaxX = (float)s->cur->plotxe;
1920  MinX = (float)s->cur->plotxb;
1921 
1922  x1 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(x-xmin));
1923  yy1 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(y-ymin));
1924 
1925  if(debug)
1926  {
1927  log_msg("xgr_drawTextInGrid(): %d %d %s", x1, yy1, msg);
1928  }
1929 
1930  XDrawString(s->dpy, s->cur->act, s->cur->gc, x1, yy1, msg, strlen(msg));
1931  }
1932 
1933  return(0);
1934 }
1935 
1936 
1937 
1938 int xgr_drawCircle( xmin, xmax, ymin, ymax, x, y, w, h, color, size)
1939 float xmin, xmax, ymin, ymax;
1940 float x, y, w, h;
1941 int color, size;
1942 {
1943  struct XGR_HEAD *p;
1944  struct XGR_ *s;
1945  int x1, x2, y1, y2;
1946  float MaxY, MinY, MaxX, MinX;
1947  unsigned int dx, dy;
1948 
1949  if(debug)
1950  {
1951  log_msg("xgr_drawCircle(%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f)", xmin, xmax, ymin, ymax, x, y, w, h);
1952  }
1953 
1954  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
1955  {
1956  s = (struct XGR_ *)p;
1957 
1958  if(!s->cur->invalid || !s->cur->act)
1959  {
1960  continue;
1961  }
1962 
1963  setColor(s, color);
1964 
1965  MaxY = (float)s->cur->plotye;
1966  MinY = (float)s->cur->plotyb;
1967  MaxX = (float)s->cur->plotxe;
1968  MinX = (float)s->cur->plotxb;
1969 
1970  x1 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(x-xmin));
1971  x2 = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(w-xmin));
1972  dx = (unsigned int)abs(x2 - x1);
1973 
1974  y1 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(y-ymin));
1975  y2 = (int)(MaxY-((MaxY-MinY)/(ymax-ymin))*(h-ymin));
1976  dy = (unsigned int)abs(y2 - y1);
1977 
1978  if(debug)
1979  {
1980  log_msg("xgr_drawCircle(): x1 = %d, x2 = %d, y1 = %d, y2 = %d, dx = %d, dy = %d", x1, x2, y1, y2, dx, dy);
1981  }
1982 
1983  XSetLineAttributes(s->dpy, s->cur->gc, size, LineSolid, CapRound, JoinRound);
1984 
1985  XDrawArc(s->dpy, s->cur->act, s->cur->gc, x1, y1, dx, dy, 0*64, 360*64);
1986 
1987  XSetLineAttributes(s->dpy, s->cur->gc, 1, LineSolid, CapRound, JoinRound);
1988  }
1989 
1990  return(0);
1991 }
1992 
1993 
1994 
1995 int xgr_drawPosText(x,y,msg, clr, f)
1996 float x,y;
1997 char *msg;
1998 int clr, f;
1999 {
2000  struct XGR_HEAD *p;
2001  struct XGR_ *s;
2002  int x1, yy1, canw, canh;
2003 
2004  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2005  {
2006  s = (struct XGR_ *)p;
2007 
2008  if(!s->cur->invalid)
2009  continue;
2010 
2011  setColor(s, clr);
2012  xgr_setFont(s, f);
2013 
2014  canw = s->cur->plotxe - s->cur->plotxb;
2015  canh = s->cur->plotye - s->cur->plotyb;
2016  x1 = (int)(x * (float)canw)+s->cur->plotxb;
2017  yy1 = (int)(y * (float)canh)+s->cur->plotyb;
2018 
2019  XDrawString(s->dpy, s->cur->act, s->cur->gc, x1, yy1, msg, strlen(msg));
2020  }
2021 
2022  return(0);
2023 }
2024 
2025 
2026 
2027 
2028 int xgr_drawText(x,y,msg, clr, f)
2029 float x,y;
2030 char *msg;
2031 int clr, f;
2032 {
2033  struct XGR_HEAD *p;
2034  struct XGR_ *s;
2035 
2036  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2037  {
2038  s = (struct XGR_ *)p;
2039 
2040  if(!s->cur->invalid)
2041  continue;
2042 
2043  setColor(s, clr);
2044  xgr_setFont(s, f);
2045  XDrawString(s->dpy, s->cur->act, s->cur->gc,
2046  (int)(x * (float)s->cur->canw),
2047  s->cur->canh - (int)(y * (float)s->cur->canh),
2048  msg, strlen(msg));
2049  }
2050 
2051  return(0);
2052 }
2053 
2054 
2055 int xgr_drawTextClear(x,y,msg, clr, f)
2056 float x,y;
2057 char *msg;
2058 int clr, f;
2059 {
2060  struct XGR_HEAD *p;
2061  struct XGR_ *s;
2062 
2063  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2064  {
2065  s = (struct XGR_ *)p;
2066 
2067  if(!s->cur->invalid)
2068  continue;
2069 
2070  setColor(s, clr);
2071  xgr_setFont(s, f);
2072  XDrawImageString(s->dpy, s->cur->act, s->cur->gc,
2073  (int)(x * (float)s->cur->canw),
2074  s->cur->canh - (int)(y * (float)s->cur->canh),
2075  msg, strlen(msg));
2076  }
2077 
2078  return(0);
2079 }
2080 
2081 
2082 
2083 int xgr_drawPoint(xdata, ydata, n, xmin, xmax, msg, color, f)
2084 float *xdata;
2085 float *ydata;
2086 int n, color;
2087 float xmin, xmax;
2088 char *msg;
2089 int f;
2090 {
2091  struct XGR_HEAD *p;
2092  struct XGR_ *s;
2093  XPoint temp;
2094  int i;
2095 
2096  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2097  {
2098  s = (struct XGR_ *)p;
2099  if(!s->cur->invalid)
2100  continue;
2101 
2102  setColor(s, color);
2103  xgr_setFont(s, f);
2104 
2105  tickGet(xdata,n, &xtickb, &xticke, &xntick, &xinterval, &xmin, &xmax);
2106  for(i=0;i<n;i++)
2107  {
2108  temp.x = (int)((float)s->cur->plotxb + (((float)s->cur->plotxe
2109  - (float)s->cur->plotxb)
2110  / (xmax - xmin))
2111  * (xdata[i] - xmin));
2112  temp.y = (int)((float)s->cur->plotye - (((float)s->cur->plotye
2113  - (float)s->cur->plotyb)
2114  / (yticke - ytickb))
2115  * (ydata[i] - ytickb));
2116  temp.x -= (s->fontW / 2);
2117  temp.y += (s->fontH / 2) -2;
2118  XDrawString(s->dpy, s->cur->act, s->cur->gc, temp.x, temp.y, msg, strlen(msg));
2119  }
2120  }
2121 
2122  return(0);
2123 }
2124 
2125 
2126 int xgr_drawOn(x, y, n, xmin, xmax, msg, color, f)
2127 float x,y;
2128 int n, color;
2129 float xmin, xmax;
2130 char *msg;
2131 int f;
2132 {
2133  struct XGR_HEAD *p;
2134  struct XGR_ *s;
2135  XPoint temp;
2136  float MaxY, MinY, MaxX, MinX;
2137  int cw;
2138 
2139  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2140  {
2141  s = (struct XGR_ *)p;
2142  if(!s->cur->invalid)
2143  continue;
2144 
2145  setColor(s, color);
2146  xgr_setFont(s, f);
2147  MaxY = (float)s->cur->plotye;
2148  MinY = (float)s->cur->plotyb;
2149  cw = s->cur->canw / n;
2150  MaxX = (float)s->cur->plotxe-cw/2;
2151  MinX = (float)s->cur->plotxb+cw/2;
2152  temp.x = (int)(MinX+((MaxX-MinX)/(xmax-xmin))*(x-xmin));
2153  temp.y = (int)(MaxY-((MaxY-MinY)/(yticke-ytickb))*(y-ytickb));
2154  temp.x -= (s->fontW / 2);
2155  temp.y += (s->fontH / 2) -2;
2156  XDrawString(s->dpy, s->cur->act, s->cur->gc, temp.x, temp.y, msg, strlen(msg));
2157  }
2158 
2159  return(0);
2160 }
2161 
2162 
2163 
2164 int xgr_drawLabel(b1, b2, b3, color)
2165 char *b1,*b2,*b3;
2166 int color;
2167 {
2168  struct XGR_HEAD *p;
2169  struct XGR_ *s;
2170  int l;
2171  float f, ff;
2172  int x1, yy1;
2173 
2174  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2175  {
2176  s = (struct XGR_ *)p;
2177  if(!s->cur->invalid)
2178  continue;
2179 
2180  setColor(s, color);
2181  xgr_setFont(s, font2);
2182  l = strlen(b1); /* top */
2183  ff = (float)s->fontW / (float)s->cur->canw;
2184  f = 0.5 - ((float)l * ff) / 2.0;
2185  x1 = (int)(f * (float)s->cur->canw);
2186  yy1 = s->cur->canh - (int)(0.95 * (float)s->cur->canh);
2187  XDrawString(s->dpy, s->cur->act, s->cur->gc, x1, yy1, b1, strlen(b1));
2188 
2189  xgr_setFont(s, font1); /* bottom */
2190  l = strlen(b2);
2191  ff = (float)s->fontW / (float)s->cur->canw;
2192  f = 0.5 - ((float)l * ff) / 2.0;
2193  x1 = (int)(f * (float)s->cur->canw);
2194  yy1 = s->cur->canh - (int)(0.025 * (float)s->cur->canh);
2195  XDrawString(s->dpy, s->cur->act, s->cur->gc, x1, yy1, b2, strlen(b2));
2196  }
2197 
2198  return(0);
2199 }
2200 
2201 
2202 
2203 static int tickGet(x,n, start, end, tks, interval, min, max)
2204 float *x;
2205 int n, *tks;
2206 float *start, *end, *interval, *min, *max;
2207 {
2208  *tks = find_ticks(x, n, start, end, interval ,min, max);
2209 
2210  return(0);
2211 }
2212 
2213 static int find_ticks(f, n, pstart, pend, ptickint, mn, mx)
2214 float *f;
2215 int n;
2216 float *pstart, *pend, *ptickint, *mn, *mx;
2217 {
2218  double min, max, tickint, diff;
2219  int i, ticks;
2220  int order;
2221 
2222  max = -1.0e127; /* there are probably standard macros, but this works */
2223  min = 9.99e127;
2224 
2225  for( i=0; i< n; i++ ) { /* compute min and max */
2226  if( f[i] > max )
2227  max = f[i];
2228  if( f[i] < min )
2229  min = f[i];
2230  }
2231  *mn = min;
2232  *mx = max;
2233 
2234  diff = max-min;
2235  if(diff > 0.0)
2236  order = (int)rint(log10(diff))-1;
2237  else
2238  {
2239  *pend = max;
2240  *pstart = min;
2241  *ptickint = diff;
2242  return(1);
2243  }
2244 
2245  tickint = pow(10, (double)order);
2246  ticks = (int)rint(diff/tickint);
2247 
2248  if( ticks >= 10 )
2249  {
2250  if( ticks >= 20 )
2251  {
2252  ticks /= 5;
2253  tickint *= 5.0;
2254  }
2255  else
2256  {
2257  ticks /= 2;
2258  tickint *= 2.0;
2259  }
2260  }
2261  else
2262  if( ticks < 3 )
2263  {
2264  ticks *= 5;
2265  tickint /= 5.0;
2266  }
2267 
2268  if(fixedZero)
2269  {
2270  float maxval;
2271 
2272  if(fabs(min) > fabs(max))
2273  maxval = fabs(min);
2274  else
2275  maxval = fabs(max);
2276 
2277  *pend = maxval;
2278  *pstart = -maxval;
2279  *ptickint = maxval*2 / 6.0;
2280  return(7);
2281  }
2282  else
2283  {
2284  *pend = ((int)floor((max + tickint) / tickint)) * tickint;
2285 
2286  *pstart = *pend - (ticks +2) * tickint;
2287  *ptickint = tickint;
2288  return(ticks);
2289  }
2290 
2291 }
2292 
2293 
2294 int xgr_setFont(s, f)
2295 struct XGR_ *s;
2296 int f;
2297 {
2298  int fx;
2299  float d;
2300 
2301  if(xgr_hardFont == -1)
2302  {
2303  fx = f;
2304  }
2305  else
2306  if(xgr_hardFont == 1)
2307  {
2308  fx = f;
2309  }
2310  else
2311  {
2312  d=(float)s->cur->canw/(float)WidthOfScreen(XDefaultScreenOfDisplay(s->dpy));
2313  fx = f + (int)rint( (float)s->numFonts * d) - 1;
2314  if(fx >= s->numFonts)
2315  fx = s->numFonts-1;
2316  if(fx < 0)
2317  fx = 0;
2318  }
2319  if( s->fontInfo[fx] == NULL)
2320  if(!loadFont(s, fx))
2321  return(1);
2322 
2323  s->font_info = s->fontInfo[fx];
2324 
2325  XSetFont(s->dpy, s->cur->gc, s->font_info->fid);
2326  s->fontW = s->font_info->max_bounds.width;
2327  s->fontH = s->font_info->max_bounds.ascent+s->font_info->max_bounds.descent;
2328 
2329  return(0);
2330 }
2331 
2332 
2334 int w;
2335 {
2336  struct XGR_HEAD *p;
2337  struct XGR_ *s;
2338 
2339  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2340  {
2341  s = (struct XGR_ *)p;
2342  s->cur->invalid = w;
2343  s->cur->foreground = -999;
2344  }
2345 
2346  return(0);
2347 }
2348 
2349 
2350 
2351 char **findFixedFonts(dpy, num)
2352 Display *dpy;
2353 int *num;
2354 {
2355  int i=0, j=0, k=0, n=0, nn=0, found=0;
2356  static char **fontNames;
2357  static char **fN;
2358  static char tempNames[40][40];
2359  int charcompare();
2360 
2361  for(i=0;i<40;i++)
2362  tempNames[i][0] = '\0';
2363 
2364  if(*num==0)
2365  {
2366  log_msg("findFixedFonts(): Num of Fixed Fonts == Zero");
2367 
2368  return((char **)0);
2369  }
2370 
2371  n = 0;
2372  fontNames = XListFonts(dpy, "?x?bold", 100, &n);
2373  if(n)
2374  {
2375  nn = n;
2376  for(i=0,k=0;i<nn;i++)
2377  {
2378  found = 0;
2379  for(j=0;j<k;j++)
2380  {
2381  if(!strncmp(tempNames[j], fontNames[i], 2))
2382  found = 1;
2383  }
2384  if(!found && strlen(fontNames[i]) < 16)
2385  strcpy(tempNames[k++], fontNames[i]);
2386  }
2387  nn = k;
2388  }
2389 
2390  n = 0;
2391  fontNames = XListFonts(dpy, "?x??bold", 100, &n);
2392  if(n)
2393  {
2394  nn += n;
2395  for(i=0;i<n;i++)
2396  {
2397  found = 0;
2398  for(j=0;j<k;j++)
2399  {
2400  if(!strncmp(tempNames[j], fontNames[i], 2))
2401  found = 1;
2402  }
2403  if(!found && strlen(fontNames[i]) < 16)
2404  strcpy(tempNames[k++], fontNames[i]);
2405  }
2406  nn = k;
2407  }
2408 
2409  n = 0;
2410  fontNames = XListFonts(dpy, "??x??bold", 100, &n);
2411  if(n)
2412  {
2413  nn += n;
2414  for(i=0;i<n;i++)
2415  {
2416  found = 0;
2417  for(j=0;j<k;j++)
2418  {
2419  if(!strncmp(tempNames[j], fontNames[i], 2))
2420  found = 1;
2421  }
2422  if(!strstr(fontNames[i], "fixed") && !found && strlen(fontNames[i]) < 16)
2423  strcpy(tempNames[k++], fontNames[i]);
2424 
2425  }
2426  nn = k;
2427  }
2428  if(nn==0)
2429  {
2430  log_msg("findFixedFonts(): No Fixed Fonts Found");
2431  *num=0;
2432 
2433  return((char **)0);
2434  }
2435 
2436  if((fN = (char **)malloc((unsigned)(nn*sizeof(char *)))) == NULL)
2437  {
2438  log_msg("findFixedFonts(): Error in malloc() of Fixed Fonts");
2439  *num=0;
2440 
2441  return((char **)0);
2442  }
2443 
2444  for(i=0;i<nn;i++)
2445  fN[i] = (char *)tempNames[i];
2446 
2447  qsort((char *)&fN[0], nn, sizeof(char *), (__compar_fn_t)charcompare);
2448  if(nn != *num)
2449  *num = nn;
2450 
2451  return(fN);
2452 }
2453 
2454 
2455 
2456 int strcmp();
2457 
2458 int charcompare(s1,s2)
2459 char **s1, **s2;
2460 {
2461  int i,j, si, sj;
2462  char *cp1, *cp2;
2463  char t1[40], t2[40];
2464 
2465  i = atoi(*s1);
2466  j = atoi(*s2);
2467  if(i<j)
2468  return(-1);
2469  else
2470  if(i>j)
2471  return(1);
2472  else
2473  {
2474  strcpy(t1, *s1);
2475  strcpy(t2, *s2);
2476 
2477  cp1 = strtok(t1, "xX");
2478  if(cp1)
2479  {
2480  cp1 = strtok((char *)NULL, "xX");
2481  if(cp1)
2482  si = atoi(cp1);
2483  else
2484  return(strcmp(*s1,*s2));
2485  }
2486  else
2487  return(strcmp(*s1,*s2));
2488 
2489  cp2 = strtok(t2, "xX");
2490  if(cp2)
2491  {
2492  cp2 = strtok((char *)NULL, "xX");
2493  if(cp2)
2494  sj = atoi(cp2);
2495  else
2496  return(strcmp(*s1,*s2));
2497  }
2498  else
2499  return(strcmp(*s1,*s2));
2500 
2501  }
2502  if(si<sj)
2503  return(-1);
2504  else
2505  if(si>sj)
2506  return(1);
2507  else
2508 
2509  return(strcmp(*s1,*s2));
2510 }
2511 
2512 
2513 
2514 int setFrameFooter(msg, lr)
2515 char *msg;
2516 int lr;
2517 {
2518  struct XGR_HEAD *p;
2519  struct XGR_ *s;
2520  int l;
2521 
2522  return(0);
2523 
2524  if(msg)
2525  l = strlen(msg);
2526  else
2527  return(0);
2528 
2529  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2530  {
2531  s = (struct XGR_ *)p;
2532  if(lr == LEFT)
2533  {
2534  XDrawString(s->dpy, s->cur->act, s->cur->gc, 5, s->cur->canh, msg, l);
2535  }
2536  else
2537  {
2538  XDrawString(s->dpy, s->cur->act, s->cur->gc, s->cur->canw / 2 +5, s->cur->canh, msg, l);
2539  }
2540  }
2541 
2542  return(0);
2543 }
2544 
2545 
2546 
2548 {
2549  struct XGR_HEAD *p;
2550  struct XGR_ *s;
2551 
2552  for(p=xgr_head.next;p!=&xgr_head;p=p->next)
2553  {
2554  s = (struct XGR_ *)p;
2555  if(XPending(s->dpy))
2556  {
2557  processEvent(s);
2558  }
2559  }
2560 
2561  return(0);
2562 }
int mcount
Definition: xgr.c:14
struct WINDOW_HEAD windows
Definition: xgr.h:94
unsigned long colors[MAX_COLORS]
Definition: xgr.h:86
#define FONT_SIZE_BIG
Definition: dataFonts.h:8
#define MAX_GRAY_SCALE
Definition: xgr.c:64
#define FONT_SIZE_SMALL
Definition: dataFonts.h:6
int plotyb
Definition: xgr.h:63
int first
Definition: xgr.h:66
int xgr_drawGrid(double f1b, double f1e, double f2b, double f2e, int n1, int n2, int dx, int dy, int tick, int label, int clr1, int clr2, int format)
#define XGR_STAT_WIN
Definition: xgr.h:22
int xgr_drawLine(float *xdata, float *ydata, int n, int color)
Definition: xgr.c:1124
int noYTick
Definition: xgr.c:19
int xgr_drawBin(float *xdata, float *ydata, int n, int color)
Definition: xgr.c:1455
int xgr_drawPosText(double x, double y, char *msg, int clr, int f)
int find_close_color(Display *dpy, Colormap cmap, XColor *exact_color, char *color)
Definition: xgr.c:981
int xgr_drawBox(double x, double y, double x2, double y2, int color)
int xgr_drawLabel(char *b1, char *b2, char *b3, int color)
Definition: xgr.c:2164
Window act
Definition: xgr.h:51
int lockScale
Definition: xgr.c:31
int xgr_makeGif(char *win, char *file)
Definition: xgr.c:887
struct BOX_DATA bd
Definition: obsmodes.c:132
int log_perror(char *msg)
int doFocal
Definition: xgr.c:17
int xgr_drawTextInGrid(double xmin, double xmax, double ymin, double ymax, double x, double y, char *msg, int color, int f)
#define FLAME3
Definition: colors.h:37
int xgr_drawText(double x, double y, char *msg, int clr, int f)
#define XGR_MAIN_WIN
Definition: xgr.h:19
int plotye
Definition: xgr.h:63
int plotxe
Definition: xgr.h:63
#define max(a, b)
Definition: cactus.h:115
struct WINDOW * specwin
Definition: xgr.h:99
int fontH
Definition: xgr.h:85
struct XGR_HEAD * next
Definition: xgr.h:36
#define FLAME2
Definition: colors.h:36
#define min(a, b)
Definition: cactus.h:114
int xgr_freeWindows(struct XGR_ *s)
Definition: xgr.c:348
int zerodata
Definition: specdata.c:54
int xgr_putXimage(char *win_name, double fx, double fy, int w, int h, unsigned char *data)
int fontW
Definition: xgr.h:85
#define PSEUDO
Definition: colors.h:34
#define GRAY32
Definition: colors.h:6
struct WINDOW * otfwin
Definition: xgr.h:98
char ** fontNames
Definition: xgr.h:84
#define FONT_SIZE_NORMAL
Definition: dataFonts.h:7
#define XGR_SET_PIXMAP
Definition: xgr.h:24
static int allocColors()
int xgr_drawLineDirect(double xmin, double xmax, double ymin, double ymax, float *xdata, float *ydata, int n, int color)
#define LEFT
Definition: defines.h:7
int debug
Definition: mailparse.c:29
int globalScale
Definition: xgr.c:29
int usPixmap
Definition: xgr.h:53
int r
Definition: colors.h:46
int flame(double a, double b, double x)
Definition: xgr.c:195
int find_ticks(struct LP_IMAGE_INFO *image)
Definition: xgraphic.c:2588
#define CYAN
Definition: colors.h:10
Display * dpy
Definition: xgr.h:79
float globalStop
Definition: specplot.c:22
int(* resize_proc)()
Definition: xgr.h:69
int(* repaint_proc)()
Definition: xgr.h:68
int sexagesimal(double dang, char *str, int prec)
int noXTick
Definition: xgr.c:18
char * colorsTxt[]
int log_msg(const char *fmt,...)
int xgr_setNumColors(int n)
Definition: xgr.c:93
XImage * createXimage(Display *display, int w, int h, int depth)
Definition: otf.c:4520
#define FLAME1
Definition: colors.h:35
int depth
Definition: xgr.h:82
Definition: xgr.h:35
#define dy(i)
int xgr_drawFillBox(double xmin, double xmax, double ymin, double ymax, double xl, double yt, double xr, double yb, int color)
unsigned long grayScale[MAX_GRAY_SCALE]
Definition: xgr.h:87
int drawGrid
Definition: xgr.c:29
int doColor
Definition: xgr.c:13
int plotxb
Definition: xgr.h:63
struct WINDOW * xgr_getWin(Window win)
Definition: xgr.c:826
int setInValid(int w)
Definition: xgr.c:2333
int xgr_hardCopy(char *win, int land, int rev, char *file)
Definition: xgr.c:851
int yntick
Definition: xgr.c:16
Colormap def_cmap
Definition: xgr.h:83
#define XGR_OTF_WIN
Definition: xgr.h:20
int xgr_setWindowSize(char *name, double x, double y)
int xgr_drawPoint(float *xdata, float *ydata, int n, double xmin, double xmax, char *msg, int color, int f)
float globalYMax
Definition: xgr.c:27
float globalStart
Definition: specdata.c:37
char errBuf[512]
Definition: dataserv.c:52
#define XGR_PLOT_SEX
Definition: xgr.h:31
int loadGrayScale(struct XGR_ *s)
Definition: xgr.c:168
Definition: xgr.h:48
int strcmp()
struct WINDOW * cur
Definition: xgr.h:95
Definition: xgr.h:75
int xgr_findWindow(Display *dpy, Window win, struct WINDOW **w)
Definition: xgr.c:602
static int tickGet()
#define XGR_SPEC_WIN
Definition: xgr.h:21
#define DD_MM_SS
Definition: sex.h:15
int charcompare(char **s1, char **s2)
Definition: xgr.c:2458
int xgr_drawPoints(double xmin, double xmax, double ymin, double ymax, float *xdata, float *ydata, int n, int color)
int xgr_graphInit(struct XGR_ *s)
Definition: xgr.c:71
int xgr_reSizeProc(Window window, int width, int height)
Definition: xgr.c:698
#define FLAME6
Definition: colors.h:40
int xgr_drawTextClear(double x, double y, char *msg, int clr, int f)
int xgr_eventProc(XEvent *event, Window window, unsigned int mask)
Definition: xgr.c:762
int g
Definition: colors.h:47
Definition: colors.h:45
Window win
Definition: xgr.h:52
float globalYMin
Definition: xgr.c:27
int setColor(int c)
Definition: parse.c:2644
int loadFlameScale(struct XGR_ *s, int cindx)
Definition: xgr.c:215
int loadPseudoScale(struct XGR_ *s)
Definition: xgr.c:279
int currentColor
Definition: xgr.c:29
int noPlot
Definition: xgr.c:20
int xgr_hardFont
Definition: xgr.c:21
int xgr_setFont(struct XGR_ *s, int f)
Definition: xgr.c:2294
char frameTitle[80]
Definition: xgr.h:50
int xgr_setColorChoice(int c)
Definition: xgr.c:106
Pixmap pixmap
Definition: xgr.h:54
float xdata[MAX_ATM_ELEMENTS]
Definition: atm.c:90
struct WINDOW_HEAD * next
Definition: xgr.h:43
int foreground
Definition: xgr.h:59
struct XGR_HEAD xgr_head
Definition: xgr.c:36
int background
Definition: xgr.h:60
int b
Definition: colors.h:48
#define XGR_PLOT_DEGREES
Definition: xgr.h:30
struct RGB colormap[]
Definition: xgr.c:69
int fixedZero
Definition: xgr.c:22
GC gc
Definition: xgr.h:56
#define BLACK
Definition: colors.h:4
int xgr_pixmapToWindow(char *name)
Definition: xgr.c:530
int setFrameFooter(char *msg, int lr)
Definition: xgr.c:2514
char prgName[80]
Definition: dataserv.c:52
#define RIGHT
Definition: defines.h:8
struct WINDOW * statwin
Definition: xgr.h:100
int canw
Definition: xgr.h:57
int xgr_clearArea(double x, double y, double dx, double dy)
int xgr_setBox(double x, double y, double dx, double dy)
int max_gray_scale
Definition: xgr.c:66
int xgr_drawCircle(double xmin, double xmax, double ymin, double ymax, double x, double y, double w, double h, int color, int size)
char ** findFixedFonts(Display *dpy, int *num)
Definition: xgr.c:2351
int(* event_proc)()
Definition: xgr.h:70
int invalid
Definition: xgr.h:65
#define m(i)
int xgr_drawOn(double x, double y, int n, double xmin, double xmax, char *msg, int color, int f)
float ydata[MAX_ATM_ELEMENTS]
Definition: atm.c:91
#define MAX_COLORS
Definition: colors.h:15
XImage * userXimage
Definition: xgr.h:89
static int drawYticks()
int xgr_mapUnmapWindow(char *name, int map)
Definition: xgr.c:568
int xgr_drawRectangle(double xmin, double xmax, double ymin, double ymax, double xl, double yt, double xr, double yb, int color, int bold)
int newMaxGrayScale
Definition: xgr.c:67
#define dx(i)
int focalTicks
struct WINDOW * plotwin
Definition: xgr.h:97
int scr_num
Definition: xgr.h:81
int xgr_rePaintProc(Window window)
Definition: xgr.c:794
int xntick
Definition: xgr.c:16
int xgr_checkForEvents(void)
Definition: xgr.c:2547
#define FLAME5
Definition: colors.h:39
int canh
Definition: xgr.h:57
int xgr_clearScreen(void)
Definition: xgr.c:921
#define GREEN
Definition: colors.h:6
int processEvent(struct XGR_ *s)
Definition: dataserv.c:908
#define FLAME4
Definition: colors.h:38
int xgr_setCurWindow(int win, int which)
Definition: xgr.c:483