144 #include <config_auto.h> 148 #include "allheaders.h" 198 PROCNAME(
"gplotCreate");
201 return (
GPLOT *)ERROR_PTR(
"rootname not defined", procName, NULL);
202 if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
203 outformat != GPLOT_EPS && outformat != GPLOT_LATEX &&
204 outformat != GPLOT_PNM)
205 return (
GPLOT *)ERROR_PTR(
"outformat invalid", procName, NULL);
208 return (
GPLOT *)ERROR_PTR(
"invalid rootname", procName, NULL);
210 #if !defined(HAVE_LIBPNG) 211 if (outformat == GPLOT_PNG) {
212 L_WARNING(
"png library missing; output pnm format\n", procName);
213 outformat = GPLOT_PNM;
217 gplot = (
GPLOT *)LEPT_CALLOC(1,
sizeof(
GPLOT));
228 snprintf(buf, Bufsize,
"%s.cmd", rootname);
230 if (outformat == GPLOT_PNG)
231 snprintf(buf, Bufsize,
"%s.png", newroot);
232 else if (outformat == GPLOT_PS)
233 snprintf(buf, Bufsize,
"%s.ps", newroot);
234 else if (outformat == GPLOT_EPS)
235 snprintf(buf, Bufsize,
"%s.eps", newroot);
236 else if (outformat == GPLOT_LATEX)
237 snprintf(buf, Bufsize,
"%s.tex", newroot);
238 else if (outformat == GPLOT_PNM)
239 snprintf(buf, Bufsize,
"%s.pnm", newroot);
259 PROCNAME(
"gplotDestroy");
261 if (pgplot == NULL) {
262 L_WARNING(
"ptr address is null!\n", procName);
266 if ((gplot = *pgplot) == NULL)
278 LEPT_FREE(gplot->
title);
324 const char *plotlabel)
327 char emptystring[] =
"";
328 char *datastr, *title;
330 l_float32 valx, valy, startx, delx;
333 PROCNAME(
"gplotAddPlot");
336 return ERROR_INT(
"gplot not defined", procName, 1);
338 return ERROR_INT(
"nay not defined", procName, 1);
339 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
340 return ERROR_INT(
"invalid plotstyle", procName, 1);
343 return ERROR_INT(
"no points to plot", procName, 1);
345 return ERROR_INT(
"nax and nay sizes differ", procName, 1);
346 if (n == 1 && plotstyle == GPLOT_LINES) {
347 L_INFO(
"only 1 pt; changing style to points\n", procName);
348 plotstyle = GPLOT_POINTS;
363 snprintf(buf, Bufsize,
"%s.data.%d", gplot->
rootname, gplot->
nplots);
368 for (i = 0; i < n; i++) {
372 valx = startx + i * delx;
374 snprintf(buf, Bufsize,
"%f %f\n", valx, valy);
403 PROCNAME(
"gplotSetScaling");
406 return ERROR_INT(
"gplot not defined", procName, 1);
408 scaling != GPLOT_LOG_SCALE_X &&
409 scaling != GPLOT_LOG_SCALE_Y &&
410 scaling != GPLOT_LOG_SCALE_X_Y)
411 return ERROR_INT(
"invalid gplot scaling", procName, 1);
433 PROCNAME(
"gplotMakeOutputPix");
436 return (
PIX *)ERROR_PTR(
"gplot not defined", procName, NULL);
438 return (
PIX *)ERROR_PTR(
"output format not an image", procName, NULL);
441 return (
PIX *)ERROR_PTR(
"plot output not made", procName, NULL);
471 PROCNAME(
"gplotMakeOutput");
474 return ERROR_INT(
"gplot not defined", procName, 1);
477 L_INFO(
"running gnuplot is disabled; " 478 "use setLeptDebugOK(1) to enable\n", procName);
483 return ERROR_INT(
"iOS 11 does not support system()", procName, 0);
491 snprintf(buf, Bufsize,
"gnuplot %s", cmdname);
493 snprintf(buf, Bufsize,
"wgnuplot %s", cmdname);
512 char *cmdstr, *plotlabel, *dataname;
513 l_int32 i, plotstyle, nplots;
516 PROCNAME(
"gplotGenCommandFile");
519 return ERROR_INT(
"gplot not defined", procName, 1);
526 snprintf(buf, Bufsize,
"set title '%s'", gplot->
title);
530 snprintf(buf, Bufsize,
"set xlabel '%s'", gplot->
xlabel);
534 snprintf(buf, Bufsize,
"set ylabel '%s'", gplot->
ylabel);
540 snprintf(buf, Bufsize,
"set terminal png; set output '%s'",
542 }
else if (gplot->
outformat == GPLOT_PS) {
543 snprintf(buf, Bufsize,
"set terminal postscript; set output '%s'",
545 }
else if (gplot->
outformat == GPLOT_EPS) {
546 snprintf(buf, Bufsize,
"set terminal postscript eps; set output '%s'",
548 }
else if (gplot->
outformat == GPLOT_LATEX) {
549 snprintf(buf, Bufsize,
"set terminal latex; set output '%s'",
551 }
else if (gplot->
outformat == GPLOT_PNM) {
552 snprintf(buf, Bufsize,
"set terminal pbm color; set output '%s'",
557 if (gplot->
scaling == GPLOT_LOG_SCALE_X ||
558 gplot->
scaling == GPLOT_LOG_SCALE_X_Y) {
559 snprintf(buf, Bufsize,
"set logscale x");
562 if (gplot->
scaling == GPLOT_LOG_SCALE_Y ||
563 gplot->
scaling == GPLOT_LOG_SCALE_X_Y) {
564 snprintf(buf, Bufsize,
"set logscale y");
569 for (i = 0; i < nplots; i++) {
574 snprintf(buf, Bufsize,
"plot '%s' title '%s' %s",
578 snprintf(buf, Bufsize,
"plot '%s' title '%s' %s, \\",
580 else if (i < nplots - 1)
581 snprintf(buf, Bufsize,
" '%s' title '%s' %s, \\",
584 snprintf(buf, Bufsize,
" '%s' title '%s' %s",
594 return ERROR_INT(
"cmd stream not opened", procName, 1);
596 fwrite(cmdstr, 1, strlen(cmdstr), fp);
619 char *plotdata, *dataname;
623 PROCNAME(
"gplotGenDataFiles");
626 return ERROR_INT(
"gplot not defined", procName, 1);
629 for (i = 0; i < nplots; i++) {
632 if ((fp = fopen(dataname,
"w")) == NULL)
633 return ERROR_INT(
"datafile stream not opened", procName, 1);
634 fwrite(plotdata, 1, strlen(plotdata), fp);
672 PROCNAME(
"gplotSimple1");
674 gplot =
gplotSimpleXY1(NULL, na, GPLOT_LINES, outformat, outroot, title);
676 return ERROR_INT(
"failed to generate plot", procName, 1);
711 PROCNAME(
"gplotSimple2");
714 outformat, outroot, title);
716 return ERROR_INT(
"failed to generate plot", procName, 1);
750 PROCNAME(
"gplotSimpleN");
752 gplot =
gplotSimpleXYN(NULL, naa, GPLOT_LINES, outformat, outroot, title);
754 return ERROR_INT(
"failed to generate plot", procName, 1);
780 static l_int32 index;
784 PROCNAME(
"gplotSimplePix1");
787 return (
PIX *)ERROR_PTR(
"na not defined", procName, NULL);
790 snprintf(buf,
sizeof(buf),
"/tmp/lept/gplot/pix1.%d", index++);
791 gplot =
gplotSimpleXY1(NULL, na, GPLOT_LINES, GPLOT_PNG, buf, title);
793 return (
PIX *)ERROR_PTR(
"failed to generate plot", procName, NULL);
797 return (
PIX *)ERROR_PTR(
"failed to generate plot", procName, NULL);
824 static l_int32 index;
828 PROCNAME(
"gplotSimplePix2");
831 return (
PIX *)ERROR_PTR(
"both na1, na2 not defined", procName, NULL);
834 snprintf(buf,
sizeof(buf),
"/tmp/lept/gplot/pix2.%d", index++);
835 gplot =
gplotSimpleXY2(NULL, na1, na2, GPLOT_LINES, GPLOT_PNG, buf, title);
837 return (
PIX *)ERROR_PTR(
"failed to generate plot", procName, NULL);
841 return (
PIX *)ERROR_PTR(
"failed to generate plot", procName, NULL);
867 static l_int32 index;
871 PROCNAME(
"gplotSimplePixN");
874 return (
PIX *)ERROR_PTR(
"naa not defined", procName, NULL);
877 snprintf(buf,
sizeof(buf),
"/tmp/lept/gplot/pixN.%d", index++);
878 gplot =
gplotSimpleXYN(NULL, naa, GPLOT_LINES, GPLOT_PNG, buf, title);
880 return (
PIX *)ERROR_PTR(
"failed to generate plot", procName, NULL);
884 return (
PIX *)ERROR_PTR(
"failed to generate plot", procName, NULL);
924 PROCNAME(
"gplotSimpleXY1");
927 return (
GPLOT *)ERROR_PTR(
"nay not defined", procName, NULL);
928 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
929 return (
GPLOT *)ERROR_PTR(
"invalid plotstyle", procName, NULL);
930 if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
931 outformat != GPLOT_EPS && outformat != GPLOT_LATEX &&
932 outformat != GPLOT_PNM)
933 return (
GPLOT *)ERROR_PTR(
"invalid outformat", procName, NULL);
935 return (
GPLOT *)ERROR_PTR(
"outroot not specified", procName, NULL);
937 if ((gplot =
gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
938 return (
GPLOT *)ERROR_PTR(
"gplot not made", procName, NULL);
982 PROCNAME(
"gplotSimpleXY2");
985 return (
GPLOT *)ERROR_PTR(
"nay1 and nay2 not both defined",
987 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
988 return (
GPLOT *)ERROR_PTR(
"invalid plotstyle", procName, NULL);
989 if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
990 outformat != GPLOT_EPS && outformat != GPLOT_LATEX &&
991 outformat != GPLOT_PNM)
992 return (
GPLOT *)ERROR_PTR(
"invalid outformat", procName, NULL);
994 return (
GPLOT *)ERROR_PTR(
"outroot not specified", procName, NULL);
996 if ((gplot =
gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
997 return (
GPLOT *)ERROR_PTR(
"gplot not made", procName, NULL);
1035 const char *outroot,
1042 PROCNAME(
"gplotSimpleXYN");
1045 return (
GPLOT *)ERROR_PTR(
"naay not defined", procName, NULL);
1047 return (
GPLOT *)ERROR_PTR(
"no numa in array", procName, NULL);
1048 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
1049 return (
GPLOT *)ERROR_PTR(
"invalid plotstyle", procName, NULL);
1050 if (outformat != GPLOT_PNG && outformat != GPLOT_PS &&
1051 outformat != GPLOT_EPS && outformat != GPLOT_LATEX &&
1052 outformat != GPLOT_PNM)
1053 return (
GPLOT *)ERROR_PTR(
"invalid outformat", procName, NULL);
1055 return (
GPLOT *)ERROR_PTR(
"outroot not specified", procName, NULL);
1057 if ((gplot =
gplotCreate(outroot, outformat, title, NULL, NULL)) == 0)
1058 return (
GPLOT *)ERROR_PTR(
"gplot not made", procName, NULL);
1059 for (i = 0; i < n; i++) {
1090 const char *rootname,
1098 PROCNAME(
"gplotGeneralPix1");
1101 return (
PIX *)ERROR_PTR(
"na not defined", procName, NULL);
1102 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
1103 return (
PIX *)ERROR_PTR(
"invalid plotstyle", procName, NULL);
1105 return (
PIX *)ERROR_PTR(
"rootname not defined", procName, NULL);
1107 gplot =
gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
1109 return (
PIX *)ERROR_PTR(
"gplot not made", procName, NULL);
1140 const char *rootname,
1148 PROCNAME(
"gplotGeneralPix2");
1151 return (
PIX *)ERROR_PTR(
"na1 not defined", procName, NULL);
1153 return (
PIX *)ERROR_PTR(
"na2 not defined", procName, NULL);
1154 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
1155 return (
PIX *)ERROR_PTR(
"invalid plotstyle", procName, NULL);
1157 return (
PIX *)ERROR_PTR(
"rootname not defined", procName, NULL);
1159 gplot =
gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
1161 return (
PIX *)ERROR_PTR(
"gplot not made", procName, NULL);
1192 const char *rootname,
1202 PROCNAME(
"gplotGeneralPixN");
1205 return (
PIX *)ERROR_PTR(
"nax not defined", procName, NULL);
1207 return (
PIX *)ERROR_PTR(
"naay not defined", procName, NULL);
1209 return (
PIX *)ERROR_PTR(
"no numa in array", procName, NULL);
1210 if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
1211 return (
PIX *)ERROR_PTR(
"invalid plotstyle", procName, NULL);
1213 return (
PIX *)ERROR_PTR(
"rootname not defined", procName, NULL);
1215 gplot =
gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
1217 return (
PIX *)ERROR_PTR(
"gplot not made", procName, NULL);
1218 for (i = 0; i < n; i++) {
1242 char *rootname, *title, *xlabel, *ylabel, *ignores;
1243 l_int32 outformat, ret, version, ignore;
1247 PROCNAME(
"gplotRead");
1250 return (
GPLOT *)ERROR_PTR(
"filename not defined", procName, NULL);
1253 return (
GPLOT *)ERROR_PTR(
"stream not opened", procName, NULL);
1255 ret = fscanf(fp,
"Gplot Version %d\n", &version);
1258 return (
GPLOT *)ERROR_PTR(
"not a gplot file", procName, NULL);
1260 if (version != GPLOT_VERSION_NUMBER) {
1262 return (
GPLOT *)ERROR_PTR(
"invalid gplot version", procName, NULL);
1265 ignore = fscanf(fp,
"Rootname: %511s\n", buf);
1267 ignore = fscanf(fp,
"Output format: %d\n", &outformat);
1268 ignores = fgets(buf, Bufsize, fp);
1270 title[strlen(title) - 1] =
'\0';
1271 ignores = fgets(buf, Bufsize, fp);
1273 xlabel[strlen(xlabel) - 1] =
'\0';
1274 ignores = fgets(buf, Bufsize, fp);
1276 ylabel[strlen(ylabel) - 1] =
'\0';
1278 gplot =
gplotCreate(rootname, outformat, title, xlabel, ylabel);
1279 LEPT_FREE(rootname);
1285 return (
GPLOT *)ERROR_PTR(
"gplot not made", procName, NULL);
1293 ignore = fscanf(fp,
"Commandfile name: %511s\n", buf);
1295 ignore = fscanf(fp,
"\nCommandfile data:");
1297 ignore = fscanf(fp,
"\nDatafile names:");
1299 ignore = fscanf(fp,
"\nPlot data:");
1301 ignore = fscanf(fp,
"\nPlot titles:");
1303 ignore = fscanf(fp,
"\nPlot styles:");
1306 ignore = fscanf(fp,
"Number of plots: %d\n", &gplot->
nplots);
1307 ignore = fscanf(fp,
"Output file name: %511s\n", buf);
1309 ignore = fscanf(fp,
"Axis scaling: %d\n", &gplot->
scaling);
1329 PROCNAME(
"gplotWrite");
1332 return ERROR_INT(
"filename not defined", procName, 1);
1334 return ERROR_INT(
"gplot not defined", procName, 1);
1337 return ERROR_INT(
"stream not opened", procName, 1);
1339 fprintf(fp,
"Gplot Version %d\n", GPLOT_VERSION_NUMBER);
1340 fprintf(fp,
"Rootname: %s\n", gplot->
rootname);
1341 fprintf(fp,
"Output format: %d\n", gplot->
outformat);
1342 fprintf(fp,
"Title: %s\n", gplot->
title);
1343 fprintf(fp,
"X axis label: %s\n", gplot->
xlabel);
1344 fprintf(fp,
"Y axis label: %s\n", gplot->
ylabel);
1346 fprintf(fp,
"Commandfile name: %s\n", gplot->
cmdname);
1347 fprintf(fp,
"\nCommandfile data:");
1349 fprintf(fp,
"\nDatafile names:");
1351 fprintf(fp,
"\nPlot data:");
1353 fprintf(fp,
"\nPlot titles:");
1355 fprintf(fp,
"\nPlot styles:");
1358 fprintf(fp,
"Number of plots: %d\n", gplot->
nplots);
1359 fprintf(fp,
"Output file name: %s\n", gplot->
outname);
1360 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()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
l_ok stringCheckForChars(const char *src, const char *chars, l_int32 *pfound)
stringCheckForChars()
PIX * gplotGeneralPixN(NUMA *nax, NUMAA *naay, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel)
gplotGeneralPixN()
PIX * gplotGeneralPix2(NUMA *na1, NUMA *na2, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel)
gplotGeneralPix2()
char * genPathname(const char *dir, const char *fname)
genPathname()
GPLOT * gplotSimpleXY1(NUMA *nax, NUMA *nay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY1()
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()
PIX * gplotSimplePixN(NUMAA *naa, const char *title)
gplotSimplePixN()
struct Sarray * datanames
const char * gplotfileoutputs[]
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
l_ok sarrayWriteStream(FILE *fp, SARRAY *sa)
sarrayWriteStream()
NUMA * numaCreate(l_int32 n)
numaCreate()
PIX * gplotGeneralPix1(NUMA *na, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel)
gplotGeneralPix1()
NUMA * numaaGetNuma(NUMAA *naa, l_int32 index, l_int32 accessflag)
numaaGetNuma()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
struct Sarray * plotlabels
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
l_ok gplotGenDataFiles(GPLOT *gplot)
gplotGenDataFiles()
PIX * gplotSimplePix2(NUMA *na1, NUMA *na2, const char *title)
gplotSimplePix2()
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 gplotAddPlot(GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plotlabel)
gplotAddPlot()
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()
GPLOT * gplotSimpleXY2(NUMA *nax, NUMA *nay1, NUMA *nay2, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXY2()
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
l_ok gplotWrite(const char *filename, GPLOT *gplot)
gplotWrite()
PIX * pixRead(const char *filename)
pixRead()
l_int32 numaaGetCount(NUMAA *naa)
numaaGetCount()
PIX * gplotMakeOutputPix(GPLOT *gplot)
gplotMakeOutputPix()
GPLOT * gplotSimpleXYN(NUMA *nax, NUMAA *naay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title)
gplotSimpleXYN()
void callSystemDebug(const char *cmd)
callSystemDebug()
l_ok gplotGenCommandFile(GPLOT *gplot)
gplotGenCommandFile()
const char * gplotstylenames[]
PIX * gplotSimplePix1(NUMA *na, const char *title)
gplotSimplePix1()
SARRAY * sarrayReadStream(FILE *fp)
sarrayReadStream()
l_ok numaWriteStderr(NUMA *na)
numaWriteStderr()
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()