-----------------------------------------------------------------* * Basic Plotting Functions * *-----------------------------------------------------------------*/ ! * \brief gplotCreate() * * \param[in] rootname root for all output files * \param[in] outformat GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX * \param[in] title [optional] overa
| 135 | * </pre> |
| 136 | */ |
| 137 | GPLOT * |
| 138 | gplotCreate(const char *rootname, |
| 139 | l_int32 outformat, |
| 140 | const char *title, |
| 141 | const char *xlabel, |
| 142 | const char *ylabel) |
| 143 | { |
| 144 | char *newroot; |
| 145 | char buf[L_BUFSIZE]; |
| 146 | l_int32 badchar; |
| 147 | GPLOT *gplot; |
| 148 | |
| 149 | PROCNAME("gplotCreate"); |
| 150 | |
| 151 | if (!rootname) |
| 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); |
| 156 | stringCheckForChars(rootname, "`;&|><\"?*$()", &badchar); |
| 157 | if (badchar) /* danger of command injection */ |
| 158 | return (GPLOT *)ERROR_PTR("invalid rootname", procName, NULL); |
| 159 | |
| 160 | if ((gplot = (GPLOT *)LEPT_CALLOC(1, sizeof(GPLOT))) == NULL) |
| 161 | return (GPLOT *)ERROR_PTR("gplot not made", procName, NULL); |
| 162 | gplot->cmddata = sarrayCreate(0); |
| 163 | gplot->datanames = sarrayCreate(0); |
| 164 | gplot->plotdata = sarrayCreate(0); |
| 165 | gplot->plottitles = sarrayCreate(0); |
| 166 | gplot->plotstyles = numaCreate(0); |
| 167 | |
| 168 | /* Save title, labels, rootname, outformat, cmdname, outname */ |
| 169 | newroot = genPathname(rootname, NULL); |
| 170 | gplot->rootname = newroot; |
| 171 | gplot->outformat = outformat; |
| 172 | snprintf(buf, L_BUFSIZE, "%s.cmd", rootname); |
| 173 | gplot->cmdname = stringNew(buf); |
| 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); |
| 182 | gplot->outname = stringNew(buf); |
| 183 | if (title) gplot->title = stringNew(title); |
| 184 | if (xlabel) gplot->xlabel = stringNew(xlabel); |
| 185 | if (ylabel) gplot->ylabel = stringNew(ylabel); |
| 186 | |
| 187 | return gplot; |
| 188 | } |
| 189 | |
| 190 | |
| 191 | /*! |
no test coverage detected