Leptonica  1.73
Image processing and image analysis suite
gplot.c
Go to the documentation of this file.
1 /*====================================================================*
2  - Copyright (C) 2001 Leptonica. All rights reserved.
3  -
4  - Redistribution and use in source and binary forms, with or without
5  - modification, are permitted provided that the following conditions
6  - are met:
7  - 1. Redistributions of source code must retain the above copyright
8  - notice, this list of conditions and the following disclaimer.
9  - 2. Redistributions in binary form must reproduce the above
10  - copyright notice, this list of conditions and the following
11  - disclaimer in the documentation and/or other materials
12  - provided with the distribution.
13  -
14  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18  - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *====================================================================*/
26 
100 #include <string.h>
101 #include "allheaders.h"
102 
103 static const l_int32 L_BUFSIZE = 512; /* hardcoded below in fscanf */
104 
105 const char *gplotstylenames[] = {"with lines",
106  "with points",
107  "with impulses",
108  "with linespoints",
109  "with dots"};
110 const char *gplotfileoutputs[] = {"",
111  "PNG",
112  "PS",
113  "EPS",
114  "LATEX"};
115 
116 
117 /*-----------------------------------------------------------------*
118  * Basic Plotting Functions *
119  *-----------------------------------------------------------------*/
137 GPLOT *
138 gplotCreate(const char *rootname,
139  l_int32 outformat,
140  const char *title,
141  const char *xlabel,
142  const char *ylabel)
143 {
144 char *newroot;
145 char buf[L_BUFSIZE];
146 l_int32 badchar;
147 GPLOT *gplot;
148 
149  PROCNAME("gplotCreate");
150 
151  if (!rootname)
152  return (GPLOT *)ERROR_PTR("rootname not defined", procName, NULL);
153  if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
154  outformat != GPLOT_EPS && outformat != GPLOT_LATEX)
155  return (GPLOT *)ERROR_PTR("outformat invalid", procName, NULL);
156  stringCheckForChars(rootname, "`;&|><\"?*", &badchar);
157  if (badchar) /* danger of command injection */
158  return (GPLOT *)ERROR_PTR("invalid rootname", procName, NULL);
159 
160  if ((gplot = (GPLOT *)LEPT_CALLOC(1, sizeof(GPLOT))) == NULL)
161  return (GPLOT *)ERROR_PTR("gplot not made", procName, NULL);
162  gplot->cmddata = sarrayCreate(0);
163  gplot->datanames = sarrayCreate(0);
164  gplot->plotdata = sarrayCreate(0);
165  gplot->plottitles = sarrayCreate(0);
166  gplot->plotstyles = numaCreate(0);
167 
168  /* Save title, labels, rootname, outformat, cmdname, outname */
169  newroot = genPathname(rootname, NULL);
170  gplot->rootname = newroot;
171  gplot->outformat = outformat;
172  snprintf(buf, L_BUFSIZE, "%s.cmd", rootname);
173  gplot->cmdname = stringNew(buf);
174  if (outformat == GPLOT_PNG)
175  snprintf(buf, L_BUFSIZE, "%s.png", newroot);
176  else if (outformat == GPLOT_PS)
177  snprintf(buf, L_BUFSIZE, "%s.ps", newroot);
178  else if (outformat == GPLOT_EPS)
179  snprintf(buf, L_BUFSIZE, "%s.eps", newroot);
180  else if (outformat == GPLOT_LATEX)
181  snprintf(buf, L_BUFSIZE, "%s.tex", newroot);
182  gplot->outname = stringNew(buf);
183  if (title) gplot->title = stringNew(title);
184  if (xlabel) gplot->xlabel = stringNew(xlabel);
185  if (ylabel) gplot->ylabel = stringNew(ylabel);
186 
187  return gplot;
188 }
189 
190 
196 void
198 {
199 GPLOT *gplot;
200 
201  PROCNAME("gplotDestroy");
202 
203  if (pgplot == NULL) {
204  L_WARNING("ptr address is null!\n", procName);
205  return;
206  }
207 
208  if ((gplot = *pgplot) == NULL)
209  return;
210 
211  LEPT_FREE(gplot->rootname);
212  LEPT_FREE(gplot->cmdname);
213  sarrayDestroy(&gplot->cmddata);
214  sarrayDestroy(&gplot->datanames);
215  sarrayDestroy(&gplot->plotdata);
216  sarrayDestroy(&gplot->plottitles);
217  numaDestroy(&gplot->plotstyles);
218  LEPT_FREE(gplot->outname);
219  if (gplot->title)
220  LEPT_FREE(gplot->title);
221  if (gplot->xlabel)
222  LEPT_FREE(gplot->xlabel);
223  if (gplot->ylabel)
224  LEPT_FREE(gplot->ylabel);
225 
226  LEPT_FREE(gplot);
227  *pgplot = NULL;
228  return;
229 }
230 
231 
262 l_int32
264  NUMA *nax,
265  NUMA *nay,
266  l_int32 plotstyle,
267  const char *plottitle)
268 {
269 char buf[L_BUFSIZE];
270 char emptystring[] = "";
271 char *datastr, *title;
272 l_int32 n, i;
273 l_float32 valx, valy, startx, delx;
274 SARRAY *sa;
275 
276  PROCNAME("gplotAddPlot");
277 
278  if (!gplot)
279  return ERROR_INT("gplot not defined", procName, 1);
280  if (!nay)
281  return ERROR_INT("nay not defined", procName, 1);
282  if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
283  return ERROR_INT("invalid plotstyle", procName, 1);
284 
285  if ((n = numaGetCount(nay)) == 0)
286  return ERROR_INT("no points to plot", procName, 1);
287  if (nax && (n != numaGetCount(nax)))
288  return ERROR_INT("nax and nay sizes differ", procName, 1);
289  if (n == 1 && plotstyle == GPLOT_LINES) {
290  L_INFO("only 1 pt; changing style to points\n", procName);
291  plotstyle = GPLOT_POINTS;
292  }
293 
294  /* Save plotstyle and plottitle */
295  numaGetParameters(nay, &startx, &delx);
296  numaAddNumber(gplot->plotstyles, plotstyle);
297  if (plottitle) {
298  title = stringNew(plottitle);
299  sarrayAddString(gplot->plottitles, title, L_INSERT);
300  } else {
301  sarrayAddString(gplot->plottitles, emptystring, L_COPY);
302  }
303 
304  /* Generate and save data filename */
305  gplot->nplots++;
306  snprintf(buf, L_BUFSIZE, "%s.data.%d", gplot->rootname, gplot->nplots);
307  sarrayAddString(gplot->datanames, buf, L_COPY);
308 
309  /* Generate data and save as a string */
310  sa = sarrayCreate(n);
311  for (i = 0; i < n; i++) {
312  if (nax)
313  numaGetFValue(nax, i, &valx);
314  else
315  valx = startx + i * delx;
316  numaGetFValue(nay, i, &valy);
317  snprintf(buf, L_BUFSIZE, "%f %f\n", valx, valy);
318  sarrayAddString(sa, buf, L_COPY);
319  }
320  datastr = sarrayToString(sa, 0);
321  sarrayAddString(gplot->plotdata, datastr, L_INSERT);
322  sarrayDestroy(&sa);
323 
324  return 0;
325 }
326 
327 
342 l_int32
344  l_int32 scaling)
345 {
346  PROCNAME("gplotSetScaling");
347 
348  if (!gplot)
349  return ERROR_INT("gplot not defined", procName, 1);
350  if (scaling != GPLOT_LINEAR_SCALE &&
351  scaling != GPLOT_LOG_SCALE_X &&
352  scaling != GPLOT_LOG_SCALE_Y &&
353  scaling != GPLOT_LOG_SCALE_X_Y)
354  return ERROR_INT("invalid gplot scaling", procName, 1);
355  gplot->scaling = scaling;
356  return 0;
357 }
358 
359 
378 l_int32
380 {
381 char buf[L_BUFSIZE];
382 char *cmdname;
383 l_int32 ignore;
384 
385  PROCNAME("gplotMakeOutput");
386 
387  if (!gplot)
388  return ERROR_INT("gplot not defined", procName, 1);
389 
390  gplotGenCommandFile(gplot);
391  gplotGenDataFiles(gplot);
392  cmdname = genPathname(gplot->cmdname, NULL);
393 
394 #ifndef _WIN32
395  snprintf(buf, L_BUFSIZE, "gnuplot %s", cmdname);
396 #else
397  snprintf(buf, L_BUFSIZE, "wgnuplot %s", cmdname);
398 #endif /* _WIN32 */
399 
400 #ifndef OS_IOS /* iOS 11 does not support system() */
401  ignore = system(buf); /* gnuplot || wgnuplot */
402 #endif /* !OS_IOS */
403 
404  LEPT_FREE(cmdname);
405  return 0;
406 }
407 
408 
415 l_int32
417 {
418 char buf[L_BUFSIZE];
419 char *cmdstr, *plottitle, *dataname;
420 l_int32 i, plotstyle, nplots;
421 FILE *fp;
422 
423  PROCNAME("gplotGenCommandFile");
424 
425  if (!gplot)
426  return ERROR_INT("gplot not defined", procName, 1);
427 
428  /* Remove any previous command data */
429  sarrayClear(gplot->cmddata);
430 
431  /* Generate command data instructions */
432  if (gplot->title) { /* set title */
433  snprintf(buf, L_BUFSIZE, "set title '%s'", gplot->title);
434  sarrayAddString(gplot->cmddata, buf, L_COPY);
435  }
436  if (gplot->xlabel) { /* set xlabel */
437  snprintf(buf, L_BUFSIZE, "set xlabel '%s'", gplot->xlabel);
438  sarrayAddString(gplot->cmddata, buf, L_COPY);
439  }
440  if (gplot->ylabel) { /* set ylabel */
441  snprintf(buf, L_BUFSIZE, "set ylabel '%s'", gplot->ylabel);
442  sarrayAddString(gplot->cmddata, buf, L_COPY);
443  }
444 
445  /* Set terminal type and output */
446  if (gplot->outformat == GPLOT_PNG) {
447  snprintf(buf, L_BUFSIZE, "set terminal png; set output '%s'",
448  gplot->outname);
449  } else if (gplot->outformat == GPLOT_PS) {
450  snprintf(buf, L_BUFSIZE, "set terminal postscript; set output '%s'",
451  gplot->outname);
452  } else if (gplot->outformat == GPLOT_EPS) {
453  snprintf(buf, L_BUFSIZE,
454  "set terminal postscript eps; set output '%s'",
455  gplot->outname);
456  } else if (gplot->outformat == GPLOT_LATEX) {
457  snprintf(buf, L_BUFSIZE, "set terminal latex; set output '%s'",
458  gplot->outname);
459  }
460  sarrayAddString(gplot->cmddata, buf, L_COPY);
461 
462  if (gplot->scaling == GPLOT_LOG_SCALE_X ||
463  gplot->scaling == GPLOT_LOG_SCALE_X_Y) {
464  snprintf(buf, L_BUFSIZE, "set logscale x");
465  sarrayAddString(gplot->cmddata, buf, L_COPY);
466  }
467  if (gplot->scaling == GPLOT_LOG_SCALE_Y ||
468  gplot->scaling == GPLOT_LOG_SCALE_X_Y) {
469  snprintf(buf, L_BUFSIZE, "set logscale y");
470  sarrayAddString(gplot->cmddata, buf, L_COPY);
471  }
472 
473  nplots = sarrayGetCount(gplot->datanames);
474  for (i = 0; i < nplots; i++) {
475  plottitle = sarrayGetString(gplot->plottitles, i, L_NOCOPY);
476  dataname = sarrayGetString(gplot->datanames, i, L_NOCOPY);
477  numaGetIValue(gplot->plotstyles, i, &plotstyle);
478  if (nplots == 1) {
479  snprintf(buf, L_BUFSIZE, "plot '%s' title '%s' %s",
480  dataname, plottitle, gplotstylenames[plotstyle]);
481  } else {
482  if (i == 0)
483  snprintf(buf, L_BUFSIZE, "plot '%s' title '%s' %s, \\",
484  dataname, plottitle, gplotstylenames[plotstyle]);
485  else if (i < nplots - 1)
486  snprintf(buf, L_BUFSIZE, " '%s' title '%s' %s, \\",
487  dataname, plottitle, gplotstylenames[plotstyle]);
488  else
489  snprintf(buf, L_BUFSIZE, " '%s' title '%s' %s",
490  dataname, plottitle, gplotstylenames[plotstyle]);
491  }
492  sarrayAddString(gplot->cmddata, buf, L_COPY);
493  }
494 
495  /* Write command data to file */
496  cmdstr = sarrayToString(gplot->cmddata, 1);
497  if ((fp = fopenWriteStream(gplot->cmdname, "w")) == NULL) {
498  LEPT_FREE(cmdstr);
499  return ERROR_INT("cmd stream not opened", procName, 1);
500  }
501  fwrite(cmdstr, 1, strlen(cmdstr), fp);
502  fclose(fp);
503  LEPT_FREE(cmdstr);
504  return 0;
505 }
506 
507 
521 l_int32
523 {
524 char *plotdata, *dataname;
525 l_int32 i, nplots;
526 FILE *fp;
527 
528  PROCNAME("gplotGenDataFiles");
529 
530  if (!gplot)
531  return ERROR_INT("gplot not defined", procName, 1);
532 
533  nplots = sarrayGetCount(gplot->datanames);
534  for (i = 0; i < nplots; i++) {
535  plotdata = sarrayGetString(gplot->plotdata, i, L_NOCOPY);
536  dataname = sarrayGetString(gplot->datanames, i, L_NOCOPY);
537  if ((fp = fopen(dataname, "w")) == NULL)
538  return ERROR_INT("datafile stream not opened", procName, 1);
539  fwrite(plotdata, 1, strlen(plotdata), fp);
540  fclose(fp);
541  }
542 
543  return 0;
544 }
545 
546 
547 /*-----------------------------------------------------------------*
548  * Quick and Dirty Plots *
549  *-----------------------------------------------------------------*/
568 l_int32
570  l_int32 outformat,
571  const char *outroot,
572  const char *title)
573 {
574  return gplotSimpleXY1(NULL, na, GPLOT_LINES, outformat, outroot, title);
575 }
576 
577 
597 l_int32
599  NUMA *na2,
600  l_int32 outformat,
601  const char *outroot,
602  const char *title)
603 {
604  return gplotSimpleXY2(NULL, na1, na2, GPLOT_LINES,
605  outformat, outroot, title);
606 }
607 
608 
628 l_int32
630  l_int32 outformat,
631  const char *outroot,
632  const char *title)
633 {
634  return gplotSimpleXYN(NULL, naa, GPLOT_LINES, outformat, outroot, title);
635 }
636 
637 
661 l_int32
663  NUMA *nay,
664  l_int32 plotstyle,
665  l_int32 outformat,
666  const char *outroot,
667  const char *title)
668 {
669 GPLOT *gplot;
670 
671  PROCNAME("gplotSimpleXY1");
672 
673  if (!nay)
674  return ERROR_INT("nay not defined", procName, 1);
675  if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
676  return ERROR_INT("invalid plotstyle", procName, 1);
677  if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
678  outformat != GPLOT_EPS && outformat != GPLOT_LATEX)
679  return ERROR_INT("invalid outformat", procName, 1);
680  if (!outroot)
681  return ERROR_INT("outroot not specified", procName, 1);
682 
683  if ((gplot = gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
684  return ERROR_INT("gplot not made", procName, 1);
685  gplotAddPlot(gplot, nax, nay, plotstyle, NULL);
686  gplotMakeOutput(gplot);
687  gplotDestroy(&gplot);
688  return 0;
689 }
690 
691 
716 l_int32
718  NUMA *nay1,
719  NUMA *nay2,
720  l_int32 plotstyle,
721  l_int32 outformat,
722  const char *outroot,
723  const char *title)
724 {
725 GPLOT *gplot;
726 
727  PROCNAME("gplotSimpleXY2");
728 
729  if (!nay1 || !nay2)
730  return ERROR_INT("nay1 and nay2 not both defined", procName, 1);
731  if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
732  return ERROR_INT("invalid plotstyle", procName, 1);
733  if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
734  outformat != GPLOT_EPS && outformat != GPLOT_LATEX)
735  return ERROR_INT("invalid outformat", procName, 1);
736  if (!outroot)
737  return ERROR_INT("outroot not specified", procName, 1);
738 
739  if ((gplot = gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
740  return ERROR_INT("gplot not made", procName, 1);
741  gplotAddPlot(gplot, nax, nay1, plotstyle, NULL);
742  gplotAddPlot(gplot, nax, nay2, plotstyle, NULL);
743  gplotMakeOutput(gplot);
744  gplotDestroy(&gplot);
745  return 0;
746 }
747 
748 
772 l_int32
774  NUMAA *naay,
775  l_int32 plotstyle,
776  l_int32 outformat,
777  const char *outroot,
778  const char *title)
779 {
780 l_int32 i, n;
781 GPLOT *gplot;
782 NUMA *nay;
783 
784  PROCNAME("gplotSimpleXYN");
785 
786  if (!naay)
787  return ERROR_INT("naay not defined", procName, 1);
788  if ((n = numaaGetCount(naay)) == 0)
789  return ERROR_INT("no numa in array", procName, 1);
790  if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
791  return ERROR_INT("invalid plotstyle", procName, 1);
792  if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
793  outformat != GPLOT_EPS && outformat != GPLOT_LATEX)
794  return ERROR_INT("invalid outformat", procName, 1);
795  if (!outroot)
796  return ERROR_INT("outroot not specified", procName, 1);
797 
798  if ((gplot = gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
799  return ERROR_INT("gplot not made", procName, 1);
800  for (i = 0; i < n; i++) {
801  nay = numaaGetNuma(naay, i, L_CLONE);
802  gplotAddPlot(gplot, nax, nay, plotstyle, NULL);
803  numaDestroy(&nay);
804  }
805  gplotMakeOutput(gplot);
806  gplotDestroy(&gplot);
807  return 0;
808 }
809 
810 
811 /*-----------------------------------------------------------------*
812  * Serialize for I/O *
813  *-----------------------------------------------------------------*/
820 GPLOT *
821 gplotRead(const char *filename)
822 {
823 char buf[L_BUFSIZE];
824 char *rootname, *title, *xlabel, *ylabel, *ignores;
825 l_int32 outformat, ret, version, ignore;
826 FILE *fp;
827 GPLOT *gplot;
828 
829  PROCNAME("gplotRead");
830 
831  if (!filename)
832  return (GPLOT *)ERROR_PTR("filename not defined", procName, NULL);
833 
834  if ((fp = fopenReadStream(filename)) == NULL)
835  return (GPLOT *)ERROR_PTR("stream not opened", procName, NULL);
836 
837  ret = fscanf(fp, "Gplot Version %d\n", &version);
838  if (ret != 1) {
839  fclose(fp);
840  return (GPLOT *)ERROR_PTR("not a gplot file", procName, NULL);
841  }
842  if (version != GPLOT_VERSION_NUMBER) {
843  fclose(fp);
844  return (GPLOT *)ERROR_PTR("invalid gplot version", procName, NULL);
845  }
846 
847  ignore = fscanf(fp, "Rootname: %511s\n", buf); /* L_BUFSIZE - 1 */
848  rootname = stringNew(buf);
849  ignore = fscanf(fp, "Output format: %d\n", &outformat);
850  ignores = fgets(buf, L_BUFSIZE, fp); /* Title: ... */
851  title = stringNew(buf + 7);
852  title[strlen(title) - 1] = '\0';
853  ignores = fgets(buf, L_BUFSIZE, fp); /* X axis label: ... */
854  xlabel = stringNew(buf + 14);
855  xlabel[strlen(xlabel) - 1] = '\0';
856  ignores = fgets(buf, L_BUFSIZE, fp); /* Y axis label: ... */
857  ylabel = stringNew(buf + 14);
858  ylabel[strlen(ylabel) - 1] = '\0';
859 
860  gplot = gplotCreate(rootname, outformat, title, xlabel, ylabel);
861  LEPT_FREE(rootname);
862  LEPT_FREE(title);
863  LEPT_FREE(xlabel);
864  LEPT_FREE(ylabel);
865  if (!gplot) {
866  fclose(fp);
867  return (GPLOT *)ERROR_PTR("gplot not made", procName, NULL);
868  }
869  sarrayDestroy(&gplot->cmddata);
870  sarrayDestroy(&gplot->datanames);
871  sarrayDestroy(&gplot->plotdata);
872  sarrayDestroy(&gplot->plottitles);
873  numaDestroy(&gplot->plotstyles);
874 
875  ignore = fscanf(fp, "Commandfile name: %511s\n", buf); /* L_BUFSIZE - 1 */
876  stringReplace(&gplot->cmdname, buf);
877  ignore = fscanf(fp, "\nCommandfile data:");
878  gplot->cmddata = sarrayReadStream(fp);
879  ignore = fscanf(fp, "\nDatafile names:");
880  gplot->datanames = sarrayReadStream(fp);
881  ignore = fscanf(fp, "\nPlot data:");
882  gplot->plotdata = sarrayReadStream(fp);
883  ignore = fscanf(fp, "\nPlot titles:");
884  gplot->plottitles = sarrayReadStream(fp);
885  ignore = fscanf(fp, "\nPlot styles:");
886  gplot->plotstyles = numaReadStream(fp);
887 
888  ignore = fscanf(fp, "Number of plots: %d\n", &gplot->nplots);
889  ignore = fscanf(fp, "Output file name: %511s\n", buf);
890  stringReplace(&gplot->outname, buf);
891  ignore = fscanf(fp, "Axis scaling: %d\n", &gplot->scaling);
892 
893  fclose(fp);
894  return gplot;
895 }
896 
897 
905 l_int32
906 gplotWrite(const char *filename,
907  GPLOT *gplot)
908 {
909 FILE *fp;
910 
911  PROCNAME("gplotWrite");
912 
913  if (!filename)
914  return ERROR_INT("filename not defined", procName, 1);
915  if (!gplot)
916  return ERROR_INT("gplot not defined", procName, 1);
917 
918  if ((fp = fopenWriteStream(filename, "wb")) == NULL)
919  return ERROR_INT("stream not opened", procName, 1);
920 
921  fprintf(fp, "Gplot Version %d\n", GPLOT_VERSION_NUMBER);
922  fprintf(fp, "Rootname: %s\n", gplot->rootname);
923  fprintf(fp, "Output format: %d\n", gplot->outformat);
924  fprintf(fp, "Title: %s\n", gplot->title);
925  fprintf(fp, "X axis label: %s\n", gplot->xlabel);
926  fprintf(fp, "Y axis label: %s\n", gplot->ylabel);
927 
928  fprintf(fp, "Commandfile name: %s\n", gplot->cmdname);
929  fprintf(fp, "\nCommandfile data:");
930  sarrayWriteStream(fp, gplot->cmddata);
931  fprintf(fp, "\nDatafile names:");
932  sarrayWriteStream(fp, gplot->datanames);
933  fprintf(fp, "\nPlot data:");
934  sarrayWriteStream(fp, gplot->plotdata);
935  fprintf(fp, "\nPlot titles:");
936  sarrayWriteStream(fp, gplot->plottitles);
937  fprintf(fp, "\nPlot styles:");
938  numaWriteStream(fp, gplot->plotstyles);
939 
940  fprintf(fp, "Number of plots: %d\n", gplot->nplots);
941  fprintf(fp, "Output file name: %s\n", gplot->outname);
942  fprintf(fp, "Axis scaling: %d\n", gplot->scaling);
943 
944  fclose(fp);
945  return 0;
946 }
void gplotDestroy(GPLOT **pgplot)
gplotDestroy()
Definition: gplot.c:197
l_int32 gplotSetScaling(GPLOT *gplot, l_int32 scaling)
gplotSetScaling()
Definition: gplot.c:343
l_int32 gplotAddPlot(GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plottitle)
gplotAddPlot()
Definition: gplot.c:263
l_int32 gplotSimple1(NUMA *na, l_int32 outformat, const char *outroot, const char *title)
gplotSimple1()
Definition: gplot.c:569
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
Definition: sarray1.c:757
l_int32 gplotWrite(const char *filename, GPLOT *gplot)
gplotWrite()
Definition: gplot.c:906
l_int32 numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
Definition: numabasic.c:472
char * title
Definition: gplot.h:88
l_int32 stringReplace(char **pdest, const char *src)
stringReplace()
Definition: utils2.c:279
char * genPathname(const char *dir, const char *fname)
genPathname()
Definition: utils2.c:2759
struct Numa * plotstyles
Definition: gplot.h:83
GPLOT * gplotCreate(const char *rootname, l_int32 outformat, const char *title, const char *xlabel, const char *ylabel)
gplotCreate()
Definition: gplot.c:138
Definition: pix.h:704
char * stringNew(const char *src)
stringNew()
Definition: utils2.c:202
struct Sarray * datanames
Definition: gplot.h:80
l_int32 numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
Definition: numabasic.c:691
char * xlabel
Definition: gplot.h:89
const char * gplotfileoutputs[]
Definition: gplot.c:110
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
Definition: sarray1.c:157
l_int32 sarrayWriteStream(FILE *fp, SARRAY *sa)
sarrayWriteStream()
Definition: sarray1.c:1507
NUMA * numaCreate(l_int32 n)
numaCreate()
Definition: numabasic.c:186
l_int32 numaGetParameters(NUMA *na, l_float32 *pstartx, l_float32 *pdelx)
numaGetParameters()
Definition: numabasic.c:935
struct Sarray * cmddata
Definition: gplot.h:79
l_int32 gplotMakeOutput(GPLOT *gplot)
gplotMakeOutput()
Definition: gplot.c:379
char * outname
Definition: gplot.h:85
Definition: array.h:116
NUMA * numaaGetNuma(NUMAA *naa, l_int32 index, l_int32 accessflag)
numaaGetNuma()
Definition: numabasic.c:1625
Definition: array.h:59
static const l_int32 L_INSERT
Definition: pix.h:710
l_int32 gplotSimpleXY1(NUMA *nax, NUMA *nay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY1()
Definition: gplot.c:662
l_int32 numaGetCount(NUMA *na)
numaGetCount()
Definition: numabasic.c:630
l_int32 gplotSimpleXYN(NUMA *nax, NUMAA *naay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXYN()
Definition: gplot.c:773
l_int32 gplotSimpleN(NUMAA *naa, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleN()
Definition: gplot.c:629
l_int32 gplotGenCommandFile(GPLOT *gplot)
gplotGenCommandFile()
Definition: gplot.c:416
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
Definition: sarray1.c:675
Definition: gplot.h:75
l_int32 gplotGenDataFiles(GPLOT *gplot)
gplotGenDataFiles()
Definition: gplot.c:522
char * cmdname
Definition: gplot.h:78
l_int32 sarrayAddString(SARRAY *sa, char *string, l_int32 copyflag)
sarrayAddString()
Definition: sarray1.c:439
Definition: array.h:71
void numaDestroy(NUMA **pna)
numaDestroy()
Definition: numabasic.c:359
char * rootname
Definition: gplot.h:77
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
Definition: utils2.c:1636
FILE * fopenReadStream(const char *filename)
fopenReadStream()
Definition: utils2.c:1593
l_int32 stringCheckForChars(const char *src, const char *chars, l_int32 *pfound)
stringCheckForChars()
Definition: utils2.c:720
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
Definition: sarray1.c:615
struct Sarray * plotdata
Definition: gplot.h:81
l_int32 numaaGetCount(NUMAA *naa)
numaaGetCount()
Definition: numabasic.c:1516
l_int32 nplots
Definition: gplot.h:84
Definition: pix.h:705
Definition: pix.h:706
l_int32 gplotSimpleXY2(NUMA *nax, NUMA *nay1, NUMA *nay2, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY2()
Definition: gplot.c:717
l_int32 scaling
Definition: gplot.h:87
l_int32 sarrayClear(SARRAY *sa)
sarrayClear()
Definition: sarray1.c:588
l_int32 gplotSimple2(NUMA *na1, NUMA *na2, l_int32 outformat, const char *outroot, const char *title)
gplotSimple2()
Definition: gplot.c:598
l_int32 numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
Definition: numabasic.c:726
l_int32 outformat
Definition: gplot.h:86
struct Sarray * plottitles
Definition: gplot.h:82
char * ylabel
Definition: gplot.h:90
const char * gplotstylenames[]
Definition: gplot.c:105
SARRAY * sarrayReadStream(FILE *fp)
sarrayReadStream()
Definition: sarray1.c:1375
NUMA * numaReadStream(FILE *fp)
numaReadStream()
Definition: numabasic.c:1109
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
Definition: sarray1.c:349
l_int32 numaWriteStream(FILE *fp, NUMA *na)
numaWriteStream()
Definition: numabasic.c:1213
GPLOT * gplotRead(const char *filename)
gplotRead()
Definition: gplot.c:821