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