home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume24 / gnuplot3 / part21 < prev    next >
Text File  |  1991-10-28  |  49KB  |  1,735 lines

  1. Newsgroups: comp.sources.misc
  2. From: gershon%gr@cs.utah.edu (Elber Gershon)
  3. Subject:  v24i043:  gnuplot3 - interactive function plotting utility, Part21/26
  4. Message-ID: <1991Oct29.030950.4051@sparky.imd.sterling.com>
  5. X-Md4-Signature: fc51f63e22070950a7dde62c0c005b02
  6. Date: Tue, 29 Oct 1991 03:09:50 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: gershon%gr@cs.utah.edu (Elber Gershon)
  10. Posting-number: Volume 24, Issue 43
  11. Archive-name: gnuplot3/part21
  12. Environment: UNIX, MS-DOS, VMS
  13. Supersedes: gnuplot2: Volume 11, Issue 65-79
  14.  
  15. #!/bin/sh
  16. # this is Part.21 (part 21 of a multipart archive)
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file gnuplot/graph3d.c continued
  19. #
  20. if test ! -r _shar_seq_.tmp; then
  21.     echo 'Please unpack part 1 first!'
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 21; then
  26.     echo Please unpack part "$Scheck" next!
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < _shar_seq_.tmp || exit 1
  32. if test ! -f _shar_wnt_.tmp; then
  33.     echo 'x - still skipping gnuplot/graph3d.c'
  34. else
  35. echo 'x - continuing file gnuplot/graph3d.c'
  36. sed 's/^X//' << 'SHAR_EOF' >> 'gnuplot/graph3d.c' &&
  37. static double make_3dtics(tmin,tmax,axis,logscale)
  38. double tmin,tmax;
  39. int axis;
  40. BOOLEAN logscale;
  41. {
  42. int len,x1,y1,x2,y2;
  43. register double xr,xnorm,tics,tic,l10;
  44. X
  45. X    xr = fabs(tmin-tmax);
  46. X
  47. X    /* Compute length of axis in screen space coords. */
  48. X    switch (axis) {
  49. X        case 'x':
  50. X            map3d_xy(tmin,0.0,0.0,&x1,&y1);
  51. X            map3d_xy(tmax,0.0,0.0,&x2,&y2);
  52. X            break;
  53. X        case 'y':
  54. X            map3d_xy(0.0,tmin,0.0,&x1,&y1);
  55. X            map3d_xy(0.0,tmax,0.0,&x2,&y2);
  56. X            break;
  57. X        case 'z':
  58. X            map3d_xy(0.0,0.0,tmin,&x1,&y1);
  59. X            map3d_xy(0.0,0.0,tmax,&x2,&y2);
  60. X            break;
  61. X    }
  62. X
  63. X    if (((long) (x1-x2))*(x1-x2) + ((long) (y1-y2))*(y1-y2) <
  64. X        sqr(3L * term_tbl[term].h_char))
  65. X        return -1.0;                              /* No tics! */
  66. X
  67. X    l10 = log10(xr);
  68. X    if (logscale) {
  69. X        tic = dbl_raise(10.0,(l10 >= 0.0 ) ? (int)l10 : ((int)l10-1));
  70. X        if (tic < 1.0)
  71. X            tic = 1.0;
  72. X    } else {
  73. X        xnorm = pow(10.0,l10-(double)((l10 >= 0.0 ) ? (int)l10 : ((int)l10-1)));
  74. X        if (xnorm <= 5)
  75. X            tics = 0.5;
  76. X        else tics = 1.0;
  77. X        tic = tics * dbl_raise(10.0,(l10 >= 0.0 ) ? (int)l10 : ((int)l10-1));
  78. X    }
  79. X    return(tic);
  80. }
  81. X
  82. do_3dplot(plots, pcount, min_x, max_x, min_y, max_y, min_z, max_z)
  83. struct surface_points *plots;
  84. int pcount;            /* count of plots in linked list */
  85. double min_x, max_x;
  86. double min_y, max_y;
  87. double min_z, max_z;
  88. {
  89. register struct termentry *t = &term_tbl[term];
  90. register int surface, xaxis_y, yaxis_x;
  91. register struct surface_points *this_plot;
  92. int xl, yl;
  93. X            /* only a Pyramid would have this many registers! */
  94. double xtemp, ytemp, ztemp, temp;
  95. struct text_label *this_label;
  96. struct arrow_def *this_arrow;
  97. BOOLEAN scaling;
  98. transform_matrix mat;
  99. X
  100. /* Initiate transformation matrix using the global view variables. */
  101. X    mat_rot_z(surface_rot_z, trans_mat);
  102. X    mat_rot_x(surface_rot_x, mat);
  103. X    mat_mult(trans_mat, trans_mat, mat);
  104. X    mat_scale(surface_scale / 2.0, surface_scale / 2.0, surface_scale / 2.0, mat);
  105. X    mat_mult(trans_mat, trans_mat, mat);
  106. X
  107. /* modify min_z/max_z so it will zscale properly. */
  108. X    ztemp = (max_z - min_z) / (2.0 * surface_zscale);
  109. X    temp = (max_z + min_z) / 2.0;
  110. X    min_z = temp - ztemp;
  111. X    max_z = temp + ztemp;
  112. X
  113. /* store these in variables global to this file */
  114. /* otherwise, we have to pass them around a lot */
  115. X    x_min3d = min_x;
  116. X    x_max3d = max_x;
  117. X    y_min3d = min_y;
  118. X    y_max3d = max_y;
  119. X    z_min3d = min_z;
  120. X    z_max3d = max_z;
  121. X
  122. X    if (polar)
  123. X    int_error("Can not splot in polar coordinate system.", NO_CARET);
  124. X
  125. X    if (z_min3d == VERYLARGE || z_max3d == -VERYLARGE ||
  126. X    x_min3d == VERYLARGE || x_max3d == -VERYLARGE ||
  127. X    y_min3d == VERYLARGE || y_max3d == -VERYLARGE)
  128. X        int_error("all points undefined!", NO_CARET);
  129. X
  130. X    /* If we are to draw the bottom grid make sure zmin is updated properly. */
  131. X    if (xtics || ytics || grid)
  132. X    z_min3d -= (max_z - min_z) * ticslevel;
  133. X
  134. /*  This used be x_max3d == x_min3d, but that caused an infinite loop once. */
  135. X    if (fabs(x_max3d - x_min3d) < zero)
  136. X    int_error("x_min3d should not equal x_max3d!",NO_CARET);
  137. X    if (fabs(y_max3d - y_min3d) < zero)
  138. X    int_error("y_min3d should not equal y_max3d!",NO_CARET);
  139. X    if (fabs(z_max3d - z_min3d) < zero)
  140. X    int_error("z_min3d should not equal z_max3d!",NO_CARET);
  141. X
  142. /* INITIALIZE TERMINAL */
  143. X    if (!term_init) {
  144. X    (*t->init)();
  145. X    term_init = TRUE;
  146. X    }
  147. X    screen_ok = FALSE;
  148. X    scaling = (*t->scale)(xsize, ysize);
  149. X    (*t->graphics)();
  150. X
  151. X    /* now compute boundary for plot (xleft, xright, ytop, ybot) */
  152. X    boundary3d(scaling);
  153. X
  154. /* SCALE FACTORS */
  155. X    zscale3d = 2.0/(z_max3d - z_min3d);
  156. X    yscale3d = 2.0/(y_max3d - y_min3d);
  157. X    xscale3d = 2.0/(x_max3d - x_min3d);
  158. X
  159. X    (*t->linetype)(-2); /* border linetype */
  160. /* PLACE TITLE */
  161. X    if (*title != 0) {
  162. X        int x, y;
  163. X
  164. X        x = title_xoffset * t->h_char;
  165. X        y = title_yoffset * t->v_char;
  166. X
  167. X        if ((*t->justify_text)(CENTRE)) 
  168. X            (*t->put_text)(x+(xleft+xright)/2, 
  169. X                       y+ytop+(t->v_char), title);
  170. X        else
  171. X            (*t->put_text)(x+(xleft+xright)/2 - strlen(title)*(t->h_char)/2,
  172. X                       y+ytop+(t->v_char), title);
  173. X    }
  174. X
  175. /* PLACE TIMEDATE */
  176. X    if (timedate) {
  177. X        int x, y;
  178. X
  179. X        x = time_xoffset * t->h_char;
  180. X        y = time_yoffset * t->v_char;
  181. X        dated = time( (long *) 0);
  182. X        tdate = ctime( &dated);
  183. X        tdate[24]='\0';
  184. X        if ((*t->text_angle)(1)) {
  185. X            if ((*t->justify_text)(CENTRE)) {
  186. X                (*t->put_text)(x+(t->v_char),
  187. X                         y+ybot+4*(t->v_char), tdate);
  188. X            }
  189. X            else {
  190. X                (*t->put_text)(x+(t->v_char),
  191. X                         y+ybot+4*(t->v_char)-(t->h_char)*strlen(ylabel)/2, 
  192. X                         tdate);
  193. X            }
  194. X        }
  195. X        else {
  196. X            (void)(*t->justify_text)(LEFT);
  197. X            (*t->put_text)(x,
  198. X                         y+ybot-3*(t->v_char), tdate);
  199. X        }
  200. X        (void)(*t->text_angle)(0);
  201. X    }
  202. X
  203. /* PLACE LABELS */
  204. X    for (this_label = first_label; this_label!=NULL;
  205. X            this_label=this_label->next ) {
  206. X        int x,y;
  207. X
  208. X        xtemp = LogScale(this_label->x, log_x, "label", "x");
  209. X        ytemp = LogScale(this_label->y, log_y, "label", "y");
  210. X        ztemp = LogScale(this_label->z, log_z, "label", "z");
  211. X            map3d_xy(xtemp,ytemp,ztemp, &x, &y);
  212. X
  213. X        if ((*t->justify_text)(this_label->pos)) {
  214. X            (*t->put_text)(x,y,this_label->text);
  215. X        }
  216. X        else {
  217. X            switch(this_label->pos) {
  218. X                case  LEFT:
  219. X                    (*t->put_text)(x,y,this_label->text);
  220. X                    break;
  221. X                case CENTRE:
  222. X                    (*t->put_text)(x -
  223. X                        (t->h_char)*strlen(this_label->text)/2,
  224. X                        y, this_label->text);
  225. X                    break;
  226. X                case RIGHT:
  227. X                    (*t->put_text)(x -
  228. X                        (t->h_char)*strlen(this_label->text),
  229. X                        y, this_label->text);
  230. X                    break;
  231. X            }
  232. X         }
  233. X     }
  234. X
  235. /* PLACE ARROWS */
  236. X    (*t->linetype)(0);    /* arrow line type */
  237. X    for (this_arrow = first_arrow; this_arrow!=NULL;
  238. X        this_arrow = this_arrow->next ) {
  239. X    int sx,sy,ex,ey;
  240. X
  241. X    xtemp = LogScale(this_arrow->sx, log_x, "arrow", "x");
  242. X    ytemp = LogScale(this_arrow->sy, log_y, "arrow", "y");
  243. X    ztemp = LogScale(this_arrow->sz, log_y, "arrow", "z");
  244. X    map3d_xy(xtemp,ytemp,ztemp, &sx, &sy);
  245. X
  246. X    xtemp = LogScale(this_arrow->ex, log_x, "arrow", "x");
  247. X    ytemp = LogScale(this_arrow->ey, log_y, "arrow", "y");
  248. X    ztemp = LogScale(this_arrow->ez, log_y, "arrow", "z");
  249. X    map3d_xy(xtemp,ytemp,ztemp, &ex, &ey);
  250. X
  251. X    (*t->arrow)(sx, sy, ex, ey, this_arrow->head);
  252. X    }
  253. X
  254. X
  255. /* DRAW SURFACES AND CONTOURS */
  256. X    real_z_min3d = min_z;
  257. X    real_z_max3d = max_z;
  258. X    if (key == -1) {
  259. X        xl = xright  - (t->h_tic) - (t->h_char)*5;
  260. X        yl = ytop - (t->v_tic) - (t->v_char);
  261. X    }
  262. X    if (key == 1) {
  263. X        xtemp = LogScale(key_x, log_x, "key", "x");
  264. X        ytemp = LogScale(key_y, log_y, "key", "y");
  265. X        ztemp = LogScale(key_z, log_z, "key", "z");
  266. X        map3d_xy(xtemp,ytemp,ztemp, &xl, &yl);
  267. X    }
  268. X
  269. X    this_plot = plots;
  270. X    for (surface = 0;
  271. X         surface < pcount;
  272. X         this_plot = this_plot->next_sp, surface++) {
  273. X        (*t->linetype)(this_plot->line_type+1);
  274. X
  275. X        if (draw_contour && this_plot->contours != NULL) {
  276. X            struct gnuplot_contours *cntrs = this_plot->contours;
  277. X
  278. X            if (key != 0) {
  279. X                if ((*t->justify_text)(RIGHT)) {
  280. X                    clip_put_text(xl,
  281. X                        yl,this_plot->title);
  282. X                }
  283. X                else {
  284. X                    if (inrange(xl-(t->h_char)*strlen(this_plot->title), 
  285. X                             xleft, xright))
  286. X                     clip_put_text(xl-(t->h_char)*strlen(this_plot->title),
  287. X                                 yl,this_plot->title);
  288. X                }
  289. X                switch(this_plot->plot_style) {
  290. X                    case IMPULSES:
  291. X                        clip_move(xl+(t->h_char),yl);
  292. X                        clip_vector(xl+4*(t->h_char),yl);
  293. X                        break;
  294. X                    case LINES:
  295. X                        clip_move(xl+(int)(t->h_char),yl);
  296. X                        clip_vector(xl+(int)(4*(t->h_char)),yl);
  297. X                        break;
  298. X                    case ERRORBARS: /* ignored; treat like points */
  299. X                    case POINTS:
  300. X                        if (!clip_point(xl+2*(t->h_char),yl)) {
  301. X                             (*t->point)(xl+2*(t->h_char),yl,
  302. X                                    this_plot->point_type);
  303. X                        }
  304. X                        break;
  305. X                    case LINESPOINTS:
  306. X                        clip_move(xl+(int)(t->h_char),yl);
  307. X                        clip_vector(xl+(int)(4*(t->h_char)),yl);
  308. X                        break;
  309. X                    case DOTS:
  310. X                        if (!clip_point(xl+2*(t->h_char),yl)) {
  311. X                             (*t->point)(xl+2*(t->h_char),yl, -1);
  312. X                        }
  313. X                        break;
  314. X                }
  315. X            }
  316. X
  317. X            while (cntrs) {
  318. X                switch(this_plot->plot_style) {
  319. X                    case IMPULSES:
  320. X                           cntr3d_impulses(cntrs, this_plot);
  321. X                        break;
  322. X                    case LINES:
  323. X                        cntr3d_lines(cntrs);
  324. X                        break;
  325. X                    case ERRORBARS: /* ignored; treat like points */
  326. X                    case POINTS:
  327. X                        cntr3d_points(cntrs, this_plot);
  328. X                        break;
  329. X                    case LINESPOINTS:
  330. X                        cntr3d_lines(cntrs);
  331. X                        cntr3d_points(cntrs, this_plot);
  332. X                        break;
  333. X                    case DOTS:
  334. X                        cntr3d_dots(cntrs);
  335. X                        break;
  336. X                }
  337. X                cntrs = cntrs->next;
  338. X            }
  339. X            if (key != 0) yl = yl - (t->v_char);
  340. X        }
  341. X
  342. X        if ( surface == 0 )
  343. X            draw_bottom_grid(this_plot,real_z_min3d,real_z_max3d);
  344. X
  345. X        if (!draw_surface) continue;
  346. X        (*t->linetype)(this_plot->line_type);
  347. X
  348. X        if (key != 0) {
  349. X            if ((*t->justify_text)(RIGHT)) {
  350. X                clip_put_text(xl,
  351. X                    yl,this_plot->title);
  352. X            }
  353. X            else {
  354. X                if (inrange(xl-(t->h_char)*strlen(this_plot->title), 
  355. X                         xleft, xright))
  356. X                 clip_put_text(xl-(t->h_char)*strlen(this_plot->title),
  357. X                             yl,this_plot->title);
  358. X            }
  359. X        }
  360. X        switch(this_plot->plot_style) {
  361. X            case IMPULSES: {
  362. X               if (key != 0) {
  363. X                  clip_move(xl+(t->h_char),yl);
  364. X                  clip_vector(xl+4*(t->h_char),yl);
  365. X               }
  366. X               plot3d_impulses(this_plot);
  367. X               break;
  368. X            }
  369. X            case LINES: {
  370. X               if (key != 0) {
  371. X                  clip_move(xl+(int)(t->h_char),yl);
  372. X                  clip_vector(xl+(int)(4*(t->h_char)),yl);
  373. X               }
  374. X               plot3d_lines(this_plot);
  375. X               break;
  376. X            }
  377. X            case ERRORBARS:    /* ignored; treat like points */
  378. X            case POINTS: {
  379. X               if (key != 0 && !clip_point(xl+2*(t->h_char),yl)) {
  380. X                  (*t->point)(xl+2*(t->h_char),yl,
  381. X                            this_plot->point_type);
  382. X               }
  383. X               plot3d_points(this_plot);
  384. X               break;
  385. X            }
  386. X            case LINESPOINTS: {
  387. X               /* put lines */
  388. X               if (key != 0) {
  389. X                  clip_move(xl+(t->h_char),yl);
  390. X                  clip_vector(xl+4*(t->h_char),yl);
  391. X               }
  392. X               plot3d_lines(this_plot);
  393. X
  394. X               /* put points */
  395. X               if (key != 0 && !clip_point(xl+2*(t->h_char),yl)) {
  396. X                  (*t->point)(xl+2*(t->h_char),yl,
  397. X                            this_plot->point_type);
  398. X               }
  399. X               plot3d_points(this_plot);
  400. X               break;
  401. X            }
  402. X            case DOTS: {
  403. X               if (key != 0 && !clip_point(xl+2*(t->h_char),yl)) {
  404. X                  (*t->point)(xl+2*(t->h_char),yl, -1);
  405. X               }
  406. X               plot3d_dots(this_plot);
  407. X               break;
  408. X            }
  409. X        }
  410. X        yl = yl - (t->v_char);
  411. X    }
  412. X    (*t->text)();
  413. X    (void) fflush(outfile);
  414. }
  415. X
  416. /* plot3d_impulses:
  417. X * Plot the surfaces in IMPULSES style
  418. X */
  419. static plot3d_impulses(plot)
  420. X    struct surface_points *plot;
  421. {
  422. X    int i;                /* point index */
  423. X    int x,y,x0,y0;            /* point in terminal coordinates */
  424. X    struct termentry *t = &term_tbl[term];
  425. X    struct iso_curve *icrvs = plot->iso_crvs;
  426. X
  427. X    while ( icrvs ) {
  428. X    struct coordinate *points = icrvs->points;
  429. X
  430. X    for (i = 0; i < icrvs->p_count; i++) {
  431. X        if (real_z_max3d<points[i].z)
  432. X        real_z_max3d=points[i].z;
  433. X        if (real_z_min3d>points[i].z)
  434. X        real_z_min3d=points[i].z;
  435. X
  436. X        map3d_xy(points[i].x, points[i].y, points[i].z, &x, &y);
  437. X        map3d_xy(points[i].x, points[i].y, z_min3d, &x0, &y0);
  438. X
  439. X        clip_move(x0,y0);
  440. X        clip_vector(x,y);
  441. X    }
  442. X
  443. X    icrvs = icrvs->next;
  444. X    }
  445. }
  446. X
  447. /* plot3d_lines:
  448. X * Plot the surfaces in LINES style
  449. X */
  450. static plot3d_lines(plot)
  451. X    struct surface_points *plot;
  452. {
  453. X    int i;
  454. X    int x,y;                /* point in terminal coordinates */
  455. X    struct termentry *t = &term_tbl[term];
  456. X    struct iso_curve *icrvs = plot->iso_crvs;
  457. X
  458. X    while ( icrvs ) {
  459. X    struct coordinate *points = icrvs->points;
  460. X
  461. X    for (i = 0; i < icrvs->p_count; i++) {
  462. X        if (real_z_max3d<points[i].z)
  463. X        real_z_max3d=points[i].z;
  464. X        if (real_z_min3d>points[i].z)
  465. X        real_z_min3d=points[i].z;
  466. X
  467. X        map3d_xy(points[i].x, points[i].y, points[i].z, &x, &y);
  468. X
  469. X        if (i > 0)
  470. X        clip_vector(x,y);
  471. X        else
  472. X        clip_move(x,y);
  473. X    }
  474. X
  475. X    icrvs = icrvs->next;
  476. X    }
  477. }
  478. X
  479. /* plot3d_points:
  480. X * Plot the surfaces in POINTS style
  481. X */
  482. static plot3d_points(plot)
  483. X    struct surface_points *plot;
  484. {
  485. X    int i,x,y;
  486. X    struct termentry *t = &term_tbl[term];
  487. X    struct iso_curve *icrvs = plot->iso_crvs;
  488. X
  489. X    while ( icrvs ) {
  490. X    struct coordinate *points = icrvs->points;
  491. X
  492. X    for (i = 0; i < icrvs->p_count; i++) {
  493. X        if (real_z_max3d<points[i].z)
  494. X        real_z_max3d=points[i].z;
  495. X        if (real_z_min3d>points[i].z)
  496. X        real_z_min3d=points[i].z;
  497. X
  498. X        map3d_xy(points[i].x, points[i].y, points[i].z, &x, &y);
  499. X
  500. X        if (!clip_point(x,y))
  501. X        (*t->point)(x,y, plot->point_type);
  502. X    }
  503. X
  504. X    icrvs = icrvs->next;
  505. X    }
  506. }
  507. X
  508. /* plot3d_dots:
  509. X * Plot the surfaces in DOTS style
  510. X */
  511. static plot3d_dots(plot)
  512. X    struct surface_points *plot;
  513. {
  514. X    int i,x,y;
  515. X    struct termentry *t = &term_tbl[term];
  516. X    struct iso_curve *icrvs = plot->iso_crvs;
  517. X
  518. X    while ( icrvs ) {
  519. X    struct coordinate *points = icrvs->points;
  520. X
  521. X        for (i = 0; i < icrvs->p_count; i++) {
  522. X        if (real_z_max3d<points[i].z)
  523. X        real_z_max3d=points[i].z;
  524. X        if (real_z_min3d>points[i].z)
  525. X            real_z_min3d=points[i].z;
  526. X
  527. X            map3d_xy(points[i].x, points[i].y, points[i].z, &x, &y);
  528. X
  529. X            if (!clip_point(x,y))
  530. X        (*t->point)(x,y, -1);
  531. X        }
  532. X
  533. X    icrvs = icrvs->next;
  534. X    }
  535. }
  536. X
  537. /* cntr3d_impulses:
  538. X * Plot a surface contour in IMPULSES style
  539. X */
  540. static cntr3d_impulses(cntr, plot)
  541. X    struct gnuplot_contours *cntr;
  542. X    struct surface_points *plot;
  543. {
  544. X    int i,j,k;                /* point index */
  545. X    int x,y,x0,y0;            /* point in terminal coordinates */
  546. X    struct termentry *t = &term_tbl[term];
  547. X
  548. X    if (draw_contour == CONTOUR_SRF || draw_contour == CONTOUR_BOTH) {
  549. X    for (i = 0; i < cntr->num_pts; i++) {
  550. X        if (real_z_max3d<cntr->coords[i].z)
  551. X        real_z_max3d=cntr->coords[i].z;
  552. X        if (real_z_min3d>cntr->coords[i].z)
  553. X        real_z_min3d=cntr->coords[i].z;
  554. X
  555. X        map3d_xy(cntr->coords[i].x, cntr->coords[i].y, cntr->coords[i].z,
  556. X             &x, &y);
  557. X        map3d_xy(cntr->coords[i].x, cntr->coords[i].y, z_min3d,
  558. X             &x0, &y0);
  559. X
  560. X        clip_move(x0,y0);
  561. X        clip_vector(x,y);
  562. X    }
  563. X    }
  564. X    else
  565. X    cntr3d_points(cntr, plot);   /* Must be on base grid, so do points. */
  566. }
  567. X
  568. /* cntr3d_lines:
  569. X * Plot a surface contour in LINES style
  570. X */
  571. static cntr3d_lines(cntr)
  572. X    struct gnuplot_contours *cntr;
  573. {
  574. X    int i,j,k;                /* point index */
  575. X    int x,y;                /* point in terminal coordinates */
  576. X    struct termentry *t = &term_tbl[term];
  577. X
  578. X    if (draw_contour == CONTOUR_SRF || draw_contour == CONTOUR_BOTH) {
  579. X    for (i = 0; i < cntr->num_pts; i++) {
  580. X        if (real_z_max3d<cntr->coords[i].z)
  581. X        real_z_max3d=cntr->coords[i].z;
  582. X        if (real_z_min3d>cntr->coords[i].z)
  583. X        real_z_min3d=cntr->coords[i].z;
  584. X
  585. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, cntr->coords[i].z,
  586. X                 &x, &y);
  587. X
  588. X            if (i > 0)
  589. X            clip_vector(x,y);
  590. X        else
  591. X        clip_move(x,y);
  592. X        }
  593. X    }
  594. X
  595. X    if (draw_contour == CONTOUR_BASE || draw_contour == CONTOUR_BOTH) {
  596. X    for (i = 0; i < cntr->num_pts; i++) {
  597. X        if (real_z_max3d<cntr->coords[i].z)
  598. X        real_z_max3d=cntr->coords[i].z;
  599. X        if (real_z_min3d>cntr->coords[i].z)
  600. X        real_z_min3d=cntr->coords[i].z;
  601. X
  602. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, z_min3d,
  603. X                 &x, &y);
  604. X
  605. X            if (i > 0)
  606. X            clip_vector(x,y);
  607. X        else
  608. X        clip_move(x,y);
  609. X        }
  610. X    }
  611. }
  612. X
  613. /* cntr3d_points:
  614. X * Plot a surface contour in POINTS style
  615. X */
  616. static cntr3d_points(cntr, plot)
  617. X    struct gnuplot_contours *cntr;
  618. X    struct surface_points *plot;
  619. {
  620. X    int i,j,k;
  621. X    int x,y;
  622. X    struct termentry *t = &term_tbl[term];
  623. X
  624. X    if (draw_contour == CONTOUR_SRF || draw_contour == CONTOUR_BOTH) {
  625. X    for (i = 0; i < cntr->num_pts; i++) {
  626. X        if (real_z_max3d<cntr->coords[i].z)
  627. X        real_z_max3d=cntr->coords[i].z;
  628. X        if (real_z_min3d>cntr->coords[i].z)
  629. X        real_z_min3d=cntr->coords[i].z;
  630. X
  631. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, cntr->coords[i].z,
  632. X                 &x, &y);
  633. X
  634. X        if (!clip_point(x,y))
  635. X        (*t->point)(x,y, plot->point_type);
  636. X        }
  637. X    }
  638. X
  639. X    if (draw_contour == CONTOUR_BASE || draw_contour == CONTOUR_BOTH) {
  640. X    for (i = 0; i < cntr->num_pts; i++) {
  641. X        if (real_z_max3d<cntr->coords[i].z)
  642. X        real_z_max3d=cntr->coords[i].z;
  643. X        if (real_z_min3d>cntr->coords[i].z)
  644. X        real_z_min3d=cntr->coords[i].z;
  645. X
  646. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, z_min3d,
  647. X                 &x, &y);
  648. X
  649. X        if (!clip_point(x,y))
  650. X        (*t->point)(x,y, plot->point_type);
  651. X        }
  652. X    }
  653. }
  654. X
  655. /* cntr3d_dots:
  656. X * Plot a surface contour in DOTS style
  657. X */
  658. static cntr3d_dots(cntr)
  659. X    struct gnuplot_contours *cntr;
  660. {
  661. X    int i,j,k;
  662. X    int x,y;
  663. X    struct termentry *t = &term_tbl[term];
  664. X
  665. X    if (draw_contour == CONTOUR_SRF || draw_contour == CONTOUR_BOTH) {
  666. X    for (i = 0; i < cntr->num_pts; i++) {
  667. X        if (real_z_max3d<cntr->coords[i].z)
  668. X        real_z_max3d=cntr->coords[i].z;
  669. X        if (real_z_min3d>cntr->coords[i].z)
  670. X        real_z_min3d=cntr->coords[i].z;
  671. X
  672. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, cntr->coords[i].z,
  673. X                 &x, &y);
  674. X
  675. X        if (!clip_point(x,y))
  676. X        (*t->point)(x,y, -1);
  677. X        }
  678. X    }
  679. X
  680. X    if (draw_contour == CONTOUR_BASE || draw_contour == CONTOUR_BOTH) {
  681. X    for (i = 0; i < cntr->num_pts; i++) {
  682. X        if (real_z_max3d<cntr->coords[i].z)
  683. X        real_z_max3d=cntr->coords[i].z;
  684. X        if (real_z_min3d>cntr->coords[i].z)
  685. X        real_z_min3d=cntr->coords[i].z;
  686. X
  687. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, z_min3d,
  688. X                 &x, &y);
  689. X
  690. X        if (!clip_point(x,y))
  691. X        (*t->point)(x,y, -1);
  692. X        }
  693. X    }
  694. }
  695. X
  696. static update_extrema_pts(ix, iy, min_sx_x, min_sx_y, min_sy_x, min_sy_y,
  697. X              x, y)
  698. X    int ix, iy, *min_sx_x, *min_sx_y, *min_sy_x, *min_sy_y;
  699. X    double x, y;
  700. {
  701. X
  702. X    if (*min_sx_x > ix + 2 ||         /* find (bottom) left corner of grid */
  703. X    (abs(*min_sx_x - ix) <= 2 && *min_sx_y > iy)) {
  704. X    *min_sx_x = ix;
  705. X    *min_sx_y = iy;
  706. X    min_sx_ox = x;
  707. X    min_sx_oy = y;
  708. X    }
  709. X    if (*min_sy_y > iy + 2 ||         /* find bottom (right) corner of grid */
  710. X    (abs(*min_sy_y - iy) <= 2 && *min_sy_x < ix)) {
  711. X    *min_sy_x = ix;
  712. X    *min_sy_y = iy;
  713. X    min_sy_ox = x;
  714. X    min_sy_oy = y;
  715. X    }
  716. }
  717. X
  718. /* Draw the bottom grid for the parametric case. */
  719. static draw_parametric_grid(plot)
  720. X    struct surface_points *plot;
  721. {
  722. X    int i,ix,iy,            /* point in terminal coordinates */
  723. X    min_sx_x = 10000,min_sx_y = 10000,min_sy_x = 10000,min_sy_y = 10000,
  724. X        grid_iso = plot->plot_type == DATA3D && plot->has_grid_topology ?
  725. X                    plot->num_iso_read : iso_samples;
  726. X    double x,y,dx,dy;
  727. X    struct termentry *t = &term_tbl[term];
  728. X
  729. X    if (grid && plot->has_grid_topology) {
  730. X        x = x_min3d;
  731. X        y = y_min3d;
  732. X
  733. X    dx = (x_max3d-x_min3d) / (grid_iso-1);
  734. X    dy = (y_max3d-y_min3d) / (grid_iso-1);
  735. X
  736. X    for (i = 0; i < grid_iso; i++) {
  737. X            if (i == 0 || i == grid_iso-1)
  738. X            (*t->linetype)(-2);
  739. X        else
  740. X            (*t->linetype)(-1);
  741. X        map3d_xy(x_min3d, y, z_min3d, &ix, &iy);
  742. X        clip_move(ix,iy);
  743. X        update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  744. X                   &min_sy_x,&min_sy_y,x_min3d,y);
  745. X
  746. X        map3d_xy(x_max3d, y, z_min3d, &ix, &iy);
  747. X        clip_vector(ix,iy);
  748. X        update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  749. X                   &min_sy_x,&min_sy_y,x_max3d,y);
  750. X
  751. X        y += dy;
  752. X    }
  753. X
  754. X    for (i = 0; i < grid_iso; i++) {
  755. X            if (i == 0 || i == grid_iso-1)
  756. X            (*t->linetype)(-2);
  757. X        else
  758. X            (*t->linetype)(-1);
  759. X        map3d_xy(x, y_min3d, z_min3d, &ix, &iy);
  760. X        clip_move(ix,iy);
  761. X        update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  762. X                   &min_sy_x,&min_sy_y,x,y_min3d);
  763. X
  764. X        map3d_xy(x, y_max3d, z_min3d, &ix, &iy);
  765. X        clip_vector(ix,iy);
  766. X        update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  767. X                   &min_sy_x,&min_sy_y,x,y_max3d);
  768. X
  769. X        x += dx;
  770. X    }
  771. X    }
  772. X    else {
  773. X    (*t->linetype)(-2);
  774. X
  775. X    map3d_xy(x_min3d, y_min3d, z_min3d, &ix, &iy);
  776. X    clip_move(ix,iy);
  777. X    update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  778. X               &min_sy_x,&min_sy_y,x_min3d,y_min3d);
  779. X
  780. X    map3d_xy(x_max3d, y_min3d, z_min3d, &ix, &iy);
  781. X    clip_vector(ix,iy);
  782. X    update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  783. X               &min_sy_x,&min_sy_y,x_max3d,y_min3d);
  784. X
  785. X    map3d_xy(x_max3d, y_max3d, z_min3d, &ix, &iy);
  786. X    clip_vector(ix,iy);
  787. X    update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  788. X               &min_sy_x,&min_sy_y,x_max3d,y_max3d);
  789. X
  790. X    map3d_xy(x_min3d, y_max3d, z_min3d, &ix, &iy);
  791. X    clip_vector(ix,iy);
  792. X    update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  793. X               &min_sy_x,&min_sy_y,x_min3d,y_max3d);
  794. X
  795. X
  796. X    map3d_xy(x_min3d, y_min3d, z_min3d, &ix, &iy);
  797. X    clip_vector(ix,iy);
  798. X    }
  799. }
  800. X
  801. /* Draw the bottom grid for non parametric case. */
  802. static draw_non_param_grid(plot)
  803. X    struct surface_points *plot;
  804. {
  805. X    int i,is_boundary=TRUE,crv_count=0,
  806. X    x,y,                /* point in terminal coordinates */
  807. X    min_sx_x = 10000,min_sx_y = 10000,min_sy_x = 10000,min_sy_y = 10000,
  808. X        grid_samples = plot->plot_type == DATA3D && plot->has_grid_topology ?
  809. X                    plot->iso_crvs->p_count : samples,
  810. X        grid_iso = plot->plot_type == DATA3D && plot->has_grid_topology ?
  811. X                    plot->num_iso_read : iso_samples;
  812. X    struct termentry *t = &term_tbl[term];
  813. X    struct iso_curve *icrvs = plot->iso_crvs;
  814. X
  815. X    while ( icrvs ) {
  816. X    struct coordinate *points = icrvs->points;
  817. X
  818. X    for (i = 0; i < icrvs->p_count; i += icrvs->p_count-1) {
  819. X        map3d_xy(points[i].x, points[i].y, z_min3d, &x, &y);
  820. X        if (is_boundary) {
  821. X        (*t->linetype)(-2);
  822. X        }
  823. X        else {
  824. X            (*t->linetype)(-1);
  825. X        }
  826. X
  827. X        if (i > 0) {
  828. X            clip_vector(x,y);
  829. X        }
  830. X        else {
  831. X            clip_move(x,y);
  832. X        }
  833. X
  834. X        if (draw_surface &&
  835. X            is_boundary &&
  836. X            (i == 0 || i == icrvs->p_count-1)) {
  837. X            int x1,y1;            /* point in terminal coordinates */
  838. X
  839. X        /* Draw a vertical line to surface corner from grid corner. */
  840. X            map3d_xy(points[i].x, points[i].y, points[i].z, &x1, &y1);
  841. X            clip_vector(x1,y1);
  842. X            clip_move(x,y);
  843. X        update_extrema_pts(x,y,&min_sx_x,&min_sx_y, &min_sy_x,&min_sy_y,
  844. X                   points[i].x,points[i].y);
  845. X        }
  846. X    }
  847. X
  848. X    if (grid) {
  849. X        crv_count++;
  850. X        icrvs = icrvs->next;
  851. X        is_boundary = crv_count == grid_iso - 1 ||
  852. X              crv_count == grid_iso ||
  853. X              (icrvs && icrvs->next == NULL);
  854. X    }
  855. X    else {
  856. X        switch (crv_count++) {
  857. X        case 0:
  858. X            for (i = 0; i < grid_iso - 1; i++)
  859. X            icrvs = icrvs->next;
  860. X            break;
  861. X        case 1:
  862. X            icrvs = icrvs->next;
  863. X            break;
  864. X        case 2:
  865. X            while (icrvs->next)
  866. X            icrvs = icrvs->next;
  867. X            break;
  868. X        case 3:
  869. X            icrvs = NULL;
  870. X            break;
  871. X        }
  872. X        }
  873. X    }
  874. }
  875. X
  876. /* Draw the bottom grid that hold the tic marks for 3d surface. */
  877. static draw_bottom_grid(plot, min_z, max_z)
  878. X    struct surface_points *plot;
  879. X    double min_z, max_z;
  880. {
  881. X    int i,j,k;                /* point index */
  882. X    int x,y,min_x = 10000,min_y = 10000;/* point in terminal coordinates */
  883. X    double xtic,ytic,ztic;
  884. X    struct termentry *t = &term_tbl[term];
  885. X
  886. X    xtic = make_3dtics(x_min3d,x_max3d,'x',log_x);
  887. X    ytic = make_3dtics(y_min3d,y_max3d,'y',log_y);
  888. X    ztic = make_3dtics(min_z,max_z,'z',log_z);
  889. X
  890. X    if (draw_border)
  891. X    if (parametric || !plot->has_grid_topology)
  892. X        draw_parametric_grid(plot);
  893. X    else
  894. X        draw_non_param_grid(plot);
  895. X
  896. X    (*t->linetype)(-2); /* border linetype */
  897. X
  898. /* label x axis tics */
  899. X    if (xtics && xtic > 0.0) {
  900. X        switch (xticdef.type) {
  901. X            case TIC_COMPUTED:
  902. X         if (x_min3d < x_max3d)
  903. X            draw_3dxtics(xtic * floor(x_min3d/xtic),
  904. X                     xtic,
  905. X                     xtic * ceil(x_max3d/xtic),
  906. X                     min_sy_oy);
  907. X                else
  908. X            draw_3dxtics(xtic * floor(x_max3d/xtic),
  909. X                     xtic,
  910. X                     xtic * ceil(x_min3d/xtic),
  911. X                     min_sy_oy);
  912. X            break;
  913. X        case TIC_SERIES:
  914. X        draw_series_3dxtics(xticdef.def.series.start, 
  915. X                    xticdef.def.series.incr, 
  916. X                    xticdef.def.series.end,
  917. X                    min_sy_oy);
  918. X        break;
  919. X        case TIC_USER:
  920. X        draw_set_3dxtics(xticdef.def.user,
  921. X                 min_sy_oy);
  922. X        break;
  923. X            default:
  924. X            (*t->text)();
  925. X            (void) fflush(outfile);
  926. X            int_error("unknown tic type in xticdef in do_3dplot", NO_CARET);
  927. X            break;        /* NOTREACHED */
  928. X        }
  929. X    }
  930. /* label y axis tics */
  931. X    if (ytics && ytic > 0.0) {
  932. X        switch (yticdef.type) {
  933. X            case TIC_COMPUTED:
  934. X         if (y_min3d < y_max3d)
  935. X            draw_3dytics(ytic * floor(y_min3d/ytic),
  936. X                     ytic,
  937. X                     ytic * ceil(y_max3d/ytic),
  938. X                     min_sy_ox);
  939. X                else
  940. X            draw_3dytics(ytic * floor(y_max3d/ytic),
  941. X                     ytic,
  942. X                     ytic * ceil(y_min3d/ytic),
  943. X                     min_sy_ox);
  944. X            break;
  945. X        case TIC_SERIES:
  946. X        draw_series_3dytics(yticdef.def.series.start, 
  947. X                    yticdef.def.series.incr, 
  948. X                    yticdef.def.series.end,
  949. X                    min_sy_ox);
  950. X        break;
  951. X        case TIC_USER:
  952. X        draw_set_3dytics(yticdef.def.user,
  953. X                 min_sy_ox);
  954. X        break;
  955. X            default:
  956. X            (*t->text)();
  957. X            (void) fflush(outfile);
  958. X            int_error("unknown tic type in yticdef in do_3dplot", NO_CARET);
  959. X            break;        /* NOTREACHED */
  960. X        }
  961. X    }
  962. /* label z axis tics */
  963. X    if (ztics && ztic > 0.0 && (draw_surface ||
  964. X                draw_contour == CONTOUR_SRF ||
  965. X                draw_contour == CONTOUR_BOTH)) {
  966. X        switch (zticdef.type) {
  967. X            case TIC_COMPUTED:
  968. X         if (min_z < max_z)
  969. X            draw_3dztics(ztic * floor(min_z/ztic),
  970. X                     ztic,
  971. X                     ztic * ceil(max_z/ztic),
  972. X                 min_sx_ox,
  973. X                     min_sx_oy,
  974. X                     min_z,
  975. X                 max_z);
  976. X                else
  977. X            draw_3dztics(ztic * floor(max_z/ztic),
  978. X                     ztic,
  979. X                     ztic * ceil(min_z/ztic),
  980. X                     min_sx_ox,
  981. X                 min_sx_oy,
  982. X                     max_z,
  983. X                 min_z);
  984. X            break;
  985. X        case TIC_SERIES:
  986. X        draw_series_3dztics(zticdef.def.series.start, 
  987. X                    zticdef.def.series.incr, 
  988. X                    zticdef.def.series.end,
  989. X                    min_sx_ox,
  990. X                    min_sx_oy,
  991. X                    min_z,
  992. X                    max_z);
  993. X
  994. X        break;
  995. X        case TIC_USER:
  996. X        draw_set_3dztics(zticdef.def.user,
  997. X                 min_sx_ox,
  998. X                     min_sx_oy,
  999. X                     min_z,
  1000. X                 max_z);
  1001. X        break;
  1002. X            default:
  1003. X            (*t->text)();
  1004. X            (void) fflush(outfile);
  1005. X            int_error("unknown tic type in zticdef in do_3dplot", NO_CARET);
  1006. X            break;        /* NOTREACHED */
  1007. X        }
  1008. X    }
  1009. X
  1010. /* PLACE XLABEL - along the middle grid X axis */
  1011. X    if (strlen(xlabel) > 0) {
  1012. X       int x1,y1;
  1013. X       double step = apx_eq( min_sy_oy, y_min3d ) ?    (y_max3d-y_min3d)/4
  1014. X                              : (y_min3d-y_max3d)/4;
  1015. X           map3d_xy((x_min3d+x_max3d)/2,min_sy_oy-step, z_min3d,&x1,&y1);
  1016. X       x1 += xlabel_xoffset * t->h_char;
  1017. X       y1 += xlabel_yoffset * t->v_char;
  1018. X       if ((*t->justify_text)(CENTRE))
  1019. X        clip_put_text(x1,y1,xlabel);
  1020. X       else
  1021. X        clip_put_text(x1 - strlen(xlabel)*(t->h_char)/2,y1,xlabel);
  1022. X    }
  1023. X
  1024. /* PLACE YLABEL - along the middle grid Y axis */
  1025. X    if (strlen(ylabel) > 0) {
  1026. X       int x1,y1;
  1027. X       double step = apx_eq( min_sy_ox, x_min3d ) ?    (x_max3d-x_min3d)/4
  1028. X                              : (x_min3d-x_max3d)/4;
  1029. X           map3d_xy(min_sy_ox-step,(y_min3d+y_max3d)/2,z_min3d,&x1,&y1);
  1030. X       x1 += ylabel_xoffset * t->h_char;
  1031. X       y1 += ylabel_yoffset * t->v_char;
  1032. X       if ((*t->justify_text)(CENTRE))
  1033. X        clip_put_text(x1,y1,ylabel);
  1034. X       else
  1035. X        clip_put_text(x1 - strlen(ylabel)*(t->h_char)/2,y1,ylabel);
  1036. X    }
  1037. X
  1038. /* PLACE ZLABEL - along the middle grid Z axis */
  1039. X    if (strlen(zlabel) > 0 &&
  1040. X        (draw_surface ||
  1041. X     draw_contour == CONTOUR_SRF ||
  1042. X     draw_contour == CONTOUR_BOTH)) {
  1043. X           map3d_xy(min_sx_ox,min_sx_oy,max_z + (max_z-min_z)/4, &x, &y);
  1044. X
  1045. X       x += zlabel_xoffset * t->h_char;
  1046. X       y += zlabel_yoffset * t->v_char;
  1047. X       if ((*t->justify_text)(CENTRE))
  1048. X        clip_put_text(x,y,zlabel);
  1049. X       else
  1050. X        clip_put_text(x - strlen(zlabel)*(t->h_char)/2,y,zlabel);
  1051. X    }
  1052. }
  1053. X
  1054. /* DRAW_3DXTICS: draw a regular tic series, x axis */
  1055. static draw_3dxtics(start, incr, end, ypos)
  1056. X    double start, incr, end, ypos; /* tic series definition */
  1057. X        /* assume start < end, incr > 0 */
  1058. {
  1059. X    double ticplace;
  1060. X    int ltic;        /* for mini log tics */
  1061. X    double lticplace;    /* for mini log tics */
  1062. X
  1063. X    end = end + SIGNIF*incr; 
  1064. X
  1065. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  1066. X        if (ticplace < x_min3d || ticplace > x_max3d) continue;
  1067. X        xtick(ticplace, xformat, incr, 1.0, ypos);
  1068. X        if (log_x && incr == 1.0) {
  1069. X            /* add mini-ticks to log scale ticmarks */
  1070. X            for (ltic = 2; ltic <= 9; ltic++) {
  1071. X                lticplace = ticplace+log10((double)ltic);
  1072. X                xtick(lticplace, "\0", incr, 0.5, ypos);
  1073. X            }
  1074. X        }
  1075. X    }
  1076. }
  1077. X
  1078. /* DRAW_3DYTICS: draw a regular tic series, y axis */
  1079. static draw_3dytics(start, incr, end, xpos)
  1080. X    double start, incr, end, xpos; /* tic series definition */
  1081. X        /* assume start < end, incr > 0 */
  1082. {
  1083. X    double ticplace;
  1084. X    int ltic;        /* for mini log tics */
  1085. X    double lticplace;    /* for mini log tics */
  1086. X
  1087. X    end = end + SIGNIF*incr; 
  1088. X
  1089. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  1090. X        if (ticplace < y_min3d || ticplace > y_max3d) continue;
  1091. X        ytick(ticplace, yformat, incr, 1.0, xpos);
  1092. X        if (log_y && incr == 1.0) {
  1093. X            /* add mini-ticks to log scale ticmarks */
  1094. X            for (ltic = 2; ltic <= 9; ltic++) {
  1095. X                lticplace = ticplace+log10((double)ltic);
  1096. X                ytick(lticplace, "\0", incr, 0.5, xpos);
  1097. X            }
  1098. X        }
  1099. X    }
  1100. }
  1101. X
  1102. /* DRAW_3DZTICS: draw a regular tic series, z axis */
  1103. static draw_3dztics(start, incr, end, xpos, ypos, z_min, z_max)
  1104. X    double start, incr, end, xpos, ypos, z_min, z_max;
  1105. X        /* assume start < end, incr > 0 */
  1106. {
  1107. X    int x, y;
  1108. X    double ticplace;
  1109. X    int ltic;        /* for mini log tics */
  1110. X    double lticplace;    /* for mini log tics */
  1111. X    register struct termentry *t = &term_tbl[term];
  1112. X
  1113. X    end = end + SIGNIF*incr; 
  1114. X
  1115. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  1116. X        if (ticplace < z_min || ticplace > z_max) continue;
  1117. X
  1118. X        ztick(ticplace, zformat, incr, 1.0, xpos, ypos);
  1119. X        if (log_z && incr == 1.0) {
  1120. X            /* add mini-ticks to log scale ticmarks */
  1121. X            for (ltic = 2; ltic <= 9; ltic++) {
  1122. X                lticplace = ticplace+log10((double)ltic);
  1123. X                ztick(lticplace, "\0", incr, 0.5, xpos, ypos);
  1124. X            }
  1125. X        }
  1126. X    }
  1127. X
  1128. X    /* Make sure the vertical line is fully drawn. */
  1129. X    (*t->linetype)(-2);    /* axis line type */
  1130. X
  1131. X    map3d_xy(xpos, ypos, z_min3d, &x, &y);
  1132. X    clip_move(x,y);
  1133. X    map3d_xy(xpos, ypos, min(end,z_max)+(log_z ? incr : 0.0), &x, &y);
  1134. X    clip_vector(x,y);
  1135. X
  1136. X    (*t->linetype)(-1); /* border linetype */
  1137. }
  1138. X
  1139. /* DRAW_SERIES_3DXTICS: draw a user tic series, x axis */
  1140. static draw_series_3dxtics(start, incr, end, ypos)
  1141. X        double start, incr, end, ypos; /* tic series definition */
  1142. X        /* assume start < end, incr > 0 */
  1143. {
  1144. X    double ticplace, place;
  1145. X    double ticmin, ticmax;    /* for checking if tic is almost inrange */
  1146. X    double spacing = log_x ? log10(incr) : incr;
  1147. X
  1148. X    if (end == VERYLARGE)
  1149. X        end = max(CheckLog(log_x, x_min3d), CheckLog(log_x, x_max3d));
  1150. X    else
  1151. X      /* limit to right side of plot */
  1152. X      end = min(end, max(CheckLog(log_x, x_min3d), CheckLog(log_x, x_max3d)));
  1153. X
  1154. X    /* to allow for rounding errors */
  1155. X    ticmin = min(x_min3d,x_max3d) - SIGNIF*incr;
  1156. X    ticmax = max(x_min3d,x_max3d) + SIGNIF*incr;
  1157. X    end = end + SIGNIF*incr; 
  1158. X
  1159. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  1160. X        place = (log_x ? log10(ticplace) : ticplace);
  1161. X        if ( inrange(place,ticmin,ticmax) )
  1162. X         xtick(place, xformat, spacing, 1.0, ypos);
  1163. X    }
  1164. }
  1165. X
  1166. /* DRAW_SERIES_3DYTICS: draw a user tic series, y axis */
  1167. static draw_series_3dytics(start, incr, end, xpos)
  1168. X        double start, incr, end, xpos; /* tic series definition */
  1169. X        /* assume start < end, incr > 0 */
  1170. {
  1171. X    double ticplace, place;
  1172. X    double ticmin, ticmax;    /* for checking if tic is almost inrange */
  1173. X    double spacing = log_y ? log10(incr) : incr;
  1174. X
  1175. X    if (end == VERYLARGE)
  1176. X        end = max(CheckLog(log_y, y_min3d), CheckLog(log_y, y_max3d));
  1177. X    else
  1178. X      /* limit to right side of plot */
  1179. X      end = min(end, max(CheckLog(log_y, y_min3d), CheckLog(log_y, y_max3d)));
  1180. X
  1181. X    /* to allow for rounding errors */
  1182. X    ticmin = min(y_min3d,y_max3d) - SIGNIF*incr;
  1183. X    ticmax = max(y_min3d,y_max3d) + SIGNIF*incr;
  1184. X    end = end + SIGNIF*incr; 
  1185. X
  1186. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  1187. X        place = (log_y ? log10(ticplace) : ticplace);
  1188. X        if ( inrange(place,ticmin,ticmax) )
  1189. X         ytick(place, xformat, spacing, 1.0, xpos);
  1190. X    }
  1191. }
  1192. X
  1193. /* DRAW_SERIES_3DZTICS: draw a user tic series, z axis */
  1194. static draw_series_3dztics(start, incr, end, xpos, ypos, z_min, z_max)
  1195. X        double start, incr, end; /* tic series definition */
  1196. X        double xpos, ypos, z_min, z_max;
  1197. X        /* assume start < end, incr > 0 */
  1198. {
  1199. X    int x, y;
  1200. X    double ticplace, place;
  1201. X    double ticmin, ticmax;    /* for checking if tic is almost inrange */
  1202. X    double spacing = log_x ? log10(incr) : incr;
  1203. X    register struct termentry *t = &term_tbl[term];
  1204. X
  1205. X    if (end == VERYLARGE)
  1206. X        end = max(CheckLog(log_z, z_min), CheckLog(log_z, z_max));
  1207. X    else
  1208. X      /* limit to right side of plot */
  1209. X      end = min(end, max(CheckLog(log_z, z_min), CheckLog(log_z, z_max)));
  1210. X
  1211. X    /* to allow for rounding errors */
  1212. X    ticmin = min(z_min,z_max) - SIGNIF*incr;
  1213. X    ticmax = max(z_min,z_max) + SIGNIF*incr;
  1214. X    end = end + SIGNIF*incr; 
  1215. X
  1216. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  1217. X        place = (log_z ? log10(ticplace) : ticplace);
  1218. X        if ( inrange(place,ticmin,ticmax) )
  1219. X         ztick(place, zformat, spacing, 1.0, xpos, ypos);
  1220. X    }
  1221. X
  1222. X    /* Make sure the vertical line is fully drawn. */
  1223. X    (*t->linetype)(-2);    /* axis line type */
  1224. X
  1225. X    map3d_xy(xpos, ypos, z_min3d, &x, &y);
  1226. X    clip_move(x,y);
  1227. X    map3d_xy(xpos, ypos, min(end,z_max)+(log_z ? incr : 0.0), &x, &y);
  1228. X    clip_vector(x,y);
  1229. X
  1230. X    (*t->linetype)(-1); /* border linetype */
  1231. }
  1232. X
  1233. /* DRAW_SET_3DXTICS: draw a user tic set, x axis */
  1234. static draw_set_3dxtics(list, ypos)
  1235. X    struct ticmark *list;    /* list of tic marks */
  1236. X    double ypos;
  1237. {
  1238. X    double ticplace;
  1239. X    double incr = (x_max3d - x_min3d) / 10;
  1240. X    /* global x_min3d, x_max3d, xscale, y_min3d, y_max3d, yscale */
  1241. X
  1242. X    while (list != NULL) {
  1243. X       ticplace = (log_x ? log10(list->position) : list->position);
  1244. X       if ( inrange(ticplace, x_min3d, x_max3d)         /* in range */
  1245. X          || NearlyEqual(ticplace, x_min3d, incr)    /* == x_min */
  1246. X          || NearlyEqual(ticplace, x_max3d, incr))    /* == x_max */
  1247. X        xtick(ticplace, list->label, incr, 1.0, ypos);
  1248. X
  1249. X       list = list->next;
  1250. X    }
  1251. }
  1252. X
  1253. /* DRAW_SET_3DYTICS: draw a user tic set, y axis */
  1254. static draw_set_3dytics(list, xpos)
  1255. X    struct ticmark *list;    /* list of tic marks */
  1256. X    double xpos;
  1257. {
  1258. X    double ticplace;
  1259. X    double incr = (y_max3d - y_min3d) / 10;
  1260. X    /* global x_min3d, x_max3d, xscale, y_min3d, y_max3d, yscale */
  1261. X
  1262. X    while (list != NULL) {
  1263. X       ticplace = (log_y ? log10(list->position) : list->position);
  1264. X       if ( inrange(ticplace, y_min3d, y_max3d)           /* in range */
  1265. X          || NearlyEqual(ticplace, y_min3d, incr)    /* == y_min3d */
  1266. X          || NearlyEqual(ticplace, y_max3d, incr))    /* == y_max3d */
  1267. X        ytick(ticplace, list->label, incr, 1.0, xpos);
  1268. X
  1269. X       list = list->next;
  1270. X    }
  1271. }
  1272. X
  1273. /* DRAW_SET_3DZTICS: draw a user tic set, z axis */
  1274. static draw_set_3dztics(list, xpos, ypos, z_min, z_max)
  1275. X    struct ticmark *list;    /* list of tic marks */
  1276. X    double xpos, ypos, z_min, z_max;
  1277. {
  1278. X    int x, y;
  1279. X    double ticplace;
  1280. X    double incr = (z_max - z_min) / 10;
  1281. X    register struct termentry *t = &term_tbl[term];
  1282. X
  1283. X    while (list != NULL) {
  1284. X       ticplace = (log_z ? log10(list->position) : list->position);
  1285. X       if ( inrange(ticplace, z_min, z_max)         /* in range */
  1286. X          || NearlyEqual(ticplace, z_min, incr)        /* == z_min */
  1287. X          || NearlyEqual(ticplace, z_max, incr))    /* == z_max */
  1288. X        ztick(ticplace, list->label, incr, 1.0, xpos, ypos);
  1289. X
  1290. X       list = list->next;
  1291. X    }
  1292. X
  1293. X    /* Make sure the vertical line is fully drawn. */
  1294. X    (*t->linetype)(-2);    /* axis line type */
  1295. X
  1296. X    map3d_xy(xpos, ypos, z_min, &x, &y);
  1297. X    clip_move(x,y);
  1298. X    map3d_xy(xpos, ypos, z_max+(log_z ? incr : 0.0), &x, &y);
  1299. X    clip_vector(x,y);
  1300. X
  1301. X    (*t->linetype)(-1); /* border linetype */
  1302. }
  1303. X
  1304. /* draw and label a x-axis ticmark */
  1305. static xtick(place, text, spacing, ticscale, ypos)
  1306. X        double place;                   /* where on axis to put it */
  1307. X        char *text;                     /* optional text label */
  1308. X        double spacing;         /* something to use with checkzero */
  1309. X        double ticscale;         /* scale factor for tic mark (0..1] */
  1310. X    double ypos;
  1311. {
  1312. X    register struct termentry *t = &term_tbl[term];
  1313. X    char ticlabel[101];
  1314. X    int x0,y0,x1,y1,x2,y2,x3,y3;
  1315. X    int ticsize = (int)((t->h_tic) * ticscale);
  1316. X    double v[2], len;
  1317. X
  1318. X    place = CheckZero(place,spacing); /* to fix rounding error near zero */
  1319. X
  1320. X    if (place > x_max3d || place < x_min3d) return;
  1321. X
  1322. X    map3d_xy(place, ypos, z_min3d, &x0, &y0);
  1323. X    /* need to figure out which is in. pick the middle point along the */
  1324. X    /* axis as in.                               */
  1325. X    map3d_xy(place, (y_max3d + y_min3d) / 2, z_min3d, &x1, &y1);
  1326. X
  1327. X    /* compute a vector of length 1 into the grid: */
  1328. X    v[0] = x1 - x0;
  1329. X    v[1] = y1 - y0;
  1330. X    len = sqrt(v[0] * v[0] + v[1] * v[1]);
  1331. X    v[0] /= len;
  1332. X    v[1] /= len;
  1333. X
  1334. X    if (tic_in) {
  1335. X    x1 = x0;
  1336. X    y1 = y0;
  1337. X    x2 = x1 + ((int) (v[0] * ticsize));
  1338. X    y2 = y1 + ((int) (v[1] * ticsize));
  1339. X        x3 = x0 - ((int) (v[0] * ticsize * 3)); /* compute text position */
  1340. X        y3 = y0 - ((int) (v[1] * ticsize * 3));
  1341. X    } else {
  1342. X    x1 = x0;
  1343. X    y1 = y0;
  1344. X    x2 = x0 - ((int) (v[0] * ticsize));
  1345. X    y2 = y0 - ((int) (v[1] * ticsize));
  1346. X        x3 = x0 - ((int) (v[0] * ticsize * 4)); /* compute text position */
  1347. X        y3 = y0 - ((int) (v[1] * ticsize * 4));
  1348. X    }
  1349. X    clip_move(x1,y1);
  1350. X    clip_vector(x2,y2);
  1351. X
  1352. X    /* label the ticmark */
  1353. X    if (text == NULL)
  1354. X     text = xformat;
  1355. X
  1356. X    (void) sprintf(ticlabel, text, CheckLog(log_x, place));
  1357. X    if (apx_eq(v[0], 0.0)) {
  1358. X        if ((*t->justify_text)(CENTRE)) {
  1359. X            clip_put_text(x3,y3,ticlabel);
  1360. X        } else {
  1361. X            clip_put_text(x3-(t->h_char)*strlen(ticlabel)/2,y3,ticlabel);
  1362. X        }
  1363. X    }
  1364. X    else if (v[0] > 0) {
  1365. X        if ((*t->justify_text)(RIGHT)) {
  1366. X            clip_put_text(x3,y3,ticlabel);
  1367. X        } else {
  1368. X            clip_put_text(x3-(t->h_char)*strlen(ticlabel),y3,ticlabel);
  1369. X        }
  1370. X    } else {
  1371. X        (*t->justify_text)(LEFT);
  1372. X    clip_put_text(x3,y3,ticlabel);
  1373. X    }
  1374. }
  1375. X
  1376. /* draw and label a y-axis ticmark */
  1377. static ytick(place, text, spacing, ticscale, xpos)
  1378. X        double place;                   /* where on axis to put it */
  1379. X        char *text;                     /* optional text label */
  1380. X        double spacing;         /* something to use with checkzero */
  1381. X        double ticscale;         /* scale factor for tic mark (0..1] */
  1382. X    double xpos;
  1383. {
  1384. X    register struct termentry *t = &term_tbl[term];
  1385. X    char ticlabel[101];
  1386. X    int x0,y0,x1,y1,x2,y2,x3,y3;
  1387. X    int ticsize = (int)((t->h_tic) * ticscale);
  1388. X    double v[2], len;
  1389. X
  1390. X    place = CheckZero(place,spacing); /* to fix rounding error near zero */
  1391. X
  1392. X    if (place > y_max3d || place < y_min3d) return;
  1393. X
  1394. X    map3d_xy(xpos, place, z_min3d, &x0, &y0);
  1395. X    /* need to figure out which is in. pick the middle point along the */
  1396. X    /* axis as in.                               */
  1397. X    map3d_xy((x_max3d + x_min3d) / 2, place, z_min3d, &x1, &y1);
  1398. X
  1399. X    /* compute a vector of length 1 into the grid: */
  1400. X    v[0] = x1 - x0;
  1401. X    v[1] = y1 - y0;
  1402. X    len = sqrt(v[0] * v[0] + v[1] * v[1]);
  1403. X    v[0] /= len;
  1404. X    v[1] /= len;
  1405. X
  1406. X    if (tic_in) {
  1407. X    x1 = x0;
  1408. X    y1 = y0;
  1409. X    x2 = x1 + ((int) (v[0] * ticsize));
  1410. X    y2 = y1 + ((int) (v[1] * ticsize));
  1411. X        x3 = x0 - ((int) (v[0] * ticsize * 3)); /* compute text position */
  1412. X        y3 = y0 - ((int) (v[1] * ticsize * 3));
  1413. X    } else {
  1414. X    x1 = x0;
  1415. X    y1 = y0;
  1416. X    x2 = x0 - ((int) (v[0] * ticsize));
  1417. X    y2 = y0 - ((int) (v[1] * ticsize));
  1418. X        x3 = x0 - ((int) (v[0] * ticsize * 4)); /* compute text position */
  1419. X        y3 = y0 - ((int) (v[1] * ticsize * 4));
  1420. X    }
  1421. X    clip_move(x1,y1);
  1422. X    clip_vector(x2,y2);
  1423. X
  1424. X    /* label the ticmark */
  1425. X    if (text == NULL)
  1426. X     text = yformat;
  1427. X
  1428. X    (void) sprintf(ticlabel, text, CheckLog(log_y, place));
  1429. X    if (apx_eq(v[0], 0.0)) {
  1430. X        if ((*t->justify_text)(CENTRE)) {
  1431. X            clip_put_text(x3,y3,ticlabel);
  1432. X        } else {
  1433. X            clip_put_text(x3-(t->h_char)*strlen(ticlabel)/2,y3,ticlabel);
  1434. X        }
  1435. X    }
  1436. X    else if (v[0] > 0) {
  1437. X        if ((*t->justify_text)(RIGHT)) {
  1438. X            clip_put_text(x3,y3,ticlabel);
  1439. X        } else {
  1440. X            clip_put_text(x3-(t->h_char)*strlen(ticlabel),y3,ticlabel);
  1441. X        }
  1442. X    } else {
  1443. X        (*t->justify_text)(LEFT);
  1444. X    clip_put_text(x3,y3,ticlabel);
  1445. X    }
  1446. }
  1447. X
  1448. /* draw and label a z-axis ticmark */
  1449. static ztick(place, text, spacing, ticscale, xpos, ypos)
  1450. X        double place;                   /* where on axis to put it */
  1451. X        char *text;                     /* optional text label */
  1452. X        double spacing;         /* something to use with checkzero */
  1453. X        double ticscale;         /* scale factor for tic mark (0..1] */
  1454. X    double xpos, ypos;
  1455. {
  1456. X    register struct termentry *t = &term_tbl[term];
  1457. X    char ticlabel[101];
  1458. X    int x0,y0,x1,y1,x2,y2,x3,y3;
  1459. X    int ticsize = (int)((t->h_tic) * ticscale);
  1460. X
  1461. X    place = CheckZero(place,spacing); /* to fix rounding error near zero */
  1462. X
  1463. X    map3d_xy(xpos, ypos, place, &x0, &y0);
  1464. X
  1465. X    if (tic_in) {
  1466. X    x1 = x0;
  1467. X    y1 = y0;
  1468. X    x2 = x0 + ticsize;
  1469. X    y2 = y0;
  1470. X        x3 = x0 - ticsize;
  1471. X        y3 = y0;
  1472. X    } else {
  1473. X    x1 = x0;
  1474. X    y1 = y0;
  1475. X    x2 = x0 - ticsize;
  1476. X    y2 = y0;
  1477. X        x3 = x0 - ticsize * 2; /* compute text position */
  1478. X        y3 = y0;
  1479. X    }
  1480. X    clip_move(x1,y1);
  1481. X    clip_vector(x2,y2);
  1482. X
  1483. X    /* label the ticmark */
  1484. X    if (text == NULL)
  1485. X     text = zformat;
  1486. X
  1487. X    (void) sprintf(ticlabel, text, CheckLog(log_z, place));
  1488. X    if ((*t->justify_text)(RIGHT)) {
  1489. X        clip_put_text(x3,y3,ticlabel);
  1490. X    } else {
  1491. X        clip_put_text(x3-(t->h_char)*(strlen(ticlabel)+1),y3,ticlabel);
  1492. X    }
  1493. }
  1494. SHAR_EOF
  1495. echo 'File gnuplot/graph3d.c is complete' &&
  1496. chmod 0644 gnuplot/graph3d.c ||
  1497. echo 'restore of gnuplot/graph3d.c failed'
  1498. Wc_c="`wc -c < 'gnuplot/graph3d.c'`"
  1499. test 52166 -eq "$Wc_c" ||
  1500.     echo 'gnuplot/graph3d.c: original size 52166, current size' "$Wc_c"
  1501. rm -f _shar_wnt_.tmp
  1502. fi
  1503. # ============= gnuplot/makefile.vms ==============
  1504. if test -f 'gnuplot/makefile.vms' -a X"$1" != X"-c"; then
  1505.     echo 'x - skipping gnuplot/makefile.vms (File already exists)'
  1506.     rm -f _shar_wnt_.tmp
  1507. else
  1508. > _shar_wnt_.tmp
  1509. echo 'x - extracting gnuplot/makefile.vms (Text)'
  1510. sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/makefile.vms' &&
  1511. #
  1512. # GNUPLOT Makefile
  1513. # for VMS
  1514. # use with the MAKE that was posted by Tony Ivanov (tony@gvgpvd.GVG.TEK.COM)
  1515. # in comp.os.vms on 5 December 1988
  1516. #
  1517. X
  1518. # NOOP  NO Optimiser
  1519. CFLAGS = /NOOP/define=(NOGAMMA,MEMSET)
  1520. X
  1521. # /define=(<terminal>) in TERMFLAGS iff you wish to support <terminal>
  1522. # see other terminal defines in term.h
  1523. X
  1524. TERMFLAGS = 
  1525. X
  1526. OBJS =  bitmap.obj,command.obj,contour.obj,eval.obj,graphics.obj,graph3d.obj, \
  1527. X        internal.obj,misc.obj,parse.obj,plot.obj,scanner.obj,setshow.obj, \
  1528. X        standard.obj,term.obj,util.obj,version.obj
  1529. X
  1530. CSOURCE1 = command.c setshow.c 
  1531. CSOURCE2 = help.c graphics.c graph3d.c internal.c 
  1532. CSOURCE3 = misc.c eval.c parse.c plot.c scanner.c standard.c 
  1533. CSOURCE4 = bitmap.c term.c util.c version.c
  1534. CSOURCE5 = [.term]aed.trm [.term]cgi.trm [.term]dumb.trm [.term]dxf.trm [.term]dxy.trm \
  1535. X    [.term]eepic.trm [.term]epson.trm [.term]fig.trm [.term]hp26.trm \
  1536. X    [.term]hp2648.trm [.term]hpgl.trm [.term]hpljii.trm 
  1537. CSOURCE6 = [.term]impcodes.h [.term]imagen.trm [.term]object.h \
  1538. X    [.term]iris4d.trm [.term]kyo.trm [.term]latex.trm [.term]pc.trm 
  1539. CSOURCE7 = [.term]post.trm [.term]qms.trm [.term]regis.trm [.term]sun.trm \
  1540. X    [.term]t410x.trm [.term]tek.trm [.term]unixpc.trm [.term]unixplot.trm \
  1541. X    [.term]v384.trm [.term]x11.trm gnuplot_x11.c
  1542. CSOURCE8 = contour.c
  1543. X
  1544. all :   gnuplot.exe gnuplot.hlp gnuplot.hlb
  1545. X
  1546. X
  1547. gnuplot.exe : $(OBJS)
  1548. X        link /exe=gnuplot $(OBJS) ,linkopt.vms/opt
  1549. X
  1550. gnuplot.hlp : doc2hlp.exe [.docs]gnuplot.doc [.docs]doc2hlp.com
  1551. X        $$@[.docs]doc2hlp.com
  1552. X
  1553. gnuplot.hlb : gnuplot.hlp
  1554. X    library/create/help gnuplot.hlb gnuplot.hlp
  1555. X
  1556. doc2hlp.exe: [.docs]doc2hlp.c
  1557. X        cc [.docs]doc2hlp.c
  1558. X        link doc2hlp,linkopt.vms/opt
  1559. X
  1560. term.obj: term.h term.c $(CSOURCE5) $(CSOURCE6) $(CSOURCE7)
  1561. X    $(CC) $(CFLAGS) $(TERMFLAGS) term.c
  1562. X
  1563. $(OBJS): plot.h
  1564. X
  1565. command.obj help.obj misc.obj: help.h
  1566. X
  1567. command.obj graphics.obj graph3d.obj misc.obj plot.obj setshow.obj term.obj: setshow.h
  1568. X
  1569. bitmap.obj term.obj: bitmap.h
  1570. X
  1571. clean :
  1572. X        purge/log
  1573. X        del/log *.obj;*
  1574. SHAR_EOF
  1575. chmod 0644 gnuplot/makefile.vms ||
  1576. echo 'restore of gnuplot/makefile.vms failed'
  1577. Wc_c="`wc -c < 'gnuplot/makefile.vms'`"
  1578. test 1998 -eq "$Wc_c" ||
  1579.     echo 'gnuplot/makefile.vms: original size 1998, current size' "$Wc_c"
  1580. rm -f _shar_wnt_.tmp
  1581. fi
  1582. # ============= gnuplot/util.c ==============
  1583. if test -f 'gnuplot/util.c' -a X"$1" != X"-c"; then
  1584.     echo 'x - skipping gnuplot/util.c (File already exists)'
  1585.     rm -f _shar_wnt_.tmp
  1586. else
  1587. > _shar_wnt_.tmp
  1588. echo 'x - extracting gnuplot/util.c (Text)'
  1589. sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/util.c' &&
  1590. /* GNUPLOT - util.c */
  1591. /*
  1592. X * Copyright (C) 1986, 1987, 1990, 1991   Thomas Williams, Colin Kelley
  1593. X *
  1594. X * Permission to use, copy, and distribute this software and its
  1595. X * documentation for any purpose with or without fee is hereby granted, 
  1596. X * provided that the above copyright notice appear in all copies and 
  1597. X * that both that copyright notice and this permission notice appear 
  1598. X * in supporting documentation.
  1599. X *
  1600. X * Permission to modify the software is granted, but not the right to
  1601. X * distribute the modified code.  Modifications are to be distributed 
  1602. X * as patches to released version.
  1603. X *  
  1604. X * This software is provided "as is" without express or implied warranty.
  1605. X * 
  1606. X *
  1607. X * AUTHORS
  1608. X * 
  1609. X *   Original Software:
  1610. X *     Thomas Williams,  Colin Kelley.
  1611. X * 
  1612. X *   Gnuplot 2.0 additions:
  1613. X *       Russell Lang, Dave Kotz, John Campbell.
  1614. X *
  1615. X *   Gnuplot 3.0 additions:
  1616. X *       Gershon Elber and many others.
  1617. X * 
  1618. X * Send your comments or suggestions to 
  1619. X *  pixar!info-gnuplot@sun.com.
  1620. X * This is a mailing list; to join it send a note to 
  1621. X *  pixar!info-gnuplot-request@sun.com.  
  1622. X * Send bug reports to
  1623. X *  pixar!bug-gnuplot@sun.com.
  1624. X */
  1625. X
  1626. #include <ctype.h>
  1627. #include <setjmp.h>
  1628. #include <stdio.h>
  1629. #include <errno.h>
  1630. #include "plot.h"
  1631. X
  1632. BOOLEAN screen_ok;
  1633. X    /* TRUE if command just typed; becomes FALSE whenever we
  1634. X        send some other output to screen.  If FALSE, the command line
  1635. X        will be echoed to the screen before the ^ error message. */
  1636. X
  1637. #ifndef vms
  1638. #ifndef __ZTC__
  1639. extern int errno;
  1640. extern int sys_nerr;
  1641. extern char *sys_errlist[];
  1642. #endif
  1643. #endif /* vms */
  1644. X
  1645. extern char input_line[];
  1646. extern struct lexical_unit token[];
  1647. extern jmp_buf env;    /* from plot.c */
  1648. extern int inline_num;        /* from command.c */
  1649. extern BOOLEAN interactive;    /* from plot.c */
  1650. extern char *infile_name;    /* from plot.c */
  1651. X
  1652. extern char *strchr();
  1653. X
  1654. #ifndef AMIGA_AC_5
  1655. extern double sqrt(), atan2();
  1656. #endif
  1657. X
  1658. /*
  1659. X * chr_in_str() compares the characters in the string of token number t_num
  1660. X * with c, and returns TRUE if a match was found.
  1661. X */
  1662. chr_in_str(t_num, c)
  1663. int t_num;
  1664. char c;
  1665. {
  1666. register int i;
  1667. X
  1668. X    if (!token[t_num].is_token)
  1669. X        return(FALSE);                /* must be a value--can't be equal */
  1670. X    for (i = 0; i < token[t_num].length; i++) {
  1671. X        if (input_line[token[t_num].start_index+i] == c)
  1672. X            return(TRUE);
  1673. X        }
  1674. X    return FALSE;
  1675. }
  1676. X
  1677. X
  1678. /*
  1679. X * equals() compares string value of token number t_num with str[], and
  1680. X *   returns TRUE if they are identical.
  1681. X */
  1682. equals(t_num, str)
  1683. int t_num;
  1684. char *str;
  1685. {
  1686. register int i;
  1687. X
  1688. X    if (!token[t_num].is_token)
  1689. X        return(FALSE);                /* must be a value--can't be equal */
  1690. X    for (i = 0; i < token[t_num].length; i++) {
  1691. X        if (input_line[token[t_num].start_index+i] != str[i])
  1692. X            return(FALSE);
  1693. X        }
  1694. X    /* now return TRUE if at end of str[], FALSE if not */
  1695. X    return(str[i] == '\0');
  1696. }
  1697. X
  1698. X
  1699. X
  1700. /*
  1701. X * almost_equals() compares string value of token number t_num with str[], and
  1702. X *   returns TRUE if they are identical up to the first $ in str[].
  1703. X */
  1704. almost_equals(t_num, str)
  1705. int t_num;
  1706. char *str;
  1707. {
  1708. register int i;
  1709. register int after = 0;
  1710. register start = token[t_num].start_index;
  1711. register length = token[t_num].length;
  1712. X
  1713. X    if (!token[t_num].is_token)
  1714. X        return(FALSE);                /* must be a value--can't be equal */
  1715. X    for (i = 0; i < length + after; i++) {
  1716. X        if (str[i] != input_line[start + i]) {
  1717. X            if (str[i] != '$')
  1718. X                return(FALSE);
  1719. SHAR_EOF
  1720. true || echo 'restore of gnuplot/util.c failed'
  1721. fi
  1722. echo 'End of  part 21'
  1723. echo 'File gnuplot/util.c is continued in part 22'
  1724. echo 22 > _shar_seq_.tmp
  1725. exit 0
  1726.  
  1727. exit 0 # Just in case...
  1728. -- 
  1729. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1730. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1731. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1732. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1733.