PageRenderTime 29ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/bin/db/dbplotpicks/qplot.c

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