/bin/db/dbheli/qplot.c

https://github.com/mattkoes/antelope_contrib · C · 727 lines · 698 code · 26 blank · 3 comment · 271 complexity · fb1f961c4b188c5a59e49a411d25e01f MD5 · raw file

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #include "qplot.h"
  5. XPoint xps[MAX_POINTS];
  6. float xpl[MAX_POINTS];
  7. float ypl[MAX_POINTS];
  8. void setdim_();
  9. void setscl_();
  10. void nplot_();
  11. QPlot *
  12. qpbin (double ts, double dt, int nsamp, float *data, double tmin, double twin, int npixels, QPlot *qpl)
  13. {
  14. double pdt, samp, dt2, dat, fsamp;
  15. int j0, j1, i, j, np, npix, ist, i2;
  16. QPlot *qov;
  17. QPlot *qpls;
  18. if (tmin > ts + dt * (nsamp - 1)) {
  19. if (qpl == NULL) return (NULL);
  20. else return (qpl);
  21. }
  22. if (tmin+twin < ts) {
  23. if (qpl == NULL) return (NULL);
  24. else return (qpl);
  25. }
  26. if (qpl == NULL) {
  27. qpls = (QPlot *) malloc (sizeof(QPlot));
  28. if (qpls == NULL) {
  29. fprintf (stderr, "qpbin: Malloc error.\n");
  30. return (NULL);
  31. }
  32. qpls->npixels = 0;
  33. qpls->min = NULL;
  34. qpls->max = NULL;
  35. qpls->in = NULL;
  36. qpls->out = NULL;
  37. qpls->numb = NULL;
  38. qpls->overlap = 0;
  39. qpls->noverlaps = 0;
  40. qpls->overlaps = NULL;
  41. qpls->min = (float *) malloc (npixels*sizeof(float));
  42. if (qpls->min == NULL) {
  43. fprintf (stderr, "qpbin: Malloc error.\n");
  44. qpfree (qpls);
  45. return (NULL);
  46. }
  47. qpls->max = (float *) malloc (npixels*sizeof(float));
  48. if (qpls->max == NULL) {
  49. fprintf (stderr, "qpbin: Malloc error.\n");
  50. qpfree (qpls);
  51. return (NULL);
  52. }
  53. qpls->in = (float *) malloc (npixels*sizeof(float));
  54. if (qpls->in == NULL) {
  55. fprintf (stderr, "qpbin: Malloc error.\n");
  56. qpfree (qpls);
  57. return (NULL);
  58. }
  59. qpls->out = (float *) malloc (npixels*sizeof(float));
  60. if (qpls->out == NULL) {
  61. fprintf (stderr, "qpbin: Malloc error.\n");
  62. qpfree (qpls);
  63. return (NULL);
  64. }
  65. qpls->numb = (int *) malloc (npixels*sizeof(int));
  66. if (qpls->numb == NULL) {
  67. fprintf (stderr, "qpbin: Malloc error.\n");
  68. qpfree (qpls);
  69. return (NULL);
  70. }
  71. for (i=0; i<npixels; i++) {
  72. qpls->min[i] = 0.0;
  73. qpls->max[i] = 0.0;
  74. qpls->in[i] = 0.0;
  75. qpls->out[i] = 0.0;
  76. qpls->numb[i] = -1;
  77. }
  78. qpls->npixels = npixels;
  79. qpls->np = 0;
  80. qpls->istart = 0;
  81. } else {
  82. qpls = qpl;
  83. }
  84. pdt = twin / (double) npixels;
  85. /* Look for overlap first. */
  86. samp = (tmin-ts) / dt;
  87. dt2 = pdt / dt;
  88. samp -= dt2;
  89. j0 = samp;
  90. if (samp < 0.0) j0--;
  91. j0++;
  92. samp += dt2;
  93. j1 = samp;
  94. np = 0;
  95. npix = 0;
  96. ist = -1;
  97. for (i=0; i<npixels; i++, samp += dt2, j0 = j1 + 1, j1 = samp) {
  98. if (samp < 0.0) j1--;
  99. if (j1 < 0) continue;
  100. if (j0 < 0) j0 = 0;
  101. if (j0 > nsamp-1) break;
  102. if (j1 > nsamp-1) j1 = nsamp - 1;
  103. if (qpls->numb[i] > -1) np++;
  104. npix++;
  105. if (ist < 0) ist = i;
  106. }
  107. if (np > 1) {
  108. if (qpls->overlaps == NULL) {
  109. qpls->overlaps = (QPlot *) malloc (sizeof(QPlot));
  110. if (qpls->overlaps == NULL) {
  111. fprintf (stderr, "qpbin: Malloc error.\n");
  112. return (NULL);
  113. }
  114. qpls->noverlaps = 1;
  115. qov = qpls->overlaps;
  116. } else {
  117. (qpls->noverlaps)++;
  118. qpls->overlaps = (QPlot *) realloc (qpls->overlaps, qpls->noverlaps*sizeof(QPlot));
  119. if (qpls->overlaps == NULL) {
  120. fprintf (stderr, "qpbin: Realloc error.\n");
  121. qpls->noverlaps = 0;
  122. return (NULL);
  123. }
  124. qov = &(qpls->overlaps[qpls->noverlaps-1]);
  125. }
  126. qov->npixels = npix;
  127. qov->np = 0;
  128. qov->istart = ist;
  129. qov->min = (float *) malloc (npix*sizeof(float));
  130. qov->max = (float *) malloc (npix*sizeof(float));
  131. qov->in = (float *) malloc (npix*sizeof(float));
  132. qov->out = (float *) malloc (npix*sizeof(float));
  133. qov->numb = (int *) malloc (npix*sizeof(int));
  134. if (qov->min == NULL || qov->max == NULL || qov->in == NULL || qov->out == NULL
  135. || qov->numb == NULL) {
  136. fprintf (stderr, "qpbin: Malloc error.\n");
  137. qpfreeoverlaps (qpls);
  138. return (NULL);
  139. }
  140. qov->overlap = 1;
  141. qov->noverlaps = 0;
  142. qov->overlaps = NULL;
  143. for (i=0; i<npix; i++) {
  144. qov->min[i] = 0.0;
  145. qov->max[i] = 0.0;
  146. qov->in[i] = 0.0;
  147. qov->out[i] = 0.0;
  148. qov->numb[i] = -1;
  149. }
  150. samp = (tmin-ts) / dt;
  151. dt2 = pdt / dt;
  152. samp -= dt2;
  153. j0 = samp;
  154. if (samp < 0.0) j0--;
  155. j0++;
  156. samp += dt2;
  157. j1 = samp;
  158. np = 0;
  159. for (i=0; i<npixels; i++, samp += dt2, j0 = j1 + 1, j1 = samp) {
  160. if (samp < 0.0) j1--;
  161. if (j1 < 0) continue;
  162. if (j0 < 0) j0 = 0;
  163. if (j0 > nsamp-1) break;
  164. if (j1 > nsamp-1) j1 = nsamp - 1;
  165. i2 = i - ist;
  166. if (j1 >= j0) {
  167. qov->numb[i2] = 1;
  168. qov->min[i2] = data[j0];
  169. qov->max[i2] = data[j0];
  170. qov->in[i2] = data[j0];
  171. qov->out[i2] = data[j1];
  172. np++;
  173. } else {
  174. if (i == 0 || i == npixels-1) {
  175. fsamp = samp - ((int)samp);
  176. dat = data[j1] + (data[j0]-data[j1])*fsamp;
  177. qov->numb[i2] = 1;
  178. qov->min[i2] = dat;
  179. qov->max[i2] = dat;
  180. qov->in[i2] = dat;
  181. qov->out[i2] = dat;
  182. np++;
  183. } else {
  184. qov->numb[i2] = 0;
  185. qov->min[i2] = 0.0;
  186. qov->max[i2] = 0.0;
  187. qov->in[i2] = 0.0;
  188. qov->out[i2] = 0.0;
  189. }
  190. }
  191. for (j=j0+1; j<=j1; j++) {
  192. if (data[j] > qov->max[i2]) qov->max[i2] = data[j];
  193. if (data[j] < qov->min[i2]) qov->min[i2] = data[j];
  194. qov->numb[i2]++;
  195. np++;
  196. }
  197. }
  198. qov->np += np;
  199. return (qpls);
  200. }
  201. /* Now bin out segment. */
  202. samp = (tmin-ts) / dt;
  203. dt2 = pdt / dt;
  204. samp -= dt2;
  205. j0 = samp;
  206. if (samp < 0.0) j0--;
  207. j0++;
  208. samp += dt2;
  209. j1 = samp;
  210. np = 0;
  211. for (i=0; i<npixels; i++, samp += dt2, j0 = j1 + 1, j1 = samp) {
  212. if (samp < 0.0) j1--;
  213. if (j1 < 0) continue;
  214. if (j0 < 0) j0 = 0;
  215. if (j0 > nsamp-1) break;
  216. if (j1 > nsamp-1) j1 = nsamp - 1;
  217. if (j1 >= j0) {
  218. qpls->numb[i] = 1;
  219. qpls->min[i] = data[j0];
  220. qpls->max[i] = data[j0];
  221. qpls->in[i] = data[j0];
  222. qpls->out[i] = data[j1];
  223. np++;
  224. } else {
  225. if (i == 0 || i == npixels-1) {
  226. fsamp = samp - ((int)samp);
  227. dat = data[j1] + (data[j0]-data[j1])*fsamp;
  228. qpls->numb[i] = 1;
  229. qpls->min[i] = dat;
  230. qpls->max[i] = dat;
  231. qpls->in[i] = dat;
  232. qpls->out[i] = dat;
  233. np++;
  234. } else {
  235. qpls->numb[i] = 0;
  236. qpls->min[i] = 0.0;
  237. qpls->max[i] = 0.0;
  238. qpls->in[i] = 0.0;
  239. qpls->out[i] = 0.0;
  240. }
  241. }
  242. for (j=j0+1; j<=j1; j++) {
  243. if (data[j] > qpls->max[i]) qpls->max[i] = data[j];
  244. if (data[j] < qpls->min[i]) qpls->min[i] = data[j];
  245. qpls->numb[i]++;
  246. np++;
  247. }
  248. }
  249. qpls->np += np;
  250. return (qpls);
  251. }
  252. int
  253. qpfree (QPlot *qpl)
  254. {
  255. if (!qpl) return(0);
  256. qpfreeoverlaps (qpl);
  257. if (qpl->min) free (qpl->min);
  258. if (qpl->max) free (qpl->max);
  259. if (qpl->in) free (qpl->in);
  260. if (qpl->out) free (qpl->out);
  261. if (qpl->numb) free (qpl->numb);
  262. free (qpl);
  263. return (0);
  264. }
  265. int
  266. qpfreeoverlaps (QPlot *qpl)
  267. {
  268. int i;
  269. if (!qpl) return(0);
  270. if (!qpl->overlaps) return(0);
  271. for (i=0; i<qpl->noverlaps; i++) {
  272. if (qpl->overlaps[i].min) free (qpl->overlaps[i].min);
  273. if (qpl->overlaps[i].max) free (qpl->overlaps[i].max);
  274. if (qpl->overlaps[i].in) free (qpl->overlaps[i].in);
  275. if (qpl->overlaps[i].out) free (qpl->overlaps[i].out);
  276. if (qpl->overlaps[i].numb) free (qpl->overlaps[i].numb);
  277. }
  278. free (qpl->overlaps);
  279. qpl->overlaps = NULL;
  280. qpl->noverlaps = 0;
  281. return (0);
  282. }
  283. int
  284. qplot (double ts, double dt, int nsamp, float *data, double tmin, double twin, int npixels, int x, int y, int h, float *ybot, float *ytop,
  285. int scale_type, float ygain, XPoint **xp)
  286. {
  287. float *min, *max, *in, *out;
  288. int *numb;
  289. QPlot *qpl;
  290. int i, n;
  291. float dfmintot, dfmaxtot;
  292. float center, ytp;
  293. float scale;
  294. QPlot *qpbin();
  295. qpl = NULL;
  296. qpl = qpbin (ts, dt, nsamp, data, tmin, twin, npixels, qpl);
  297. if (qpl == NULL) return (0);
  298. n = qpl->np;
  299. if (n < 1) {
  300. qpfree (qpl);
  301. return (0);
  302. }
  303. min = qpl->min;
  304. max = qpl->max;
  305. in = qpl->in;
  306. out = qpl->out;
  307. numb = qpl->numb;
  308. switch (scale_type) {
  309. case QPL_SCALE_FIXED:
  310. for (i = 0, n = 0; i<npixels; i++) {
  311. if (numb[i] == 1) {
  312. n++;
  313. } else if (numb[i] > 1) {
  314. n += 4;
  315. }
  316. }
  317. if (n == 0) {
  318. qpfree (qpl);
  319. return (0);
  320. }
  321. scale = (float) h / (*ybot - *ytop);
  322. break;
  323. case QPL_SCALE_AUTO:
  324. case QPL_SCALE_AUTO0:
  325. for (i = 0, n = 0; i<npixels; i++) {
  326. if (numb[i] == 1) {
  327. if (n == 0) {
  328. dfmintot = min[i];
  329. dfmaxtot = max[i];
  330. } else {
  331. if (min[i] < dfmintot)
  332. dfmintot = min[i];
  333. if (max[i] > dfmaxtot)
  334. dfmaxtot = max[i];
  335. }
  336. n++;
  337. } else if (numb[i] > 1) {
  338. if (n == 0) {
  339. dfmintot = min[i];
  340. dfmaxtot = max[i];
  341. } else {
  342. if (min[i] < dfmintot)
  343. dfmintot = min[i];
  344. if (max[i] > dfmaxtot)
  345. dfmaxtot = max[i];
  346. }
  347. n += 4;
  348. }
  349. }
  350. if (n == 0) {
  351. qpfree (qpl);
  352. return (0);
  353. }
  354. if (scale_type == QPL_SCALE_AUTO0) {
  355. if (dfmaxtot < 0) dfmaxtot = -dfmaxtot;
  356. if (dfmintot < 0) dfmintot = -dfmintot;
  357. if (dfmintot > dfmaxtot) dfmaxtot = dfmintot;
  358. *ytop = dfmaxtot;
  359. *ybot = -dfmaxtot;
  360. } else {
  361. *ytop = dfmaxtot;
  362. *ybot = dfmintot;
  363. }
  364. if (*ybot == *ytop) {
  365. *ytop += 0.5;
  366. *ybot -= 0.5;
  367. }
  368. scale = (float) h / (*ybot - *ytop);
  369. break;
  370. default:
  371. qpfree (qpl);
  372. return (0);
  373. }
  374. if (n > MAX_POINTS) {
  375. fprintf (stderr, "qplot: Attempt to exceed MAX_POINTS.\n");
  376. qpfree (qpl);
  377. return (0);
  378. }
  379. n = 0;
  380. center = (*ybot + *ytop) * 0.5;
  381. ytp = center - (center - *ytop) / ygain;
  382. scale *= ygain;
  383. for (i=0; i<npixels; i++) {
  384. if (numb[i] == 1) {
  385. xps[n].x = (short) (i + x);
  386. xps[n].y = (short) (scale*(in[i]-ytp) + y);
  387. n++;
  388. } else if (numb[i] > 1) {
  389. xps[n].x = (short) (i + x);
  390. xps[n].y = (short) (scale*(in[i]-ytp) + y);
  391. n++;
  392. xps[n].x = xps[n-1].x;
  393. xps[n].y = (short) (scale*(min[i]-ytp) + y);
  394. if (xps[n].y != xps[n-1].y) n++;
  395. xps[n].x = xps[n-1].x;
  396. xps[n].y = (short) (scale*(max[i]-ytp) + y);
  397. if (xps[n].y != xps[n-1].y) n++;
  398. xps[n].x = xps[n-1].x;
  399. xps[n].y = (short) (scale*(out[i]-ytp) + y);
  400. if (xps[n].y != xps[n-1].y) n++;
  401. }
  402. }
  403. *xp = xps;
  404. qpfree (qpl);
  405. return (n);
  406. }
  407. int
  408. qplotsegs (QPlot *qpl, int x, int y, int h, float *ybot, float *ytop, int scale_type, float ygain, Display *display, Drawable drawable, GC gc, GC gcov)
  409. {
  410. float *min, *max, *in, *out;
  411. int *numb;
  412. int npixels;
  413. int i, j, n, ntot;
  414. float dfmintot, dfmaxtot;
  415. float center, ytp;
  416. float scale;
  417. int iepoch, iepoch0;
  418. GC gcl;
  419. if (qpl == NULL) return (0);
  420. n = qpl->np;
  421. if (n < 1) return (0);
  422. npixels = qpl->npixels;
  423. if (npixels < 2) return (0);
  424. if (!qpl->overlap) {
  425. gcl = gc;
  426. } else {
  427. gcl = gcov;
  428. }
  429. min = qpl->min;
  430. max = qpl->max;
  431. in = qpl->in;
  432. out = qpl->out;
  433. numb = qpl->numb;
  434. switch (scale_type) {
  435. case QPL_SCALE_FIXED:
  436. for (i = 0, n = 0; i<npixels; i++) {
  437. if (numb[i] == 1) {
  438. n++;
  439. } else if (numb[i] > 1) {
  440. n += 4;
  441. }
  442. }
  443. if (n == 0) return (0);
  444. scale = (float) h / (*ybot - *ytop);
  445. break;
  446. case QPL_SCALE_AUTO:
  447. case QPL_SCALE_AUTO0:
  448. for (i = 0,n = 0; i<npixels; i++) {
  449. if (numb[i] == 1) {
  450. if (n == 0) {
  451. dfmintot = min[i];
  452. dfmaxtot = max[i];
  453. } else {
  454. if (min[i] < dfmintot)
  455. dfmintot = min[i];
  456. if (max[i] > dfmaxtot)
  457. dfmaxtot = max[i];
  458. }
  459. n++;
  460. } else if (numb[i] > 1) {
  461. if (n == 0) {
  462. dfmintot = min[i];
  463. dfmaxtot = max[i];
  464. } else {
  465. if (min[i] < dfmintot)
  466. dfmintot = min[i];
  467. if (max[i] > dfmaxtot)
  468. dfmaxtot = max[i];
  469. }
  470. n += 4;
  471. }
  472. }
  473. for (j=0; j<qpl->noverlaps; j++) {
  474. for (i = 0; i<qpl->overlaps[j].npixels; i++) {
  475. if (qpl->overlaps[j].min[i] < dfmintot)
  476. dfmintot = qpl->overlaps[j].min[i];
  477. if (qpl->overlaps[j].max[i] > dfmaxtot)
  478. dfmaxtot = qpl->overlaps[j].max[i];
  479. }
  480. }
  481. if (n == 0) return 0;
  482. if (scale_type == QPL_SCALE_AUTO0) {
  483. if (dfmaxtot < 0) dfmaxtot = -dfmaxtot;
  484. if (dfmintot < 0) dfmintot = -dfmintot;
  485. if (dfmintot > dfmaxtot) dfmaxtot = dfmintot;
  486. *ytop = dfmaxtot;
  487. *ybot = -dfmaxtot;
  488. } else {
  489. *ytop = dfmaxtot;
  490. *ybot = dfmintot;
  491. }
  492. if (*ybot == *ytop) {
  493. *ytop += 0.5;
  494. *ybot -= 0.5;
  495. }
  496. scale = (float) h / (*ybot - *ytop);
  497. break;
  498. default:
  499. return (0);
  500. }
  501. if (n > MAX_POINTS) {
  502. fprintf (stderr, "qplotsegs: Attempt to exceed MAX_POINTS.\n");
  503. return (0);
  504. }
  505. n = 0;
  506. ntot = 0;
  507. center = (*ybot + *ytop) * 0.5;
  508. ytp = center - (center - *ytop) / ygain;
  509. scale *= ygain;
  510. x += qpl->istart;
  511. iepoch0 = time(NULL);
  512. for (i=0; i<npixels; i++) {
  513. if (numb[i] == 1) {
  514. xps[n].x = (short) (i + x);
  515. xps[n].y = (short) (scale*(in[i]-ytp) + y);
  516. n++;
  517. } else if (numb[i] > 1) {
  518. xps[n].x = (short) (i + x);
  519. xps[n].y = (short) (scale*(in[i]-ytp) + y);
  520. n++;
  521. xps[n].x = xps[n-1].x;
  522. xps[n].y = (short) (scale*(min[i]-ytp) + y);
  523. if (xps[n].y != xps[n-1].y) n++;
  524. xps[n].x = xps[n-1].x;
  525. xps[n].y = (short) (scale*(max[i]-ytp) + y);
  526. if (xps[n].y != xps[n-1].y) n++;
  527. xps[n].x = xps[n-1].x;
  528. xps[n].y = (short) (scale*(out[i]-ytp) + y);
  529. if (xps[n].y != xps[n-1].y) n++;
  530. } else if (numb[i] < 0) {
  531. if (n > 0) {
  532. ntot += n;
  533. if (n > 1) XDrawLines (display, drawable, gcl,
  534. xps, n,CoordModeOrigin);
  535. n = 0;
  536. }
  537. }
  538. iepoch = time(NULL);
  539. }
  540. if (n > 0) {
  541. ntot += n;
  542. if (n > 1) XDrawLines (display, drawable, gcl, xps,
  543. n, CoordModeOrigin);
  544. }
  545. for (i=0; i<qpl->noverlaps; i++) {
  546. ntot += qplotsegs (&(qpl->overlaps[i]), x, y, h, ybot, ytop, QPL_SCALE_FIXED,
  547. ygain, display, drawable, gc, gcov);
  548. }
  549. return (ntot);
  550. }
  551. int
  552. nqplotsegs (QPlot *qpl, float xdim, float ydim, float xlow, float ylow, float *ybot, float *ytop, int scale_type, int iclip, float ygain)
  553. {
  554. float *min, *max, *in, *out;
  555. int *numb;
  556. int npixels;
  557. int i, j, n, ntot;
  558. float dfmintot, dfmaxtot;
  559. float center;
  560. int igraf = 0;
  561. int ithick = 0;
  562. float thick = 0.0;
  563. static char asymb[] = " ";
  564. static float xmin, xmax, ymin, ymax;
  565. static float xdm, ydm, xlw, ylw;
  566. static int nnpixels;
  567. if (qpl == NULL) return (0);
  568. n = qpl->np;
  569. if (n < 1) return (0);
  570. npixels = qpl->npixels;
  571. if (npixels < 2) return (0);
  572. if (!qpl->overlap) nnpixels = npixels;
  573. min = qpl->min;
  574. max = qpl->max;
  575. in = qpl->in;
  576. out = qpl->out;
  577. numb = qpl->numb;
  578. switch (scale_type) {
  579. case QPL_SCALE_FIXED:
  580. for (i = 0, n = 0; i<npixels; i++) {
  581. if (numb[i] == 1) {
  582. n++;
  583. } else if (numb[i] > 1) {
  584. n += 4;
  585. }
  586. }
  587. if (n == 0) return (0);
  588. break;
  589. case QPL_SCALE_AUTO:
  590. case QPL_SCALE_AUTO0:
  591. for (i = 0,n = 0; i<npixels; i++) {
  592. if (numb[i] == 1) {
  593. if (n == 0) {
  594. dfmintot = min[i];
  595. dfmaxtot = max[i];
  596. } else {
  597. if (min[i] < dfmintot)
  598. dfmintot = min[i];
  599. if (max[i] > dfmaxtot)
  600. dfmaxtot = max[i];
  601. }
  602. n++;
  603. } else if (numb[i] > 1) {
  604. if (n == 0) {
  605. dfmintot = min[i];
  606. dfmaxtot = max[i];
  607. } else {
  608. if (min[i] < dfmintot)
  609. dfmintot = min[i];
  610. if (max[i] > dfmaxtot)
  611. dfmaxtot = max[i];
  612. }
  613. n += 4;
  614. }
  615. }
  616. for (j=0; j<qpl->noverlaps; j++) {
  617. for (i = 0; i<qpl->overlaps[j].npixels; i++) {
  618. if (qpl->overlaps[j].min[i] < dfmintot)
  619. dfmintot = qpl->overlaps[j].min[i];
  620. if (qpl->overlaps[j].max[i] > dfmaxtot)
  621. dfmaxtot = qpl->overlaps[j].max[i];
  622. }
  623. }
  624. if (n == 0) return 0;
  625. if (scale_type == QPL_SCALE_AUTO0) {
  626. if (dfmaxtot < 0) dfmaxtot = -dfmaxtot;
  627. if (dfmintot < 0) dfmintot = -dfmintot;
  628. if (dfmintot > dfmaxtot) dfmaxtot = dfmintot;
  629. *ytop = dfmaxtot;
  630. *ybot = -dfmaxtot;
  631. } else {
  632. *ytop = dfmaxtot;
  633. *ybot = dfmintot;
  634. }
  635. if (*ybot == *ytop) {
  636. *ytop += 0.5;
  637. *ybot -= 0.5;
  638. }
  639. break;
  640. default:
  641. return (0);
  642. }
  643. if (n > MAX_POINTS) {
  644. fprintf (stderr, "qplotsegs: Attempt to exceed MAX_POINTS.\n");
  645. return (0);
  646. }
  647. n = 0;
  648. ntot = 0;
  649. center = (*ybot + *ytop) * 0.5;
  650. ymax = center + (*ytop - center) / ygain;
  651. ymin = center - (center - *ybot) / ygain;
  652. xmin = 0.0;
  653. xmax = nnpixels-1;
  654. xdm = xdim;
  655. ydm = ydim;
  656. xlw = xlow;
  657. ylw = ylow;
  658. setdim_ (&xdm, &ydm, &xlw, &ylw);
  659. setscl_ (&xmin, &xmax, &ymin, &ymax);
  660. for (i=0; i<npixels; i++) {
  661. if (numb[i] == 1) {
  662. xpl[n] = (i + qpl->istart);
  663. ypl[n] = in[i];
  664. n++;
  665. } else if (numb[i] > 1) {
  666. xpl[n] = (i + qpl->istart);
  667. ypl[n] = in[i];
  668. n++;
  669. xpl[n] = xpl[n-1];
  670. ypl[n] = min[i];
  671. if (ypl[n] != ypl[n-1]) n++;
  672. xpl[n] = xpl[n-1];
  673. ypl[n] = max[i];
  674. if (ypl[n] != ypl[n-1]) n++;
  675. xpl[n] = xpl[n-1];
  676. ypl[n] = out[i];
  677. if (ypl[n] != ypl[n-1]) n++;
  678. } else if (numb[i] < 0) {
  679. if (n > 0) {
  680. ntot += n;
  681. if (n > 1) {
  682. nplot_ (&n, xpl, ypl, &igraf, &iclip, &thick, &ithick,
  683. asymb, strlen(asymb));
  684. }
  685. n = 0;
  686. }
  687. }
  688. }
  689. if (n > 0) {
  690. ntot += n;
  691. if (n > 1) {
  692. nplot_ (&n, xpl, ypl, &igraf, &iclip, &thick, &ithick,
  693. asymb, strlen(asymb));
  694. }
  695. }
  696. for (i=0; i<qpl->noverlaps; i++) {
  697. ntot += nqplotsegs (&(qpl->overlaps[i]), xdim, ydim, xlow, ylow, ybot, ytop, QPL_SCALE_FIXED, iclip, ygain);
  698. }
  699. return (ntot);
  700. }
  701. /* $Id$ */