Leptonica  1.77.0
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_ok
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_ok
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_ok
380 {
381 char buf[L_BUFSIZE];
382 char *cmdname;
383 
384  PROCNAME("gplotMakeOutput");
385 
386  if (!gplot)
387  return ERROR_INT("gplot not defined", procName, 1);
388 
389  if (!LeptDebugOK) {
390  L_INFO("running gnuplot is disabled; "
391  "use setLeptDebugOK(1) to enable\n", procName);
392  return 0;
393  }
394 
395 #ifdef OS_IOS /* iOS 11 does not support system() */
396  return ERROR_INT("iOS 11 does not support system()", procName, 0);
397 #endif /* OS_IOS */
398 
399  gplotGenCommandFile(gplot);
400  gplotGenDataFiles(gplot);
401  cmdname = genPathname(gplot->cmdname, NULL);
402 
403 #ifndef _WIN32
404  snprintf(buf, L_BUFSIZE, "gnuplot %s", cmdname);
405 #else
406  snprintf(buf, L_BUFSIZE, "wgnuplot %s", cmdname);
407 #endif /* _WIN32 */
408 
409  callSystemDebug(buf); /* gnuplot || wgnuplot */
410  LEPT_FREE(cmdname);
411  return 0;
412 }
413 
414 
421 l_ok
423 {
424 char buf[L_BUFSIZE];
425 char *cmdstr, *plottitle, *dataname;
426 l_int32 i, plotstyle, nplots;
427 FILE *fp;
428 
429  PROCNAME("gplotGenCommandFile");
430 
431  if (!gplot)
432  return ERROR_INT("gplot not defined", procName, 1);
433 
434  /* Remove any previous command data */
435  sarrayClear(gplot->cmddata);
436 
437  /* Generate command data instructions */
438  if (gplot->title) { /* set title */
439  snprintf(buf, L_BUFSIZE, "set title '%s'", gplot->title);
440  sarrayAddString(gplot->cmddata, buf, L_COPY);
441  }
442  if (gplot->xlabel) { /* set xlabel */
443  snprintf(buf, L_BUFSIZE, "set xlabel '%s'", gplot->xlabel);
444  sarrayAddString(gplot->cmddata, buf, L_COPY);
445  }
446  if (gplot->ylabel) { /* set ylabel */
447  snprintf(buf, L_BUFSIZE, "set ylabel '%s'", gplot->ylabel);
448  sarrayAddString(gplot->cmddata, buf, L_COPY);
449  }
450 
451  /* Set terminal type and output */
452  if (gplot->outformat == GPLOT_PNG) {
453  snprintf(buf, L_BUFSIZE, "set terminal png; set output '%s'",
454  gplot->outname);
455  } else if (gplot->outformat == GPLOT_PS) {
456  snprintf(buf, L_BUFSIZE, "set terminal postscript; set output '%s'",
457  gplot->outname);
458  } else if (gplot->outformat == GPLOT_EPS) {
459  snprintf(buf, L_BUFSIZE,
460  "set terminal postscript eps; set output '%s'",
461  gplot->outname);
462  } else if (gplot->outformat == GPLOT_LATEX) {
463  snprintf(buf, L_BUFSIZE, "set terminal latex; set output '%s'",
464  gplot->outname);
465  }
466  sarrayAddString(gplot->cmddata, buf, L_COPY);
467 
468  if (gplot->scaling == GPLOT_LOG_SCALE_X ||
469  gplot->scaling == GPLOT_LOG_SCALE_X_Y) {
470  snprintf(buf, L_BUFSIZE, "set logscale x");
471  sarrayAddString(gplot->cmddata, buf, L_COPY);
472  }
473  if (gplot->scaling == GPLOT_LOG_SCALE_Y ||
474  gplot->scaling == GPLOT_LOG_SCALE_X_Y) {
475  snprintf(buf, L_BUFSIZE, "set logscale y");
476  sarrayAddString(gplot->cmddata, buf, L_COPY);
477  }
478 
479  nplots = sarrayGetCount(gplot->datanames);
480  for (i = 0; i < nplots; i++) {
481  plottitle = sarrayGetString(gplot->plottitles, i, L_NOCOPY);
482  dataname = sarrayGetString(gplot->datanames, i, L_NOCOPY);
483  numaGetIValue(gplot->plotstyles, i, &plotstyle);
484  if (nplots == 1) {
485  snprintf(buf, L_BUFSIZE, "plot '%s' title '%s' %s",
486  dataname, plottitle, gplotstylenames[plotstyle]);
487  } else {
488  if (i == 0)
489  snprintf(buf, L_BUFSIZE, "plot '%s' title '%s' %s, \\",
490  dataname, plottitle, gplotstylenames[plotstyle]);
491  else if (i < nplots - 1)
492  snprintf(buf, L_BUFSIZE, " '%s' title '%s' %s, \\",
493  dataname, plottitle, gplotstylenames[plotstyle]);
494  else
495  snprintf(buf, L_BUFSIZE, " '%s' title '%s' %s",
496  dataname, plottitle, gplotstylenames[plotstyle]);
497  }
498  sarrayAddString(gplot->cmddata, buf, L_COPY);
499  }
500 
501  /* Write command data to file */
502  cmdstr = sarrayToString(gplot->cmddata, 1);
503  if ((fp = fopenWriteStream(gplot->cmdname, "w")) == NULL) {
504  LEPT_FREE(cmdstr);
505  return ERROR_INT("cmd stream not opened", procName, 1);
506  }
507  fwrite(cmdstr, 1, strlen(cmdstr), fp);
508  fclose(fp);
509  LEPT_FREE(cmdstr);
510  return 0;
511 }
512 
513 
527 l_ok
529 {
530 char *plotdata, *dataname;
531 l_int32 i, nplots;
532 FILE *fp;
533 
534  PROCNAME("gplotGenDataFiles");
535 
536  if (!gplot)
537  return ERROR_INT("gplot not defined", procName, 1);
538 
539  nplots = sarrayGetCount(gplot->datanames);
540  for (i = 0; i < nplots; i++) {
541  plotdata = sarrayGetString(gplot->plotdata, i, L_NOCOPY);
542  dataname = sarrayGetString(gplot->datanames, i, L_NOCOPY);
543  if ((fp = fopen(dataname, "w")) == NULL)
544  return ERROR_INT("datafile stream not opened", procName, 1);
545  fwrite(plotdata, 1, strlen(plotdata), fp);
546  fclose(fp);
547  }
548 
549  return 0;
550 }
551 
552 
553 /*-----------------------------------------------------------------*
554  * Quick and Dirty Plots *
555  *-----------------------------------------------------------------*/
574 l_ok
576  l_int32 outformat,
577  const char *outroot,
578  const char *title)
579 {
580  return gplotSimpleXY1(NULL, na, GPLOT_LINES, outformat, outroot, title);
581 }
582 
583 
603 l_ok
605  NUMA *na2,
606  l_int32 outformat,
607  const char *outroot,
608  const char *title)
609 {
610  return gplotSimpleXY2(NULL, na1, na2, GPLOT_LINES,
611  outformat, outroot, title);
612 }
613 
614 
634 l_ok
636  l_int32 outformat,
637  const char *outroot,
638  const char *title)
639 {
640  return gplotSimpleXYN(NULL, naa, GPLOT_LINES, outformat, outroot, title);
641 }
642 
643 
667 l_ok
669  NUMA *nay,
670  l_int32 plotstyle,
671  l_int32 outformat,
672  const char *outroot,
673  const char *title)
674 {
675 GPLOT *gplot;
676 
677  PROCNAME("gplotSimpleXY1");
678 
679  if (!nay)
680  return ERROR_INT("nay not defined", procName, 1);
681  if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
682  return ERROR_INT("invalid plotstyle", procName, 1);
683  if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
684  outformat != GPLOT_EPS && outformat != GPLOT_LATEX)
685  return ERROR_INT("invalid outformat", procName, 1);
686  if (!outroot)
687  return ERROR_INT("outroot not specified", procName, 1);
688 
689  if ((gplot = gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
690  return ERROR_INT("gplot not made", procName, 1);
691  gplotAddPlot(gplot, nax, nay, plotstyle, NULL);
692  gplotMakeOutput(gplot);
693  gplotDestroy(&gplot);
694  return 0;
695 }
696 
697 
722 l_ok
724  NUMA *nay1,
725  NUMA *nay2,
726  l_int32 plotstyle,
727  l_int32 outformat,
728  const char *outroot,
729  const char *title)
730 {
731 GPLOT *gplot;
732 
733  PROCNAME("gplotSimpleXY2");
734 
735  if (!nay1 || !nay2)
736  return ERROR_INT("nay1 and nay2 not both defined", procName, 1);
737  if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
738  return ERROR_INT("invalid plotstyle", procName, 1);
739  if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
740  outformat != GPLOT_EPS && outformat != GPLOT_LATEX)
741  return ERROR_INT("invalid outformat", procName, 1);
742  if (!outroot)
743  return ERROR_INT("outroot not specified", procName, 1);
744 
745  if ((gplot = gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
746  return ERROR_INT("gplot not made", procName, 1);
747  gplotAddPlot(gplot, nax, nay1, plotstyle, NULL);
748  gplotAddPlot(gplot, nax, nay2, plotstyle, NULL);
749  gplotMakeOutput(gplot);
750  gplotDestroy(&gplot);
751  return 0;
752 }
753 
754 
778 l_ok
780  NUMAA *naay,
781  l_int32 plotstyle,
782  l_int32 outformat,
783  const char *outroot,
784  const char *title)
785 {
786 l_int32 i, n;
787 GPLOT *gplot;
788 NUMA *nay;
789 
790  PROCNAME("gplotSimpleXYN");
791 
792  if (!naay)
793  return ERROR_INT("naay not defined", procName, 1);
794  if ((n = numaaGetCount(naay)) == 0)
795  return ERROR_INT("no numa in array", procName, 1);
796  if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
797  return ERROR_INT("invalid plotstyle", procName, 1);
798  if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
799  outformat != GPLOT_EPS && outformat != GPLOT_LATEX)
800  return ERROR_INT("invalid outformat", procName, 1);
801  if (!outroot)
802  return ERROR_INT("outroot not specified", procName, 1);
803 
804  if ((gplot = gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
805  return ERROR_INT("gplot not made", procName, 1);
806  for (i = 0; i < n; i++) {
807  nay = numaaGetNuma(naay, i, L_CLONE);
808  gplotAddPlot(gplot, nax, nay, plotstyle, NULL);
809  numaDestroy(&nay);
810  }
811  gplotMakeOutput(gplot);
812  gplotDestroy(&gplot);
813  return 0;
814 }
815 
816 
817 /*-----------------------------------------------------------------*
818  * Serialize for I/O *
819  *-----------------------------------------------------------------*/
826 GPLOT *
827 gplotRead(const char *filename)
828 {
829 char buf[L_BUFSIZE];
830 char *rootname, *title, *xlabel, *ylabel, *ignores;
831 l_int32 outformat, ret, version, ignore;
832 FILE *fp;
833 GPLOT *gplot;
834 
835  PROCNAME("gplotRead");
836 
837  if (!filename)
838  return (GPLOT *)ERROR_PTR("filename not defined", procName, NULL);
839 
840  if ((fp = fopenReadStream(filename)) == NULL)
841  return (GPLOT *)ERROR_PTR("stream not opened", procName, NULL);
842 
843  ret = fscanf(fp, "Gplot Version %d\n", &version);
844  if (ret != 1) {
845  fclose(fp);
846  return (GPLOT *)ERROR_PTR("not a gplot file", procName, NULL);
847  }
848  if (version != GPLOT_VERSION_NUMBER) {
849  fclose(fp);
850  return (GPLOT *)ERROR_PTR("invalid gplot version", procName, NULL);
851  }
852 
853  ignore = fscanf(fp, "Rootname: %511s\n", buf); /* L_BUFSIZE - 1 */
854  rootname = stringNew(buf);
855  ignore = fscanf(fp, "Output format: %d\n", &outformat);
856  ignores = fgets(buf, L_BUFSIZE, fp); /* Title: ... */
857  title = stringNew(buf + 7);
858  title[strlen(title) - 1] = '\0';
859  ignores = fgets(buf, L_BUFSIZE, fp); /* X axis label: ... */
860  xlabel = stringNew(buf + 14);
861  xlabel[strlen(xlabel) - 1] = '\0';
862  ignores = fgets(buf, L_BUFSIZE, fp); /* Y axis label: ... */
863  ylabel = stringNew(buf + 14);
864  ylabel[strlen(ylabel) - 1] = '\0';
865 
866  gplot = gplotCreate(rootname, outformat, title, xlabel, ylabel);
867  LEPT_FREE(rootname);
868  LEPT_FREE(title);
869  LEPT_FREE(xlabel);
870  LEPT_FREE(ylabel);
871  if (!gplot) {
872  fclose(fp);
873  return (GPLOT *)ERROR_PTR("gplot not made", procName, NULL);
874  }
875  sarrayDestroy(&gplot->cmddata);
876  sarrayDestroy(&gplot->datanames);
877  sarrayDestroy(&gplot->plotdata);
878  sarrayDestroy(&gplot->plottitles);
879  numaDestroy(&gplot->plotstyles);
880 
881  ignore = fscanf(fp, "Commandfile name: %511s\n", buf); /* L_BUFSIZE - 1 */
882  stringReplace(&gplot->cmdname, buf);
883  ignore = fscanf(fp, "\nCommandfile data:");
884  gplot->cmddata = sarrayReadStream(fp);
885  ignore = fscanf(fp, "\nDatafile names:");
886  gplot->datanames = sarrayReadStream(fp);
887  ignore = fscanf(fp, "\nPlot data:");
888  gplot->plotdata = sarrayReadStream(fp);
889  ignore = fscanf(fp, "\nPlot titles:");
890  gplot->plottitles = sarrayReadStream(fp);
891  ignore = fscanf(fp, "\nPlot styles:");
892  gplot->plotstyles = numaReadStream(fp);
893 
894  ignore = fscanf(fp, "Number of plots: %d\n", &gplot->nplots);
895  ignore = fscanf(fp, "Output file name: %511s\n", buf);
896  stringReplace(&gplot->outname, buf);
897  ignore = fscanf(fp, "Axis scaling: %d\n", &gplot->scaling);
898 
899  fclose(fp);
900  return gplot;
901 }
902 
903 
911 l_ok
912 gplotWrite(const char *filename,
913  GPLOT *gplot)
914 {
915 FILE *fp;
916 
917  PROCNAME("gplotWrite");
918 
919  if (!filename)
920  return ERROR_INT("filename not defined", procName, 1);
921  if (!gplot)
922  return ERROR_INT("gplot not defined", procName, 1);
923 
924  if ((fp = fopenWriteStream(filename, "wb")) == NULL)
925  return ERROR_INT("stream not opened", procName, 1);
926 
927  fprintf(fp, "Gplot Version %d\n", GPLOT_VERSION_NUMBER);
928  fprintf(fp, "Rootname: %s\n", gplot->rootname);
929  fprintf(fp, "Output format: %d\n", gplot->outformat);
930  fprintf(fp, "Title: %s\n", gplot->title);
931  fprintf(fp, "X axis label: %s\n", gplot->xlabel);
932  fprintf(fp, "Y axis label: %s\n", gplot->ylabel);
933 
934  fprintf(fp, "Commandfile name: %s\n", gplot->cmdname);
935  fprintf(fp, "\nCommandfile data:");
936  sarrayWriteStream(fp, gplot->cmddata);
937  fprintf(fp, "\nDatafile names:");
938  sarrayWriteStream(fp, gplot->datanames);
939  fprintf(fp, "\nPlot data:");
940  sarrayWriteStream(fp, gplot->plotdata);
941  fprintf(fp, "\nPlot titles:");
942  sarrayWriteStream(fp, gplot->plottitles);
943  fprintf(fp, "\nPlot styles:");
944  numaWriteStream(fp, gplot->plotstyles);
945 
946  fprintf(fp, "Number of plots: %d\n", gplot->nplots);
947  fprintf(fp, "Output file name: %s\n", gplot->outname);
948  fprintf(fp, "Axis scaling: %d\n", gplot->scaling);
949 
950  fclose(fp);
951  return 0;
952 }
void gplotDestroy(GPLOT **pgplot)
gplotDestroy()
Definition: gplot.c:197
l_ok numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
Definition: numabasic.c:692
l_ok gplotSetScaling(GPLOT *gplot, l_int32 scaling)
gplotSetScaling()
Definition: gplot.c:343
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
Definition: sarray1.c:763
Definition: pix.h:717
l_ok gplotAddPlot(GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plottitle)
gplotAddPlot()
Definition: gplot.c:263
l_ok stringCheckForChars(const char *src, const char *chars, l_int32 *pfound)
stringCheckForChars()
Definition: utils2.c:778
char * title
Definition: gplot.h:88
char * genPathname(const char *dir, const char *fname)
genPathname()
Definition: utils2.c:2880
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
Definition: numabasic.c:473
struct Numa * plotstyles
Definition: gplot.h:83
l_ok gplotMakeOutput(GPLOT *gplot)
gplotMakeOutput()
Definition: gplot.c:379
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:716
char * stringNew(const char *src)
stringNew()
Definition: utils2.c:215
struct Sarray * datanames
Definition: gplot.h:80
char * xlabel
Definition: gplot.h:89
const char * gplotfileoutputs[]
Definition: gplot.c:110
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
Definition: sarray1.c:163
l_ok sarrayWriteStream(FILE *fp, SARRAY *sa)
sarrayWriteStream()
Definition: sarray1.c:1514
l_ok numaWriteStream(FILE *fp, NUMA *na)
numaWriteStream()
Definition: numabasic.c:1246
NUMA * numaCreate(l_int32 n)
numaCreate()
Definition: numabasic.c:187
struct Sarray * cmddata
Definition: gplot.h:79
char * outname
Definition: gplot.h:85
Definition: array.h:116
NUMA * numaaGetNuma(NUMAA *naa, l_int32 index, l_int32 accessflag)
numaaGetNuma()
Definition: numabasic.c:1659
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
Definition: numabasic.c:727
Definition: array.h:59
l_int32 numaGetCount(NUMA *na)
numaGetCount()
Definition: numabasic.c:631
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
Definition: sarray1.c:446
l_ok gplotGenDataFiles(GPLOT *gplot)
gplotGenDataFiles()
Definition: gplot.c:528
l_ok gplotSimpleXY2(NUMA *nax, NUMA *nay1, NUMA *nay2, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY2()
Definition: gplot.c:723
l_ok gplotSimpleXY1(NUMA *nax, NUMA *nay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY1()
Definition: gplot.c:668
l_ok gplotSimple2(NUMA *na1, NUMA *na2, l_int32 outformat, const char *outroot, const char *title)
gplotSimple2()
Definition: gplot.c:604
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
Definition: sarray1.c:681
Definition: gplot.h:75
char * cmdname
Definition: gplot.h:78
l_ok numaGetParameters(NUMA *na, l_float32 *pstartx, l_float32 *pdelx)
numaGetParameters()
Definition: numabasic.c:936
l_ok stringReplace(char **pdest, const char *src)
stringReplace()
Definition: utils2.c:337
Definition: array.h:71
l_ok sarrayClear(SARRAY *sa)
sarrayClear()
Definition: sarray1.c:594
void numaDestroy(NUMA **pna)
numaDestroy()
Definition: numabasic.c:360
char * rootname
Definition: gplot.h:77
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
Definition: utils2.c:1700
FILE * fopenReadStream(const char *filename)
fopenReadStream()
Definition: utils2.c:1657
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
Definition: sarray1.c:621
l_ok gplotWrite(const char *filename, GPLOT *gplot)
gplotWrite()
Definition: gplot.c:912
struct Sarray * plotdata
Definition: gplot.h:81
l_ok gplotSimpleXYN(NUMA *nax, NUMAA *naay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXYN()
Definition: gplot.c:779
l_int32 numaaGetCount(NUMAA *naa)
numaaGetCount()
Definition: numabasic.c:1550
l_int32 nplots
Definition: gplot.h:84
Definition: pix.h:718
Definition: pix.h:719
l_int32 scaling
Definition: gplot.h:87
void callSystemDebug(const char *cmd)
callSystemDebug()
Definition: utils2.c:2474
l_ok gplotGenCommandFile(GPLOT *gplot)
gplotGenCommandFile()
Definition: gplot.c:422
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:1382
l_ok gplotSimple1(NUMA *na, l_int32 outformat, const char *outroot, const char *title)
gplotSimple1()
Definition: gplot.c:575
l_ok gplotSimpleN(NUMAA *naa, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleN()
Definition: gplot.c:635
NUMA * numaReadStream(FILE *fp)
numaReadStream()
Definition: numabasic.c:1110
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
Definition: sarray1.c:355
GPLOT * gplotRead(const char *filename)
gplotRead()
Definition: gplot.c:827