144 #include <config_auto.h>
148 #include "allheaders.h"
199 return (
GPLOT *)ERROR_PTR(
"rootname not defined", __func__, NULL);
200 if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
201 outformat != GPLOT_EPS && outformat != GPLOT_LATEX &&
202 outformat != GPLOT_PNM)
203 return (
GPLOT *)ERROR_PTR(
"outformat invalid", __func__, NULL);
206 return (
GPLOT *)ERROR_PTR(
"invalid rootname", __func__, NULL);
208 #if !defined(HAVE_LIBPNG)
209 if (outformat == GPLOT_PNG) {
210 L_WARNING(
"png library missing; output pnm format\n", __func__);
211 outformat = GPLOT_PNM;
215 gplot = (
GPLOT *)LEPT_CALLOC(1,
sizeof(
GPLOT));
226 snprintf(buf, Bufsize,
"%s.cmd", rootname);
228 if (outformat == GPLOT_PNG)
229 snprintf(buf, Bufsize,
"%s.png", newroot);
230 else if (outformat == GPLOT_PS)
231 snprintf(buf, Bufsize,
"%s.ps", newroot);
232 else if (outformat == GPLOT_EPS)
233 snprintf(buf, Bufsize,
"%s.eps", newroot);
234 else if (outformat == GPLOT_LATEX)
235 snprintf(buf, Bufsize,
"%s.tex", newroot);
236 else if (outformat == GPLOT_PNM)
237 snprintf(buf, Bufsize,
"%s.pnm", newroot);
257 if (pgplot == NULL) {
258 L_WARNING(
"ptr address is null!\n", __func__);
262 if ((gplot = *pgplot) == NULL)
274 LEPT_FREE(gplot->
title);
320 const char *plotlabel)
323 char emptystring[] =
"";
324 char *datastr, *title;
326 l_float32 valx, valy, startx, delx;
330 return ERROR_INT(
"gplot not defined", __func__, 1);
332 return ERROR_INT(
"nay not defined", __func__, 1);
333 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
334 return ERROR_INT(
"invalid plotstyle", __func__, 1);
337 return ERROR_INT(
"no points to plot", __func__, 1);
339 return ERROR_INT(
"nax and nay sizes differ", __func__, 1);
340 if (n == 1 && plotstyle == GPLOT_LINES) {
341 L_INFO(
"only 1 pt; changing style to points\n", __func__);
342 plotstyle = GPLOT_POINTS;
357 snprintf(buf, Bufsize,
"%s.data.%d", gplot->
rootname, gplot->
nplots);
362 for (i = 0; i < n; i++) {
366 valx = startx + i * delx;
368 snprintf(buf, Bufsize,
"%f %f\n", valx, valy);
398 return ERROR_INT(
"gplot not defined", __func__, 1);
400 scaling != GPLOT_LOG_SCALE_X &&
401 scaling != GPLOT_LOG_SCALE_Y &&
402 scaling != GPLOT_LOG_SCALE_X_Y)
403 return ERROR_INT(
"invalid gplot scaling", __func__, 1);
426 return (
PIX *)ERROR_PTR(
"gplot not defined", __func__, NULL);
428 return (
PIX *)ERROR_PTR(
"output format not an image", __func__, NULL);
431 return (
PIX *)ERROR_PTR(
"plot output not made", __func__, NULL);
462 return ERROR_INT(
"gplot not defined", __func__, 1);
465 L_INFO(
"running gnuplot is disabled; "
466 "use setLeptDebugOK(1) to enable\n", __func__);
471 return ERROR_INT(
"iOS 11 does not support system()", __func__, 0);
479 snprintf(buf, Bufsize,
"gnuplot %s", cmdname);
481 snprintf(buf, Bufsize,
"wgnuplot %s", cmdname);
500 char *cmdstr, *plotlabel, *dataname;
501 l_int32 i, plotstyle, nplots;
505 return ERROR_INT(
"gplot not defined", __func__, 1);
512 snprintf(buf, Bufsize,
"set title '%s'", gplot->
title);
516 snprintf(buf, Bufsize,
"set xlabel '%s'", gplot->
xlabel);
520 snprintf(buf, Bufsize,
"set ylabel '%s'", gplot->
ylabel);
526 snprintf(buf, Bufsize,
"set terminal png; set output '%s'",
528 }
else if (gplot->
outformat == GPLOT_PS) {
529 snprintf(buf, Bufsize,
"set terminal postscript; set output '%s'",
531 }
else if (gplot->
outformat == GPLOT_EPS) {
532 snprintf(buf, Bufsize,
"set terminal postscript eps; set output '%s'",
534 }
else if (gplot->
outformat == GPLOT_LATEX) {
535 snprintf(buf, Bufsize,
"set terminal latex; set output '%s'",
537 }
else if (gplot->
outformat == GPLOT_PNM) {
538 snprintf(buf, Bufsize,
"set terminal pbm color; set output '%s'",
543 if (gplot->
scaling == GPLOT_LOG_SCALE_X ||
544 gplot->
scaling == GPLOT_LOG_SCALE_X_Y) {
545 snprintf(buf, Bufsize,
"set logscale x");
548 if (gplot->
scaling == GPLOT_LOG_SCALE_Y ||
549 gplot->
scaling == GPLOT_LOG_SCALE_X_Y) {
550 snprintf(buf, Bufsize,
"set logscale y");
555 for (i = 0; i < nplots; i++) {
560 snprintf(buf, Bufsize,
"plot '%s' title '%s' %s",
564 snprintf(buf, Bufsize,
"plot '%s' title '%s' %s, \\",
566 else if (i < nplots - 1)
567 snprintf(buf, Bufsize,
" '%s' title '%s' %s, \\",
570 snprintf(buf, Bufsize,
" '%s' title '%s' %s",
580 return ERROR_INT(
"cmd stream not opened", __func__, 1);
582 fwrite(cmdstr, 1, strlen(cmdstr), fp);
605 char *plotdata, *dataname;
610 return ERROR_INT(
"gplot not defined", __func__, 1);
613 for (i = 0; i < nplots; i++) {
616 if ((fp = fopen(dataname,
"w")) == NULL)
617 return ERROR_INT(
"datafile stream not opened", __func__, 1);
618 fwrite(plotdata, 1, strlen(plotdata), fp);
656 gplot =
gplotSimpleXY1(NULL, na, GPLOT_LINES, outformat, outroot, title);
658 return ERROR_INT(
"failed to generate plot", __func__, 1);
694 outformat, outroot, title);
696 return ERROR_INT(
"failed to generate plot", __func__, 1);
730 gplot =
gplotSimpleXYN(NULL, naa, GPLOT_LINES, outformat, outroot, title);
732 return ERROR_INT(
"failed to generate plot", __func__, 1);
758 static l_int32 index;
763 return (
PIX *)ERROR_PTR(
"na not defined", __func__, NULL);
766 snprintf(buf,
sizeof(buf),
"/tmp/lept/gplot/pix1.%d", index++);
767 gplot =
gplotSimpleXY1(NULL, na, GPLOT_LINES, GPLOT_PNG, buf, title);
769 return (
PIX *)ERROR_PTR(
"failed to generate plot", __func__, NULL);
773 return (
PIX *)ERROR_PTR(
"failed to generate plot", __func__, NULL);
800 static l_int32 index;
805 return (
PIX *)ERROR_PTR(
"both na1, na2 not defined", __func__, NULL);
808 snprintf(buf,
sizeof(buf),
"/tmp/lept/gplot/pix2.%d", index++);
809 gplot =
gplotSimpleXY2(NULL, na1, na2, GPLOT_LINES, GPLOT_PNG, buf, title);
811 return (
PIX *)ERROR_PTR(
"failed to generate plot", __func__, NULL);
815 return (
PIX *)ERROR_PTR(
"failed to generate plot", __func__, NULL);
841 static l_int32 index;
846 return (
PIX *)ERROR_PTR(
"naa not defined", __func__, NULL);
849 snprintf(buf,
sizeof(buf),
"/tmp/lept/gplot/pixN.%d", index++);
850 gplot =
gplotSimpleXYN(NULL, naa, GPLOT_LINES, GPLOT_PNG, buf, title);
852 return (
PIX *)ERROR_PTR(
"failed to generate plot", __func__, NULL);
856 return (
PIX *)ERROR_PTR(
"failed to generate plot", __func__, NULL);
897 return (
GPLOT *)ERROR_PTR(
"nay not defined", __func__, NULL);
898 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
899 return (
GPLOT *)ERROR_PTR(
"invalid plotstyle", __func__, NULL);
900 if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
901 outformat != GPLOT_EPS && outformat != GPLOT_LATEX &&
902 outformat != GPLOT_PNM)
903 return (
GPLOT *)ERROR_PTR(
"invalid outformat", __func__, NULL);
905 return (
GPLOT *)ERROR_PTR(
"outroot not specified", __func__, NULL);
907 if ((gplot =
gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
908 return (
GPLOT *)ERROR_PTR(
"gplot not made", __func__, NULL);
953 return (
GPLOT *)ERROR_PTR(
"nay1 and nay2 not both defined",
955 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
956 return (
GPLOT *)ERROR_PTR(
"invalid plotstyle", __func__, NULL);
957 if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
958 outformat != GPLOT_EPS && outformat != GPLOT_LATEX &&
959 outformat != GPLOT_PNM)
960 return (
GPLOT *)ERROR_PTR(
"invalid outformat", __func__, NULL);
962 return (
GPLOT *)ERROR_PTR(
"outroot not specified", __func__, NULL);
964 if ((gplot =
gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
965 return (
GPLOT *)ERROR_PTR(
"gplot not made", __func__, NULL);
1003 const char *outroot,
1011 return (
GPLOT *)ERROR_PTR(
"naay not defined", __func__, NULL);
1013 return (
GPLOT *)ERROR_PTR(
"no numa in array", __func__, NULL);
1014 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
1015 return (
GPLOT *)ERROR_PTR(
"invalid plotstyle", __func__, NULL);
1016 if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
1017 outformat != GPLOT_EPS && outformat != GPLOT_LATEX &&
1018 outformat != GPLOT_PNM)
1019 return (
GPLOT *)ERROR_PTR(
"invalid outformat", __func__, NULL);
1021 return (
GPLOT *)ERROR_PTR(
"outroot not specified", __func__, NULL);
1023 if ((gplot =
gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
1024 return (
GPLOT *)ERROR_PTR(
"gplot not made", __func__, NULL);
1025 for (i = 0; i < n; i++) {
1056 const char *rootname,
1065 return (
PIX *)ERROR_PTR(
"na not defined", __func__, NULL);
1066 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
1067 return (
PIX *)ERROR_PTR(
"invalid plotstyle", __func__, NULL);
1069 return (
PIX *)ERROR_PTR(
"rootname not defined", __func__, NULL);
1071 gplot =
gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
1073 return (
PIX *)ERROR_PTR(
"gplot not made", __func__, NULL);
1104 const char *rootname,
1113 return (
PIX *)ERROR_PTR(
"na1 not defined", __func__, NULL);
1115 return (
PIX *)ERROR_PTR(
"na2 not defined", __func__, NULL);
1116 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
1117 return (
PIX *)ERROR_PTR(
"invalid plotstyle", __func__, NULL);
1119 return (
PIX *)ERROR_PTR(
"rootname not defined", __func__, NULL);
1121 gplot =
gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
1123 return (
PIX *)ERROR_PTR(
"gplot not made", __func__, NULL);
1154 const char *rootname,
1165 return (
PIX *)ERROR_PTR(
"nax not defined", __func__, NULL);
1167 return (
PIX *)ERROR_PTR(
"naay not defined", __func__, NULL);
1169 return (
PIX *)ERROR_PTR(
"no numa in array", __func__, NULL);
1170 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
1171 return (
PIX *)ERROR_PTR(
"invalid plotstyle", __func__, NULL);
1173 return (
PIX *)ERROR_PTR(
"rootname not defined", __func__, NULL);
1175 gplot =
gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
1177 return (
PIX *)ERROR_PTR(
"gplot not made", __func__, NULL);
1178 for (i = 0; i < n; i++) {
1202 char *rootname, *title, *xlabel, *ylabel, *ignores;
1203 l_int32 outformat, ret, version, ignore;
1208 return (
GPLOT *)ERROR_PTR(
"filename not defined", __func__, NULL);
1211 return (
GPLOT *)ERROR_PTR(
"stream not opened", __func__, NULL);
1213 ret = fscanf(fp,
"Gplot Version %d\n", &version);
1216 return (
GPLOT *)ERROR_PTR(
"not a gplot file", __func__, NULL);
1218 if (version != GPLOT_VERSION_NUMBER) {
1220 return (
GPLOT *)ERROR_PTR(
"invalid gplot version", __func__, NULL);
1223 ignore = fscanf(fp,
"Rootname: %511s\n", buf);
1225 ignore = fscanf(fp,
"Output format: %d\n", &outformat);
1226 ignores = fgets(buf, Bufsize, fp);
1228 title[strlen(title) - 1] =
'\0';
1229 ignores = fgets(buf, Bufsize, fp);
1231 xlabel[strlen(xlabel) - 1] =
'\0';
1232 ignores = fgets(buf, Bufsize, fp);
1234 ylabel[strlen(ylabel) - 1] =
'\0';
1236 gplot =
gplotCreate(rootname, outformat, title, xlabel, ylabel);
1237 LEPT_FREE(rootname);
1243 return (
GPLOT *)ERROR_PTR(
"gplot not made", __func__, NULL);
1251 ignore = fscanf(fp,
"Commandfile name: %511s\n", buf);
1253 ignore = fscanf(fp,
"\nCommandfile data:");
1255 ignore = fscanf(fp,
"\nDatafile names:");
1257 ignore = fscanf(fp,
"\nPlot data:");
1259 ignore = fscanf(fp,
"\nPlot titles:");
1261 ignore = fscanf(fp,
"\nPlot styles:");
1264 ignore = fscanf(fp,
"Number of plots: %d\n", &gplot->
nplots);
1265 ignore = fscanf(fp,
"Output file name: %511s\n", buf);
1267 ignore = fscanf(fp,
"Axis scaling: %d\n", &gplot->
scaling);
1288 return ERROR_INT(
"filename not defined", __func__, 1);
1290 return ERROR_INT(
"gplot not defined", __func__, 1);
1293 return ERROR_INT(
"stream not opened", __func__, 1);
1295 fprintf(fp,
"Gplot Version %d\n", GPLOT_VERSION_NUMBER);
1296 fprintf(fp,
"Rootname: %s\n", gplot->
rootname);
1297 fprintf(fp,
"Output format: %d\n", gplot->
outformat);
1298 fprintf(fp,
"Title: %s\n", gplot->
title);
1299 fprintf(fp,
"X axis label: %s\n", gplot->
xlabel);
1300 fprintf(fp,
"Y axis label: %s\n", gplot->
ylabel);
1302 fprintf(fp,
"Commandfile name: %s\n", gplot->
cmdname);
1303 fprintf(fp,
"\nCommandfile data:");
1305 fprintf(fp,
"\nDatafile names:");
1307 fprintf(fp,
"\nPlot data:");
1309 fprintf(fp,
"\nPlot titles:");
1311 fprintf(fp,
"\nPlot styles:");
1314 fprintf(fp,
"Number of plots: %d\n", gplot->
nplots);
1315 fprintf(fp,
"Output file name: %s\n", gplot->
outname);
1316 fprintf(fp,
"Axis scaling: %d\n", gplot->
scaling);
PIX * gplotSimplePix2(NUMA *na1, NUMA *na2, const char *title)
gplotSimplePix2()
l_ok gplotAddPlot(GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plotlabel)
gplotAddPlot()
l_ok gplotMakeOutput(GPLOT *gplot)
gplotMakeOutput()
GPLOT * gplotCreate(const char *rootname, l_int32 outformat, const char *title, const char *xlabel, const char *ylabel)
gplotCreate()
PIX * gplotGeneralPixN(NUMA *nax, NUMAA *naay, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel)
gplotGeneralPixN()
PIX * gplotMakeOutputPix(GPLOT *gplot)
gplotMakeOutputPix()
GPLOT * gplotSimpleXY1(NUMA *nax, NUMA *nay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY1()
void gplotDestroy(GPLOT **pgplot)
gplotDestroy()
l_ok gplotSimple2(NUMA *na1, NUMA *na2, l_int32 outformat, const char *outroot, const char *title)
gplotSimple2()
l_ok gplotWrite(const char *filename, GPLOT *gplot)
gplotWrite()
l_ok gplotGenCommandFile(GPLOT *gplot)
gplotGenCommandFile()
l_ok gplotSetScaling(GPLOT *gplot, l_int32 scaling)
gplotSetScaling()
GPLOT * gplotRead(const char *filename)
gplotRead()
PIX * gplotGeneralPix1(NUMA *na, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel)
gplotGeneralPix1()
PIX * gplotSimplePixN(NUMAA *naa, const char *title)
gplotSimplePixN()
const char * gplotstylenames[]
l_ok gplotSimpleN(NUMAA *naa, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleN()
PIX * gplotGeneralPix2(NUMA *na1, NUMA *na2, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel)
gplotGeneralPix2()
GPLOT * gplotSimpleXYN(NUMA *nax, NUMAA *naay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXYN()
l_ok gplotGenDataFiles(GPLOT *gplot)
gplotGenDataFiles()
PIX * gplotSimplePix1(NUMA *na, const char *title)
gplotSimplePix1()
GPLOT * gplotSimpleXY2(NUMA *nax, NUMA *nay1, NUMA *nay2, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY2()
const char * gplotfileoutputs[]
l_ok gplotSimple1(NUMA *na, l_int32 outformat, const char *outroot, const char *title)
gplotSimple1()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
NUMA * numaReadStream(FILE *fp)
numaReadStream()
l_ok numaGetFValue(NUMA *na, l_int32 index, l_float32 *pval)
numaGetFValue()
l_ok numaWriteStderr(NUMA *na)
numaWriteStderr()
NUMA * numaCreate(l_int32 n)
numaCreate()
l_int32 numaaGetCount(NUMAA *naa)
numaaGetCount()
NUMA * numaaGetNuma(NUMAA *naa, l_int32 index, l_int32 accessflag)
numaaGetNuma()
void numaDestroy(NUMA **pna)
numaDestroy()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok numaGetParameters(NUMA *na, l_float32 *pstartx, l_float32 *pdelx)
numaGetParameters()
PIX * pixRead(const char *filename)
pixRead()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
SARRAY * sarrayReadStream(FILE *fp)
sarrayReadStream()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
l_ok sarrayClear(SARRAY *sa)
sarrayClear()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
l_ok sarrayWriteStream(FILE *fp, SARRAY *sa)
sarrayWriteStream()
struct Sarray * datanames
struct Sarray * plotlabels
char * stringNew(const char *src)
stringNew()
l_ok stringReplace(char **pdest, const char *src)
stringReplace()
void callSystemDebug(const char *cmd)
callSystemDebug()
l_ok stringCheckForChars(const char *src, const char *chars, l_int32 *pfound)
stringCheckForChars()
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
char * genPathname(const char *dir, const char *fname)
genPathname()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
FILE * fopenReadStream(const char *filename)
fopenReadStream()