NEURON
plot.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include "hoc.h"
3 
4 
5 /*LINTLIBRARY*/
6 #undef IGNORE
7 #if LINT
8 #define IGNORE(arg) {if(arg);}
9 #else
10 #define IGNORE(arg) arg
11 #endif
12 
13 #if GRX
14 #include <libbcc.h>
15 #include "hoc.h"
16 #define __TURBOC__
17 #endif
18 
19 #if defined(useNeXTstep) || defined(__TURBOC__) || defined(__linux__)
20 #ifndef NRNOC_X11
21 #define NRNOC_X11 0
22 #endif
23 #endif
24 
25 #define FIG 1 /* 12/8/88 add fig style output , replaces hpflag*/
26 #define TEK 1
27 #define HP 1
28 /* but not VT125 */
29 #define CODRAW 1
30 
31 #if CODRAW
32 static void Codraw_plt(int, double, double);
33 static void Codraw_preamble(void);
34 #endif
35 
36 #if HP
37 static void hplot(int, double, double);
38 #endif
39 
40 #if FIG
41 static void Fig_preamble(void);
42 static void Fig_plt(int, double, double);
43 void Fig_file(const char*, int);
44 #endif
45 
46 #if TEK
47 static void tplot(int, double, double);
48 #endif
49 
50 #include <stdio.h>
51 #include <string.h>
52 
53 #if defined(__MINGW32__)
54 extern char** _environ;
55 #else /*!__MINGW32__*/
56 
57 #if HAVE_UNISTD_H
58 #include <unistd.h>
59 #if !defined(__APPLE__)
60 extern char** environ;
61 #else /* __APPLE */
62 #include <crt_externs.h>
63 #endif /* __APPLE__ */
64 #endif /* HAVE_UNISTD_H */
65 
66 #endif /*!__MINGW32__*/
67 
68 #if DOS
69 #include <graphics.h>
70 #include <dos.h>
71 #endif
72 #if defined(GRX)
73 #define DOS 1
74 #endif
75 
76 static int console = 1; /* 1 plotting to console graphics */
77 static int hardplot; /* 1 hp style 2 fig style 3 coplot*/
78 static int graphdev;
79 static int hpflag; /* hp plotter switch */
80 int hoc_plttext; /* text can be printed to hpdev */
81 #define text hoc_plttext
82 static FILE *gdev; /* system call stdout not directed to here */
83 static FILE *hpdev; /* hp, or fig style file */
84 static FILE *cdev; /* console device */
85 
86 #define SSUN 1
87 #define VT 2
88 #define SEL 3
89 #define TEK4014 4
90 #define ADM 5
91 #define NX 6
92 
93 #define US 037
94 #define GS 035
95 #define CAN 030
96 #define EM 031
97 #define FS 034
98 #define ESC 033
99 #define ETX 03
100 
101 static char vt100[] = "TERM=vt125";
102 static char adm3a[] = "TERM=adm3a";
103 static char ssun[] = "TERM=sun";
104 static char tek4014[] = "TERM=4014";
105 static char ncsa[] = "NEURON=ncsa";
106 int hoc_color = 15;
107 static double xlast, ylast;
108 
109 #if NRNOC_X11
110 extern void x11_put_text(const char*), x11_close_window(void), x11_setcolor(int);
111 extern void x11_coord(double, double), x11_vector(), x11_point(), x11_move(), x11flush();
112 extern void x11_clear(), x11_cleararea(), x11_open_window(), x11_fast(int);
113 static void hoc_x11plot(int, double, double);
114 #endif
115 
116 #if NeXTstep
117 extern void NeXT_put_text(), NeXT_close_window(), NeXT_setcolor();
118 extern void NeXT_coord(), NeXT_vector(), NeXT_point(), NeXT_move(), NeXTflush();
119 extern void NeXT_clear(), NeXT_cleararea(), NeXT_open_window(), NeXT_fast();
120 #endif
121 
122 static void hard_text_preamble();
123 
124 #if defined(__TURBOC__)
125 int egagrph = 0; /* global because need to erase on quit if in graphics
126  mode */
127 static int graphmode = 0;
128 static double xres=640., yres=350.;
129 static tplt();
130 
131 void *_graphgetmem(unsigned size) {
132  char *p;
133  p= hoc_Emalloc(size), hoc_malchk() ;
134  return p;
135 }
136 
137 static void Initplot(void) {
138 #if !defined(__GO32__)
139  registerfarbgidriver(EGAVGA_driver_far);
140  registerfarbgidriver(CGA_driver_far);
141  registerfarbgidriver(Herc_driver_far);
142  registerfarbgifont(triplex_font_far);
143 #endif
144 
145  graphdev = DETECT;
146  initgraph(&graphdev, &graphmode,"c:\\bc\\bgi");
147  {int err;
148  graphdev=1;
149  err = graphresult();
150  if (err != grOk) {
151 hoc_execerror("Error in initializing graphics adaptor\n", (char *)0);
152  }
153  xres = (double)(getmaxx()+1);
154  yres = (double)(getmaxy()+1);
155  grx_txt_clear();
156  return;
157  }
158  if (graphdev > 0) {
159  xres = (double)(getmaxx()+1);
160  yres = (double)(getmaxy()+1);
161  restorecrtmode();
162  } else {
163 hoc_execerror("Error in initializing graphics adaptor\n", (char *)0);
164  }
165 }
166 #endif
167 
168 void plprint(const char* s)
169 {
170 #if DOS
171  extern int newstyle;
172  extern unsigned text_style, text_size, text_orient;
173 #endif
174  char buf[128];
175 
176  if (text && s[strlen(s) - 1] == '\n') {
177  IGNORE(strcpy(buf, s));
178  s = buf;
179  buf[strlen(s)-1] = '\0';
180  }
181 
182  if (console && text) {
183 #if DOS
184  if (egagrph == 2) {
185  if (newstyle) {
186  settextstyle(text_style,text_orient,text_size);
187  newstyle = 0;
188  }
189  outtext(s);
190  }else{
191  IGNORE(fprintf(cdev, "%s", s));
192  }
193 #else
194 #if SUNCORE
195  hoc_pl_sunplot(s);
196 #else
197 #if NRNOC_X11
198  x11_put_text(s);
199 #else
200 #if NeXTstep
201  if (graphdev == NX)
202  NeXT_put_text(s);
203 #else
204 
205  IGNORE(fprintf(cdev, "%s", s));
206  IGNORE(fflush(cdev));
207 #endif
208 #endif
209 #endif
210 #endif
211 
212  } else if (!text) {
213 #if GRX
214  if (egagrph) {
215  hoc_outtext(s);
216  }else
217 #endif
218  {
219 #if 0
220  IGNORE(fprintf(stdout, "%s", s));
221 #else
222  nrnpy_pr("%s", s);
223 #endif
224  }
225  }
226  if (hardplot && hpdev && text && strlen(s)) {
228  IGNORE(fprintf(hpdev, "%s", s));
229  IGNORE(fflush(hpdev));
230  }
231  if (text && s == buf) {
232  plt(1, xlast, ylast-20);
233  plt(-2, 0.,0.);
234  }
235 }
236 
237 #if GRX
238 static int trcur;
239 static GrTextRegion* gtr;
240 #define GRXCOL 80
241 #define GRXROW 5
242 void grx_move(int r, int c){
243  r = r%GRXROW;
244  c = c%GRXCOL;
245  trcur = c + r*GRXCOL;
246 }
247 void grx_rel_move(int new){
248  trcur = ((int)(trcur/GRXCOL))*GRXCOL + new;
249 }
250 void grx_output_some_chars(const char* string, int count) {
251  if (string[count] == '\0') {
252  hoc_outtext(string);
253  }else{
254  hoc_outtext("non-terminated string\n");
255  }
256 }
257 void grx_delete_chars(int count) {
258  int i;
259  int j = trcur;
260  for (i=0; i < count; ++i) {
261  gtr->txr_buffer[j++] = ' ';
262  }
263  GrDumpTextRegion(gtr);
264 }
265 grx_insert_some_chars(string, count) char* string; int count; {
266  int i, j;
267  i = trcur + count;
268  j = trcur + count;
269  while(i >= trcur) {
270  gtr->txr_buffer[j--] = gtr->txr_buffer[i--];
271  }
272  i = trcur;
273  grx_output_some_chars(string, count);
274  trcur = i;
275 }
276 grx_backspace(count) int count; {
277  while (count--) {
278  trcur--;
279  }
280 }
281 grx_clear_to_eol() {
282  int j = trcur;
283  do {
284  gtr->txr_buffer[j] = ' ';
285  }while ((++j)%GRXCOL);
286  GrDumpTextRegion(gtr);
287 }
288 
289 grx_force_text() {
290  int i;
291  for (i=0; i < GRXCOL*GRXROW; ++i) {
292  gtr->txr_backup[i] = '\0';
293  }
294  GrDumpTextRegion(gtr);
295 }
296 
297 grx_txt_clear() {
298  int i;
299  if (!gtr) {
300  gtr = (GrTextRegion*)emalloc(sizeof(GrTextRegion));
301  gtr->txr_font = (GrFont*)0;
302  gtr->txr_buffer = ecalloc(GRXCOL*GRXROW, sizeof(char));
303  gtr->txr_backup = ecalloc(GRXCOL*GRXROW, sizeof(char));
304  gtr->txr_xpos = 0;
305  gtr->txr_ypos = 0;
306  gtr->txr_width = GRXCOL;
307  gtr->txr_height = GRXROW;
308  gtr->txr_lineoffset = GRXCOL;
309  gtr->txr_fgcolor.v = 7;
310  gtr->txr_bgcolor.v = 0;
311  gtr->txr_chrtype = GR_BYTE_TEXT;
312  }
313  for (i=0; i < GRXCOL*GRXROW; ++i) {
314  gtr->txr_buffer[i] = ' ';
315  }
316  trcur = 0;
317  GrDumpTextRegion(gtr);
318 }
319 
320 hoc_outtext(s) char* s; {
321  int i;
322  char* cp;
323  int ch;
324  if (!egagrph) {
325  return;
326  }
327  if (! gtr) {
328  grx_txt_clear();
329  }
330 
331  for (cp = s; *cp; ++cp) {
332  ch = *cp;
333  if (*cp == '\n' || trcur >= GRXROW*GRXCOL) {
334  char* c1, *c2;
335  int j;
336  for (i=1; i < GRXROW; ++i) {
337  c1 = gtr->txr_buffer + (i-1)*GRXCOL;
338  c2 = gtr->txr_buffer + (i)*GRXCOL;
339  for (j =0; j < GRXCOL; ++j) {
340  c1[j] = c2[j];
341  }
342  }
343  for (i=0; i < GRXCOL; ++i) {
344  c2[i] = ' ';
345  }
346  trcur = (GRXROW-1)*GRXCOL;
347  continue;
348  }
349  if (ch == '\t') {
350  ch = ' ';
351  }
352  gtr->txr_buffer[trcur++] = ch;
353  }
354  GrDumpTextRegion(gtr);
355 }
356 #endif
357 
358 void initplot(void)
359 {
360 #if !defined(__MINGW32__) /* to end of function */
361  int i;
362 #if defined (__APPLE__)
363  char** environ=(*_NSGetEnviron());
364 #endif
365 #if defined(__TURBOC__)
366  graphdev = 0;
367 #else
368 #if NeXTstep
369  graphdev = NX;
370 #else
371  graphdev = SSUN;
372  for (i = 0; environ[i] != NULL; i++)
373  {
374  if (strcmp(environ[i], vt100) == 0)
375  graphdev = VT;
376  if (strcmp(environ[i], ssun) == 0)
377  graphdev = SSUN;
378  if (strcmp(environ[i], adm3a) == 0)
379  graphdev = ADM;
380  if (strcmp(environ[i], tek4014) == 0)
381  graphdev = TEK4014;
382  if (strcmp(environ[i], ncsa) == 0)
383  graphdev = TEK4014;
384  }
385 #endif /*!NeXTstep*/
386 #endif /*!__TURBOC__*/
387  hpdev = (FILE *)0;
388  cdev = gdev = stdout;
389 #if SUNCORE
390  if (graphdev == SSUN) {
391  hoc_open_sunplot(environ);
392 #else
393 #if NeXTstep
394  /*EMPTY*/
395  if (graphdev == SSUN) {
396 #else
397 #if NRNOC_X11
398  /*EMPTY*/
399  if (graphdev == SSUN) {
400 #else
401  if (graphdev == SSUN) {
402 /*
403  if (graphdev == SSUN &&(cdev = fopen("/dev/ttyp4", "w")) == (FILE *)0) {
404  IGNORE(fprintf(stderr, "Can't open /dev/ttyp4 for TEK\n"));
405  cdev = stdout;
406 */
407 #endif /*NRNOC_X11*/
408 #endif /*NeXTstep*/
409 #endif /*SUNCORE*/
410  } else {
411  if (graphdev == TEK4014) {
412  cdev = gdev = stdout;
413  }
414  }
415 #endif /*!__MINGW32__*/
416 }
417 
418 void hoc_close_plot(void) {
419 #if DOS
420  if (egagrph) plt(-3,0.,0.);
421 #else
422 #if SUNCORE
423  hoc_close_sunplot();
424 #else
425 #if NRNOC_X11
426  x11_close_window();
427 #else
428 #if NeXTstep
429  NeXT_close_window();
430 #endif
431 #endif
432 #endif
433 #endif
434 }
435 
436 void plt(int mode, double x, double y) {
437  if (x < 0.) x = 0.;
438  if (x > 1000.) x = 1000.;
439  if (y < 0.) y = 0.;
440  if (y > 780.) y = 780.;
441  if (mode >= 0) {
442  xlast = x;
443  ylast = y;
444  }
445  if (console) {
446 #if defined(__TURBOC__)
447  if(graphdev > 0) {
448  tplt(mode, x, y);
449  } else if (graphdev == 0) {
450  Initplot();
451  tplt(mode, x, y);
452  }
453 #else
454  switch (graphdev) {
455  case SSUN:
456 #if SUNCORE
457  hoc_sunplot(&text, mode, x, y);
458  break;
459 #else
460 #if NRNOC_X11
461  hoc_x11plot(mode,x,y);
462  break;
463 #else
464 #if NeXTstep
465  break;
466  case NX:
467  hoc_NeXTplot(mode,x,y);
468  break;
469 #endif
470 #endif
471 #endif
472 #if TEK
473  case ADM:
474  case SEL:
475  case TEK4014:
476  tplot(mode, x, y);
477  break;
478 #endif
479 #if VT125
480  case VT:
481  vtplot(mode, x, y);
482  break;
483 #endif
484  }
485 #endif
486  }
487 #if HP
488  if (hardplot == 1) {
489  hplot(mode, x, y);
490  }
491 #endif
492 #if FIG
493  if (hardplot == 2) {
494  Fig_plt(mode, x, y);
495  }
496 #endif
497 #if CODRAW
498  if (hardplot == 3) {
499  Codraw_plt(mode, x, y);
500  }
501 #endif
502  if (hardplot && hpdev) {
503  IGNORE(fflush(hpdev));
504  }
505  if (console && cdev) {
506  IGNORE(fflush(cdev));
507  }
508 }
509 
510 #if TEK
511 #define XHOME 0
512 #define YHOME 770
513 
514 static void tplot(int mode, double x, double y) {
515  unsigned ix, iy;
516  int hx, hy, ly, lx;
517 
518  if (graphdev == SEL) {
519  IGNORE(putc(ESC, cdev));
520  IGNORE(putc('1', cdev));
521  }
522  if (mode < 0) {
523  switch (mode) {
524  default:
525  case -1: /* home cursor */
526  switch (graphdev) {
527  case ADM: /* to adm3a alpha mode */
528  IGNORE(putc(US, cdev));
529  IGNORE(putc(CAN, cdev));
530  break;
531  case TEK4014:
532  default:
533  IGNORE(putc(GS, cdev));
534  hy = (((YHOME & 01777) >> 5) + 32);
535  ly = ((YHOME & 037) + 96);
536  hx = (((XHOME & 01777) >> 5) + 32);
537  lx = ((XHOME & 037) + 64);
538  IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx));
539  IGNORE(putc(US, cdev));
540  break;
541  }
542  text = 0;
543  return;
544 
545  case -2: /* to 4010 alpha mode */
546  IGNORE(putc(GS, cdev));
547  IGNORE(putc(US, cdev));
548  text = 1;
549  return;
550 
551  case -3: /* erase, and go to alpha on ADM */
552  switch (graphdev) {
553  case ADM:
554  IGNORE(putc(GS, cdev));
555  IGNORE(putc(EM, cdev));
556  IGNORE(putc(US, cdev));
557  IGNORE(putc(CAN, cdev));
558  break;
559  case TEK4014:
560  default:
561  IGNORE(putc(ESC, cdev));
562  IGNORE(putc(014, cdev));
563  break;
564  }
565  text = 0;
566  return;
567  }
568  }
569  switch (mode) {
570  case 0: /* enter point mode */
571  /*IGNORE(putc(FS, cdev));
572  break;*/ /* no point mode on pure 4014 so plot vector of 0 length*/
573  case 1: /* enter vector mode */
574  IGNORE(putc(GS, cdev));
575  break;
576  }
577  iy = y;
578  ix = x;
579  hy = (((iy & 01777) >> 5) + 32);
580  ly = ((iy & 037) + 96);
581  hx = (((ix & 01777) >> 5) + 32);
582  lx = ((ix & 037) + 64);
583  IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx));
584  if (mode == 0) {
585  IGNORE(fprintf(cdev, "%c%c%c%c", hy, ly, hx, lx));
586  }
587  return;
588 }
589 
590 #endif /*TEK*/
591 
592 #if FIG || HP || CODRAW
593 
594 static char hardplot_filename[100];
595 
596 void hardplot_file(const char *s) {
597  if (hpdev) {
598  IGNORE(fclose(hpdev));
599  }
600  hpdev = (FILE *) 0;
601  hpflag = 0;
602  hardplot = 0;
603  gdev = stdout;
604  if (s) {
605  hpdev = fopen(s, "w");
606  if (hpdev) {
607  strncpy(hardplot_filename, s, 99);
608  hpflag = 1;
609  gdev = hpdev;
610  } else {
611  IGNORE(fprintf(stderr, "Can't open %s for hardplot output\n", s));
612  }
613  } else {
614  hardplot_filename[0] = '\0';
615  }
616 }
617 
618 void Fig_file(const char *s, int dev) {
619  plt(-1, 0., 0.);
620  hardplot_file(s);
621  if (!hpdev) return;
622  hardplot = dev;
623 #if FIG
624  if (hardplot == 2) {
625  Fig_preamble();
626  }
627 #endif
628 #if CODRAW
629  if (hardplot == 3) {
630  Codraw_preamble();
631  }
632 #endif
633 }
634 
635 #endif
636 
637 static char fig_text_preamble[100];
638 
639 static void hard_text_preamble(void) {
640  if (hardplot == 2) {
641  IGNORE(fprintf(hpdev, "%s", fig_text_preamble));
642  fig_text_preamble[0] = '\0';
643  }
644 }
645 
646 #if FIG
647 
648 static void Fig_preamble(void) {
649  static char fig_preamble[] = "#FIG 1.4\n80 2\n";
650 
651  if (!hpdev) return;
652  IGNORE(fprintf(hpdev, "%s", fig_preamble));
653 }
654 
655 #define HIRES 1
656 
657 void Fig_plt(int mode, double x, double y) {
658 #define SCX(x) ((int)(x*.8))
659 #define SCY(y) (600-(int)(y*.8))
660 #if HIRES
661 #define SCXD(x) ((x*.8))
662 #define SCYD(y) (7.5*80.-(y*.8))
663 #endif
664 #undef TEXT
665 #define TEXT 1
666 #define LINE1 2
667 #define LINE2 3
668  static short state = 0;
669  static double oldx, oldy;
670  static char
671  text_preamble[] = "4 0 0 16 0 0 0 0.000 1 16 40 ",
672  text_postamble[] = "\1\n",
673 #if HIRES
674  line_preamble[] = "7 1 0 1 0 0 0 0 0.000 0 0\n",
675 #else
676  line_preamble[]="2 1 0 1 0 0 0 0 0.000 0 0\n",
677 #endif
678  line_postamble[] = " 9999 9999\n";
679 
680 
681  if (!hpdev) return;
682 
683  if (state == TEXT) {
684  if (!fig_text_preamble[0]) {
685  IGNORE(fprintf(hpdev, "%s", text_postamble));
686  }
687  state = 0;
688  text = 0;
689  }
690 
691  if (mode < 0) {
692  if (state == LINE2) {
693  IGNORE(fprintf(hpdev, "%s", line_postamble));
694  }
695  text = 0;
696  state = 0;
697  if (mode == -2) {
698  IGNORE(sprintf(fig_text_preamble, "%s %d %d ",
699  text_preamble, SCX(oldx), SCY(oldy)));
700  state = TEXT;
701  text = 1;
702  return;
703  }
704  if (mode == -3) {
705 #if 0
706  IGNORE(fseek(hpdev, 0L, 0));
707  Fig_preamble();
708 #else
709  Fig_file(hardplot_filename, 2);
710 #endif
711  }
712  } else {
713  switch (mode) {
714  case 0:
715  break;
716  case 1:
717  if (state == LINE2) {
718  IGNORE(fprintf(hpdev, "%s", line_postamble));
719  }
720  state = LINE1;
721  break;
722  default:
723  if (state == LINE1) {
724 #if HIRES
725  IGNORE(fprintf(hpdev, "%s %.1f %.1f\n", line_preamble,
726  SCXD(oldx), SCYD(oldy)));
727 #else
728  IGNORE(fprintf(hpdev, "%s %d %d\n", line_preamble,
729  SCX(oldx), SCY(oldy)));
730 #endif
731  state = LINE2;
732  }
733 #if HIRES
734  IGNORE(fprintf(hpdev, " %.1f %.1f\n", SCXD(x), SCYD(y)));
735 #else
736  IGNORE(fprintf(hpdev, " %d %d\n", SCX(x), SCY(y)));
737 #endif
738  break;
739  }
740  oldx = x;
741  oldy = y;
742  }
743 }
744 
745 #endif /*FIG*/
746 
747 #if HP
748 
749 void hplot(int mode, double x, double y) {
750  static short hpflag = 0;
751  static short txt = 0;
752 
753  if (!hpdev) return;
754  if (hpflag == 0) {
755  hpflag = 1;
756  IGNORE(fprintf(hpdev, "%c.Y%c.I81;;17:%c.N;19:SC 0,1023,0,780;SP 1;",
757  ESC, ESC, ESC));
758  }
759 
760  if (txt == 1) {
761  IGNORE(fprintf(hpdev, "%c;", ETX));
762  txt = 0;
763  text = 0;
764  }
765  if (mode < 0)
766  switch (mode) {
767  case -2:
768  IGNORE(fprintf(hpdev, "LB"));
769  txt = 1;
770  text = 1;
771  return;
772 
773  case -3:
774  txt = 0;
775  text = 0;
776  hpflag = 0;
777  IGNORE(fseek(hpdev, 0L, 0));
778  return;
779  default:
780  IGNORE(fprintf(hpdev, "PU;SP;%c.Z", ESC));
781  txt = 0;
782  text = 0;
783  hpflag = 0;
784  return;
785  }
786  switch (mode) {
787  case 0:
788  IGNORE(fprintf(hpdev, "PU %8.2f,%8.2f;PD;", x, y));
789  return;
790  case 1:
791  IGNORE(fprintf(hpdev, "PU %8.2f,%8.2f;", x, y));
792  return;
793  default:
794  IGNORE(fprintf(hpdev, "PD %8.2f,%8.2f;", x, y));
795  return;
796  }
797 }
798 
799 #endif /*HP*/
800 
801 /* not modified for new method */
802 #if VT125
803 void vtplot(int mode, double x, double y)
804 {
805  static short vtgrph = 0;
806  int vtx, vty;
807 
808  if (mode < 0)
809  {
810  IGNORE(fprintf(gdev, "%c\\%c", ESC, ESC));
811  switch (mode)
812  {
813  default:
814  case -1: /* vt125 alpha mode */
815  break;
816 
817  case -2: /* graphics text mode */
818  IGNORE(fprintf(gdev, "P1pt\'"));
819  vtgrph = 2;
820  return;
821 
822  case -3: /* erase graphics */
823  IGNORE(fprintf(gdev, "P1pS(E)"));
824  break;
825 
826  case -4: /* erase text */
827  IGNORE(fprintf(gdev, "[2J"));
828  break;
829 
830  case -5: /* switch to HP plotter */
831  IGNORE(fprintf(gdev, "%c\\%c[5i", ESC, ESC)); /* esc and open port */
832  vtgrph = 0;
833  hplot(-5, 0., 0.);
834  return;
835  }
836  IGNORE(fprintf(gdev, "%c\\", ESC));
837  vtgrph = 0;
838  return;
839  }
840 
841  if (vtgrph == 2)
842  {
843  IGNORE(fprintf(gdev, "%c\\", ESC));
844  vtgrph = 0;
845  }
846  if (vtgrph == 0)
847  {
848  IGNORE(fprintf(gdev, "%cP1p", ESC));
849  vtgrph = 1;
850  }
851  vtx = (int) ((767./1023.)*x);
852  vty = (int) (479. - (479/779.)*y);
853  if (mode >= 2)
854  {
855  IGNORE(fprintf(gdev, "v[%d,%d]", vtx, vty));
856  return;
857  }
858  IGNORE(fprintf(gdev, "p[%d,%d]", vtx, vty));
859  if (mode == 0)
860  IGNORE(fprintf(gdev, "v[]"));
861  return;
862 }
863 #endif /*VT*/
864 
865 int set_color(int c) {
866  if (c >= 0 || c < 128) {
867  hoc_color = c;
868  }
869 #if defined(__TURBOC__)
870  if (egagrph) {
871  setcolor(hoc_color);
872  }
873 #else
874 #if SUNCORE
875  set_line_index(c);
876  set_text_index(c);
877 #else
878 #if NRNOC_X11
879  x11_setcolor(c);
880 #else
881 #if NeXTstep
882  NeXT_setcolor(c);
883 #endif
884 #endif
885 #endif
886 #endif
887  return (int) hoc_color;
888 }
889 
890 #if defined(__TURBOC__)
891 #define UN unsigned int
892 
893 static void tplt(int mode, double x, double y)
894 {
895 #if DOS
896  extern int newstyle;
897 #endif
898  int ix, iy;
899 
900  if (egagrph == 0)
901  {
902  setgraphmode(graphmode);
903  setcolor(hoc_color);
904  egagrph = 1;
905 #if DOS
906  newstyle = 1;
907 #endif
908  }
909 
910  if (mode < 0)
911  {
912  text = 0;
913  switch (mode)
914  {
915  default:
916  case -1:
917  if (egagrph) {
918  egagrph=1;
919  }
920  cursor(0,0);
921  break;
922 
923  case -2: /* graphics text mode */
924  egagrph=2;
925  text = 1;
926  return;
927 
928  case -3: /* erase graphics */
929  restorecrtmode();
930  egagrph = 0;
931  break;
932 #if GRX
933  case -4:
934  grx_txt_clear();
935  break;
936  case -5:
937  GrClearScreen(0);
938  grx_force_text();
939  break;
940  }
941 #endif
942  return;
943  }
944 
945  ix = ((xres -1.)/1023.)*x;
946  iy = (yres-1.) - ((yres-1.)/779.)*y;
947 
948  if (mode >= 2)
949  {
950  lineto(ix, iy);
951  }
952  if (mode == 1) {
953  moveto(ix, iy);
954  }
955  if (mode == 0)
956  {
957  moveto(ix, iy);
958  lineto(ix, iy);
959  }
960  return;
961 }
962 
963 void cursor(int r, int c) {
964 #if !defined(__GO32__)
965  int ax, dx;
966  ax = 2*256;
967  dx = (r&255)*256 + c&255;
968  _AX = ax;
969  _BX = 0;
970  _DX = dx;
971  geninterrupt(0x10);
972 #endif
973 }
974 #endif
975 
976 #if CODRAW
977 
978 #define CODRAW_MAXPOINT 200
979 static int codraw_npoint = 0;
980 static float *codraw_pointx, *codraw_pointy;
981 
982 static void codraw_line();
983 
985  static char codraw_preamble[] = "SW(1,0,8,0,8);\nST(1);\nSG(0.1);\n\
986 SF(1,'HELVET-L');\nSF(2,'HELVET');\nSF(3,'CENTURY');\nSF(4,'SCRIPT');\n\
987 SF(5,'GREEK');\nSP(1);\nLT(1);LW(1);LC(15);LD(50);\nTF(1);TW(1);TS(0);TC(15);\
988 TL(1);TV(4);TA(0);TH(0.2);\n";
989 
990  if (!hpdev) return;
991  IGNORE(fprintf(hpdev, "%s", codraw_preamble));
992  codraw_npoint = 0;
993  if (!codraw_pointy) {
994  codraw_pointx = (float *) hoc_Emalloc(CODRAW_MAXPOINT * sizeof(float));
995  codraw_pointy = (float *) hoc_Emalloc(CODRAW_MAXPOINT * sizeof(float));
996  hoc_malchk();
997  }
998 }
999 
1000 void Codraw_plt(int mode, double x, double y) {
1001 #undef SCXD
1002 #undef SCYD
1003 #define SCXD(x) ((x*.008))
1004 #define SCYD(y) ((y*.008))
1005 #undef TEXT
1006 #undef LINE1
1007 #undef LINE2
1008 #define TEXT 1
1009 #define LINE1 2
1010 #define LINE2 3
1011  static short state = 0;
1012  static double oldx, oldy;
1013 
1014  if (!hpdev) return;
1015 
1016  if (state == TEXT) {
1017  IGNORE(fprintf(hpdev, "');\n"));
1018  state = 0;
1019  text = 0;
1020  }
1021 
1022  if (mode < 0) {
1023  if (state == LINE2) {
1024  codraw_line();
1025  }
1026  text = 0;
1027  state = 0;
1028  if (mode == -2) {
1029  IGNORE(fprintf(hpdev, "TT(%.2f,%.2f,'",
1030  SCXD(oldx), SCYD(oldy)));
1031  state = TEXT;
1032  text = 1;
1033  return;
1034  }
1035  if (mode == -3) {
1036  IGNORE(fseek(hpdev, 0L, 0));
1037  Codraw_preamble();
1038  }
1039  } else {
1040  switch (mode) {
1041  case 0:
1042  break;
1043  case 1:
1044  if (state == LINE2) {
1045  codraw_line();
1046  }
1047  state = LINE1;
1048  break;
1049  default:
1050  if (state == LINE1) {
1051  codraw_npoint = 1;
1052  codraw_pointx[0] = oldx;
1053  codraw_pointy[0] = oldy;
1054  state = LINE2;
1055  }
1056  codraw_pointx[codraw_npoint] = x;
1057  codraw_pointy[codraw_npoint] = y;
1058  if (++codraw_npoint == CODRAW_MAXPOINT) {
1059  codraw_line();
1060  }
1061  break;
1062  }
1063  oldx = x;
1064  oldy = y;
1065  }
1066 }
1067 
1068 static void codraw_line() {
1069  int i;
1070 
1071  if (codraw_npoint < 2) {
1072  codraw_npoint = 0;
1073  return;
1074  }
1075  IGNORE(fprintf(hpdev, "LL(%d", codraw_npoint));
1076  for (i = 0; i < codraw_npoint; i++) {
1077  if (((i + 1) % 8) == 0) {
1078  IGNORE(fprintf(hpdev, "\n"));
1079  }
1080  IGNORE(fprintf(hpdev, ",%.2f,%.2f", SCXD(codraw_pointx[i]),
1081  SCYD(codraw_pointy[i])));
1082  }
1083  IGNORE(fprintf(hpdev, ");\n"));
1084  if (codraw_npoint == CODRAW_MAXPOINT) {
1085  codraw_npoint = 1;
1086  codraw_pointx[0] = codraw_pointx[CODRAW_MAXPOINT - 1];
1087  codraw_pointy[0] = codraw_pointy[CODRAW_MAXPOINT - 1];
1088  } else {
1089  codraw_npoint = 0;
1090  }
1091 }
1092 
1093 #endif
1094 
1095 #if NRNOC_X11
1096 extern char *getenv();
1097 static void hoc_x11plot(int mode, double x, double y)
1098 {
1099  extern int x11_init_done;
1100 
1101  if (!x11_init_done) {
1102  x11_open_window();
1103  }
1104 
1105  if (mode >= 0) {
1106  x11_coord(x, y);
1107  }
1108  if (mode > 1) {
1109  x11_vector();
1110  }else {
1111  switch (mode) {
1112  case 0:
1113  x11_point();
1114  break;
1115  case 1:
1116  x11_move();
1117  break;
1118  case -1:
1119  text = 0;
1120  x11flush();
1121  break;
1122  case -2:
1123  text = 1;
1124  break;
1125  case -3:
1126  x11_clear();
1127  break;
1128  case -4:
1129  x11_coord(x, y);
1130  x11_cleararea();
1131  break;
1132  case -5:
1133  x11_fast(1);
1134  break;
1135  case -6:
1136  x11_fast(0);
1137  }
1138  }
1139 }
1140 #endif /*NRNOC_X11*/
1141 
1142 #if NeXTstep
1143 /* extern char *getenv(); */
1144 static
1145 hoc_NeXTplot(mode, x, y)
1146  int mode;
1147  double x, y;
1148 {
1149  extern int NeXT_init_done;
1150 
1151  if (!NeXT_init_done) {
1152  NeXT_open_window();
1153  }
1154 
1155  if (mode >= 0) {
1156  NeXT_coord(x, y);
1157  }
1158  if (mode > 1) {
1159  NeXT_vector();
1160  }else {
1161  switch (mode) {
1162  case 0:
1163  NeXT_point();
1164  break;
1165  case 1:
1166  NeXT_move();
1167  break;
1168  case -1:
1169  text = 0;
1170  NeXTflush();
1171  break;
1172  case -2:
1173  text = 1;
1174  break;
1175  case -3:
1176  NeXT_clear();
1177  break;
1178  case -4:
1179  NeXT_coord(x, y);
1180  NeXT_cleararea();
1181  break;
1182  case -5:
1183  NeXT_fast(1);
1184  break;
1185  case -6:
1186  NeXT_fast(0);
1187  break;
1188  case -7:
1189  NeXT_fast(-1);
1190  break;
1191  }
1192  }
1193 }
1194 #endif /*NeXTstep*/
1195 
void hoc_close_plot(void)
Definition: plot.cpp:418
void plt(int mode, double x, double y)
Definition: plot.cpp:436
static FILE * cdev
Definition: plot.cpp:84
void * ecalloc(size_t n, size_t size)
Definition: symbol.cpp:221
#define LINE1
static void codraw_line()
Definition: plot.cpp:1068
int hoc_color
Definition: plot.cpp:106
void initplot(void)
Definition: plot.cpp:358
#define text
Definition: plot.cpp:81
#define TEK4014
Definition: plot.cpp:89
#define XHOME
Definition: plot.cpp:511
size_t size() const
Definition: ivocvect.h:43
static char fig_text_preamble[100]
Definition: plot.cpp:637
static void Fig_plt(int, double, double)
Definition: plot.cpp:657
#define ADM
Definition: plot.cpp:90
static int codraw_npoint
Definition: plot.cpp:979
size_t p
static char tek4014[]
Definition: plot.cpp:104
static int graphdev
Definition: plot.cpp:78
unsigned int text_orient
Definition: settext.cpp:10
#define YHOME
Definition: plot.cpp:512
static FILE * hpdev
Definition: plot.cpp:83
unsigned int text_style
Definition: settext.cpp:10
static void Fig_preamble(void)
Definition: plot.cpp:648
int hoc_plttext
Definition: plot.cpp:80
#define ESC
Definition: plot.cpp:98
int nrnpy_pr(const char *fmt,...)
Definition: fileio.cpp:939
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
static char adm3a[]
Definition: plot.cpp:102
static void hard_text_preamble()
Definition: plot.cpp:639
#define SCXD(x)
static char vt100[]
Definition: plot.cpp:101
#define US
Definition: plot.cpp:93
int newstyle
Definition: settext.cpp:9
#define CAN
Definition: plot.cpp:95
_CONST char * s
Definition: system.cpp:74
#define LINE2
static float * codraw_pointx
Definition: plot.cpp:980
int
Definition: nrnmusic.cpp:71
#define CODRAW_MAXPOINT
Definition: plot.cpp:978
int set_color(int c)
Definition: plot.cpp:865
#define GS
Definition: plot.cpp:94
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:741
void Fig_file(const char *, int)
Definition: plot.cpp:618
#define EM
Definition: plot.cpp:96
char * getenv(const char *s)
Definition: macprt.cpp:67
size_t j
static int hpflag
Definition: plot.cpp:79
fprintf(stderr, "Don't know the location of params at %p\, pp)
#define SSUN
Definition: plot.cpp:86
static char hardplot_filename[100]
Definition: plot.cpp:594
char * emalloc(unsigned n)
Definition: list.cpp:189
static void hplot(int, double, double)
Definition: plot.cpp:749
#define SCY(y)
#define SEL
Definition: plot.cpp:88
void hardplot_file(const char *s)
Definition: plot.cpp:596
static double ylast
Definition: plot.cpp:107
static char ncsa[]
Definition: plot.cpp:105
void hoc_malchk()
Definition: symbol.cpp:187
unsigned int text_size
Definition: settext.cpp:10
#define NX
Definition: plot.cpp:91
#define i
Definition: md1redef.h:12
#define c
static double * lx
Definition: axis.cpp:485
#define VT
Definition: plot.cpp:87
static void Codraw_plt(int, double, double)
Definition: plot.cpp:1000
static void Codraw_preamble(void)
Definition: plot.cpp:984
static FILE * gdev
Definition: plot.cpp:82
static int egagrph
Definition: fmenu.cpp:122
char buf[512]
Definition: init.cpp:13
#define ETX
Definition: plot.cpp:99
#define IGNORE(arg)
Definition: plot.cpp:10
static int hardplot
Definition: plot.cpp:77
void plprint(const char *s)
Definition: plot.cpp:168
#define TEXT
static double xlast
Definition: plot.cpp:107
static void tplot(int, double, double)
Definition: plot.cpp:514
static float * codraw_pointy
Definition: plot.cpp:980
FILE * fopen()
static int console
Definition: plot.cpp:76
return NULL
Definition: cabcode.cpp:461
static char ssun[]
Definition: plot.cpp:103
void * hoc_Emalloc(size_t size)
Definition: symbol.cpp:194
#define SCYD(y)
#define SCX(x)