MCPcopy Create free account
hub / github.com/creatale/node-dv / gplotRead

Function gplotRead

deps/leptonica/src/gplot.c:826–901  ·  view source on GitHub ↗

-----------------------------------------------------------------* * Serialize for I/O * *-----------------------------------------------------------------*/ ! * \brief gplotRead() * * \param[in] filename * \return gplot, or NULL on error */

Source from the content-addressed store, hash-verified

824 * \return gplot, or NULL on error
825 */
826GPLOT *
827gplotRead(const char *filename)
828{
829char buf[L_BUFSIZE];
830char *rootname, *title, *xlabel, *ylabel, *ignores;
831l_int32 outformat, ret, version, ignore;
832FILE *fp;
833GPLOT *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:");

Callers

nothing calls this directly

Calls 9

fopenReadStreamFunction · 0.85
fscanfFunction · 0.85
stringNewFunction · 0.85
gplotCreateFunction · 0.85
sarrayDestroyFunction · 0.85
numaDestroyFunction · 0.85
stringReplaceFunction · 0.85
sarrayReadStreamFunction · 0.85
numaReadStreamFunction · 0.85

Tested by

no test coverage detected