101 #include "allheaders.h" 103 static const l_int32 L_BUFSIZE = 512;
149 PROCNAME(
"gplotCreate");
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);
158 return (
GPLOT *)ERROR_PTR(
"invalid rootname", procName, NULL);
160 if ((gplot = (
GPLOT *)LEPT_CALLOC(1,
sizeof(
GPLOT))) == NULL)
161 return (
GPLOT *)ERROR_PTR(
"gplot not made", procName, NULL);
172 snprintf(buf, L_BUFSIZE,
"%s.cmd", rootname);
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);
201 PROCNAME(
"gplotDestroy");
203 if (pgplot == NULL) {
204 L_WARNING(
"ptr address is null!\n", procName);
208 if ((gplot = *pgplot) == NULL)
220 LEPT_FREE(gplot->
title);
267 const char *plottitle)
270 char emptystring[] =
"";
271 char *datastr, *title;
273 l_float32 valx, valy, startx, delx;
276 PROCNAME(
"gplotAddPlot");
279 return ERROR_INT(
"gplot not defined", procName, 1);
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);
286 return ERROR_INT(
"no points to plot", procName, 1);
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;
306 snprintf(buf, L_BUFSIZE,
"%s.data.%d", gplot->
rootname, gplot->
nplots);
311 for (i = 0; i < n; i++) {
315 valx = startx + i * delx;
317 snprintf(buf, L_BUFSIZE,
"%f %f\n", valx, valy);
346 PROCNAME(
"gplotSetScaling");
349 return ERROR_INT(
"gplot not defined", procName, 1);
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);
384 PROCNAME(
"gplotMakeOutput");
387 return ERROR_INT(
"gplot not defined", procName, 1);
390 L_INFO(
"running gnuplot is disabled; " 391 "use setLeptDebugOK(1) to enable\n", procName);
396 return ERROR_INT(
"iOS 11 does not support system()", procName, 0);
404 snprintf(buf, L_BUFSIZE,
"gnuplot %s", cmdname);
406 snprintf(buf, L_BUFSIZE,
"wgnuplot %s", cmdname);
425 char *cmdstr, *plottitle, *dataname;
426 l_int32 i, plotstyle, nplots;
429 PROCNAME(
"gplotGenCommandFile");
432 return ERROR_INT(
"gplot not defined", procName, 1);
439 snprintf(buf, L_BUFSIZE,
"set title '%s'", gplot->
title);
443 snprintf(buf, L_BUFSIZE,
"set xlabel '%s'", gplot->
xlabel);
447 snprintf(buf, L_BUFSIZE,
"set ylabel '%s'", gplot->
ylabel);
453 snprintf(buf, L_BUFSIZE,
"set terminal png; set output '%s'",
455 }
else if (gplot->
outformat == GPLOT_PS) {
456 snprintf(buf, L_BUFSIZE,
"set terminal postscript; set output '%s'",
458 }
else if (gplot->
outformat == GPLOT_EPS) {
459 snprintf(buf, L_BUFSIZE,
460 "set terminal postscript eps; set output '%s'",
462 }
else if (gplot->
outformat == GPLOT_LATEX) {
463 snprintf(buf, L_BUFSIZE,
"set terminal latex; set output '%s'",
468 if (gplot->
scaling == GPLOT_LOG_SCALE_X ||
469 gplot->
scaling == GPLOT_LOG_SCALE_X_Y) {
470 snprintf(buf, L_BUFSIZE,
"set logscale x");
473 if (gplot->
scaling == GPLOT_LOG_SCALE_Y ||
474 gplot->
scaling == GPLOT_LOG_SCALE_X_Y) {
475 snprintf(buf, L_BUFSIZE,
"set logscale y");
480 for (i = 0; i < nplots; i++) {
485 snprintf(buf, L_BUFSIZE,
"plot '%s' title '%s' %s",
489 snprintf(buf, L_BUFSIZE,
"plot '%s' title '%s' %s, \\",
491 else if (i < nplots - 1)
492 snprintf(buf, L_BUFSIZE,
" '%s' title '%s' %s, \\",
495 snprintf(buf, L_BUFSIZE,
" '%s' title '%s' %s",
505 return ERROR_INT(
"cmd stream not opened", procName, 1);
507 fwrite(cmdstr, 1, strlen(cmdstr), fp);
530 char *plotdata, *dataname;
534 PROCNAME(
"gplotGenDataFiles");
537 return ERROR_INT(
"gplot not defined", procName, 1);
540 for (i = 0; i < nplots; i++) {
543 if ((fp = fopen(dataname,
"w")) == NULL)
544 return ERROR_INT(
"datafile stream not opened", procName, 1);
545 fwrite(plotdata, 1, strlen(plotdata), fp);
580 return gplotSimpleXY1(NULL, na, GPLOT_LINES, outformat, outroot, title);
611 outformat, outroot, title);
640 return gplotSimpleXYN(NULL, naa, GPLOT_LINES, outformat, outroot, title);
677 PROCNAME(
"gplotSimpleXY1");
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);
687 return ERROR_INT(
"outroot not specified", procName, 1);
689 if ((gplot =
gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
690 return ERROR_INT(
"gplot not made", procName, 1);
733 PROCNAME(
"gplotSimpleXY2");
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);
743 return ERROR_INT(
"outroot not specified", procName, 1);
745 if ((gplot =
gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
746 return ERROR_INT(
"gplot not made", procName, 1);
790 PROCNAME(
"gplotSimpleXYN");
793 return ERROR_INT(
"naay not defined", procName, 1);
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);
802 return ERROR_INT(
"outroot not specified", procName, 1);
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++) {
830 char *rootname, *title, *xlabel, *ylabel, *ignores;
831 l_int32 outformat, ret, version, ignore;
835 PROCNAME(
"gplotRead");
838 return (
GPLOT *)ERROR_PTR(
"filename not defined", procName, NULL);
841 return (
GPLOT *)ERROR_PTR(
"stream not opened", procName, NULL);
843 ret = fscanf(fp,
"Gplot Version %d\n", &version);
846 return (
GPLOT *)ERROR_PTR(
"not a gplot file", procName, NULL);
848 if (version != GPLOT_VERSION_NUMBER) {
850 return (
GPLOT *)ERROR_PTR(
"invalid gplot version", procName, NULL);
853 ignore = fscanf(fp,
"Rootname: %511s\n", buf);
855 ignore = fscanf(fp,
"Output format: %d\n", &outformat);
856 ignores = fgets(buf, L_BUFSIZE, fp);
858 title[strlen(title) - 1] =
'\0';
859 ignores = fgets(buf, L_BUFSIZE, fp);
861 xlabel[strlen(xlabel) - 1] =
'\0';
862 ignores = fgets(buf, L_BUFSIZE, fp);
864 ylabel[strlen(ylabel) - 1] =
'\0';
866 gplot =
gplotCreate(rootname, outformat, title, xlabel, ylabel);
873 return (
GPLOT *)ERROR_PTR(
"gplot not made", procName, NULL);
881 ignore = fscanf(fp,
"Commandfile name: %511s\n", buf);
883 ignore = fscanf(fp,
"\nCommandfile data:");
885 ignore = fscanf(fp,
"\nDatafile names:");
887 ignore = fscanf(fp,
"\nPlot data:");
889 ignore = fscanf(fp,
"\nPlot titles:");
891 ignore = fscanf(fp,
"\nPlot styles:");
894 ignore = fscanf(fp,
"Number of plots: %d\n", &gplot->
nplots);
895 ignore = fscanf(fp,
"Output file name: %511s\n", buf);
897 ignore = fscanf(fp,
"Axis scaling: %d\n", &gplot->
scaling);
917 PROCNAME(
"gplotWrite");
920 return ERROR_INT(
"filename not defined", procName, 1);
922 return ERROR_INT(
"gplot not defined", procName, 1);
925 return ERROR_INT(
"stream not opened", procName, 1);
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);
934 fprintf(fp,
"Commandfile name: %s\n", gplot->
cmdname);
935 fprintf(fp,
"\nCommandfile data:");
937 fprintf(fp,
"\nDatafile names:");
939 fprintf(fp,
"\nPlot data:");
941 fprintf(fp,
"\nPlot titles:");
943 fprintf(fp,
"\nPlot styles:");
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);
void gplotDestroy(GPLOT **pgplot)
gplotDestroy()
l_ok numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
l_ok gplotSetScaling(GPLOT *gplot, l_int32 scaling)
gplotSetScaling()
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
l_ok gplotAddPlot(GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plottitle)
gplotAddPlot()
l_ok stringCheckForChars(const char *src, const char *chars, l_int32 *pfound)
stringCheckForChars()
char * genPathname(const char *dir, const char *fname)
genPathname()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
l_ok gplotMakeOutput(GPLOT *gplot)
gplotMakeOutput()
GPLOT * gplotCreate(const char *rootname, l_int32 outformat, const char *title, const char *xlabel, const char *ylabel)
gplotCreate()
char * stringNew(const char *src)
stringNew()
struct Sarray * datanames
const char * gplotfileoutputs[]
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
l_ok sarrayWriteStream(FILE *fp, SARRAY *sa)
sarrayWriteStream()
l_ok numaWriteStream(FILE *fp, NUMA *na)
numaWriteStream()
NUMA * numaCreate(l_int32 n)
numaCreate()
NUMA * numaaGetNuma(NUMAA *naa, l_int32 index, l_int32 accessflag)
numaaGetNuma()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
l_ok gplotGenDataFiles(GPLOT *gplot)
gplotGenDataFiles()
l_ok gplotSimpleXY2(NUMA *nax, NUMA *nay1, NUMA *nay2, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY2()
l_ok gplotSimpleXY1(NUMA *nax, NUMA *nay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY1()
l_ok gplotSimple2(NUMA *na1, NUMA *na2, l_int32 outformat, const char *outroot, const char *title)
gplotSimple2()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_ok numaGetParameters(NUMA *na, l_float32 *pstartx, l_float32 *pdelx)
numaGetParameters()
l_ok stringReplace(char **pdest, const char *src)
stringReplace()
l_ok sarrayClear(SARRAY *sa)
sarrayClear()
void numaDestroy(NUMA **pna)
numaDestroy()
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
l_ok gplotWrite(const char *filename, GPLOT *gplot)
gplotWrite()
l_ok gplotSimpleXYN(NUMA *nax, NUMAA *naay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXYN()
l_int32 numaaGetCount(NUMAA *naa)
numaaGetCount()
void callSystemDebug(const char *cmd)
callSystemDebug()
l_ok gplotGenCommandFile(GPLOT *gplot)
gplotGenCommandFile()
struct Sarray * plottitles
const char * gplotstylenames[]
SARRAY * sarrayReadStream(FILE *fp)
sarrayReadStream()
l_ok gplotSimple1(NUMA *na, l_int32 outformat, const char *outroot, const char *title)
gplotSimple1()
l_ok gplotSimpleN(NUMAA *naa, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleN()
NUMA * numaReadStream(FILE *fp)
numaReadStream()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
GPLOT * gplotRead(const char *filename)
gplotRead()