-----------------------------------------------------------------* * Serialize for I/O * *-----------------------------------------------------------------*/ ! * \brief gplotRead() * * \param[in] filename * \return gplot, or NULL on error */
| 824 | * \return gplot, or NULL on error |
| 825 | */ |
| 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:"); |
nothing calls this directly
no test coverage detected