code beautified
This commit is contained in:
parent
ee5de05933
commit
6a1f801038
|
|
@ -1,3 +1,6 @@
|
|||
2011-08-19 Holger Vogt
|
||||
* rawfile.c: code beautified
|
||||
|
||||
2011-08-14 Robert Larice
|
||||
* src/frontend/postsc.c :
|
||||
postsc.c, swallow warnings
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ int raw_prec = -1; /* How many sigfigs to use, default 15 (max). */
|
|||
|
||||
#ifdef HAS_WINDOWS
|
||||
#undef fscanf /* redo I/O from WINMAIN.C here
|
||||
otherwise reading ASCII will not work */
|
||||
otherwise reading ASCII will not work */
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -53,8 +53,8 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
|
||||
/* Why bother printing out an empty plot? */
|
||||
if (!pl->pl_dvecs) {
|
||||
fprintf(cp_err, "Error: plot is empty, nothing written.\n");
|
||||
return;
|
||||
fprintf(cp_err, "Error: plot is empty, nothing written.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (raw_prec != -1)
|
||||
|
|
@ -63,22 +63,21 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
prec = DEFPREC;
|
||||
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
/* - Binary file binary write - hvogt 15.03.2000 ---------------------*/
|
||||
/* - Binary file binary write - hvogt 15.03.2000 ---------------------*/
|
||||
if (binary) {
|
||||
if ((fp = fopen(name, app ? "ab" : "wb")) == NULL) {
|
||||
perror(name);
|
||||
return;
|
||||
}
|
||||
fprintf(cp_out,"binary raw file\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ((fp = fopen(name, app ? "a" : "w")) == NULL) {
|
||||
perror(name);
|
||||
return;
|
||||
}
|
||||
fprintf(cp_out,"ASCII raw file\n");
|
||||
}
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* --------------------------------------------------------------------*/
|
||||
|
||||
#else
|
||||
|
||||
|
|
@ -95,34 +94,34 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
if (iscomplex(v))
|
||||
realflag = FALSE;
|
||||
nvars++;
|
||||
/* Find the length and dimensions of the longest vector
|
||||
* in the plot.
|
||||
* Be paranoid and assume somewhere we may have
|
||||
* forgotten to set the dimensions of 1-D vectors.
|
||||
*/
|
||||
if (v->v_numdims <= 1) {
|
||||
v->v_numdims = 1;
|
||||
v->v_dims[0] = v->v_length;
|
||||
}
|
||||
if (v->v_length > length) {
|
||||
length = v->v_length;
|
||||
numdims = v->v_numdims;
|
||||
for (j = 0; j < numdims; j++) {
|
||||
dims[j] = v->v_dims[j];
|
||||
}
|
||||
}
|
||||
/* Find the length and dimensions of the longest vector
|
||||
* in the plot.
|
||||
* Be paranoid and assume somewhere we may have
|
||||
* forgotten to set the dimensions of 1-D vectors.
|
||||
*/
|
||||
if (v->v_numdims <= 1) {
|
||||
v->v_numdims = 1;
|
||||
v->v_dims[0] = v->v_length;
|
||||
}
|
||||
if (v->v_length > length) {
|
||||
length = v->v_length;
|
||||
numdims = v->v_numdims;
|
||||
for (j = 0; j < numdims; j++) {
|
||||
dims[j] = v->v_dims[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(fp, "Title: %s\n", pl->pl_title);
|
||||
fprintf(fp, "Date: %s\n", pl->pl_date);
|
||||
fprintf(fp, "Plotname: %s\n", pl->pl_name);
|
||||
fprintf(fp, "Flags: %s%s\n",
|
||||
realflag ? "real" : "complex", raw_padding ? "" : " unpadded" );
|
||||
realflag ? "real" : "complex", raw_padding ? "" : " unpadded" );
|
||||
fprintf(fp, "No. Variables: %d\n", nvars);
|
||||
fprintf(fp, "No. Points: %d\n", length);
|
||||
if (numdims > 1) {
|
||||
dimstring(dims, numdims, buf);
|
||||
fprintf(fp, "Dimensions: %s\n", buf);
|
||||
dimstring(dims, numdims, buf);
|
||||
fprintf(fp, "Dimensions: %s\n", buf);
|
||||
}
|
||||
|
||||
for (wl = pl->pl_commands; wl; wl = wl->wl_next)
|
||||
|
|
@ -156,18 +155,18 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
|
||||
fprintf(fp, "Variables:\n");
|
||||
for (i = 0, v = pl->pl_dvecs; v; v = v->v_next) {
|
||||
if ( strcmp( ft_typenames(v->v_type), "current" ) == 0 ) {
|
||||
branch = NULL;
|
||||
if ((branch = strstr( v->v_name, "#branch" )) != NULL) {
|
||||
*branch = '\0';
|
||||
}
|
||||
fprintf(fp, "\t%d\ti(%s)\t%s", i++, v->v_name, ft_typenames(v->v_type));
|
||||
if ( branch != NULL ) *branch = '#';
|
||||
} else if ( strcmp( ft_typenames(v->v_type), "voltage" ) == 0 ) {
|
||||
fprintf(fp, "\t%d\t%s\t%s", i++, v->v_name, ft_typenames(v->v_type));
|
||||
} else {
|
||||
fprintf(fp, "\t%d\t%s\t%s", i++, v->v_name, ft_typenames(v->v_type));
|
||||
}
|
||||
if ( strcmp( ft_typenames(v->v_type), "current" ) == 0 ) {
|
||||
branch = NULL;
|
||||
if ((branch = strstr( v->v_name, "#branch" )) != NULL) {
|
||||
*branch = '\0';
|
||||
}
|
||||
fprintf(fp, "\t%d\ti(%s)\t%s", i++, v->v_name, ft_typenames(v->v_type));
|
||||
if ( branch != NULL ) *branch = '#';
|
||||
} else if ( strcmp( ft_typenames(v->v_type), "voltage" ) == 0 ) {
|
||||
fprintf(fp, "\t%d\t%s\t%s", i++, v->v_name, ft_typenames(v->v_type));
|
||||
} else {
|
||||
fprintf(fp, "\t%d\t%s\t%s", i++, v->v_name, ft_typenames(v->v_type));
|
||||
}
|
||||
if (v->v_flags & VF_MINGIVEN)
|
||||
fprintf(fp, " min=%e", v->v_minsignal);
|
||||
if (v->v_flags & VF_MAXGIVEN)
|
||||
|
|
@ -178,18 +177,18 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
fprintf(fp, " grid=%d", v->v_gridtype);
|
||||
if (v->v_plottype)
|
||||
fprintf(fp, " plot=%d", v->v_plottype);
|
||||
/* Only write dims if they are different from default. */
|
||||
writedims = FALSE;
|
||||
if (v->v_numdims != numdims) {
|
||||
writedims = TRUE;
|
||||
} else {
|
||||
for (j = 0; j < numdims; j++)
|
||||
if (dims[j] != v->v_dims[j])
|
||||
writedims = TRUE;
|
||||
}
|
||||
if (writedims) {
|
||||
dimstring(v->v_dims, v->v_numdims, buf);
|
||||
fprintf(fp, " dims=%s",buf);
|
||||
/* Only write dims if they are different from default. */
|
||||
writedims = FALSE;
|
||||
if (v->v_numdims != numdims) {
|
||||
writedims = TRUE;
|
||||
} else {
|
||||
for (j = 0; j < numdims; j++)
|
||||
if (dims[j] != v->v_dims[j])
|
||||
writedims = TRUE;
|
||||
}
|
||||
if (writedims) {
|
||||
dimstring(v->v_dims, v->v_numdims, buf);
|
||||
fprintf(fp, " dims=%s",buf);
|
||||
}
|
||||
(void) putc('\n', fp);
|
||||
}
|
||||
|
|
@ -198,69 +197,69 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
fprintf(fp, "Binary:\n");
|
||||
for (i = 0; i < length; i++) {
|
||||
for (v = pl->pl_dvecs; v; v = v->v_next) {
|
||||
/* Don't run off the end of this vector's data. */
|
||||
if (i < v->v_length) {
|
||||
if (realflag) {
|
||||
dd = (isreal(v) ? v->v_realdata[i] :
|
||||
realpart(&v->v_compdata[i]));
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
} else if (isreal(v)) {
|
||||
dd = v->v_realdata[i];
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
dd = 0.0;
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
} else {
|
||||
dd = realpart(&v->v_compdata[i]);
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
dd = imagpart(&v->v_compdata[i]);
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
}
|
||||
/* Don't run off the end of this vector's data. */
|
||||
if (i < v->v_length) {
|
||||
if (realflag) {
|
||||
dd = (isreal(v) ? v->v_realdata[i] :
|
||||
realpart(&v->v_compdata[i]));
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
} else if (isreal(v)) {
|
||||
dd = v->v_realdata[i];
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
dd = 0.0;
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
} else {
|
||||
dd = realpart(&v->v_compdata[i]);
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
dd = imagpart(&v->v_compdata[i]);
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
}
|
||||
} else if (raw_padding) {
|
||||
dd = 0.0;
|
||||
if (realflag) {
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
} else {
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
}
|
||||
}
|
||||
dd = 0.0;
|
||||
if (realflag) {
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
} else {
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
(void) fwrite(&dd, sizeof
|
||||
(double), 1, fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(fp, "Values:\n");
|
||||
for (i = 0; i < length; i++) {
|
||||
fprintf(fp, " %d", i);
|
||||
for (v = pl->pl_dvecs; v; v = v->v_next) {
|
||||
if (i < v->v_length) {
|
||||
if (realflag)
|
||||
fprintf(fp, "\t%.*e\n", prec,
|
||||
isreal(v) ? v->v_realdata[i] :
|
||||
realpart(&v->v_compdata[i]));
|
||||
else if (isreal(v))
|
||||
fprintf(fp, "\t%.*e,0.0\n", prec,
|
||||
v->v_realdata[i]);
|
||||
else
|
||||
fprintf(fp, "\t%.*e,%.*e\n", prec,
|
||||
realpart(&v->v_compdata[i]),
|
||||
prec,
|
||||
imagpart(&v->v_compdata[i]));
|
||||
for (v = pl->pl_dvecs; v; v = v->v_next) {
|
||||
if (i < v->v_length) {
|
||||
if (realflag)
|
||||
fprintf(fp, "\t%.*e\n", prec,
|
||||
isreal(v) ? v->v_realdata[i] :
|
||||
realpart(&v->v_compdata[i]));
|
||||
else if (isreal(v))
|
||||
fprintf(fp, "\t%.*e,0.0\n", prec,
|
||||
v->v_realdata[i]);
|
||||
else
|
||||
fprintf(fp, "\t%.*e,%.*e\n", prec,
|
||||
realpart(&v->v_compdata[i]),
|
||||
prec,
|
||||
imagpart(&v->v_compdata[i]));
|
||||
} else if (raw_padding) {
|
||||
if (realflag) {
|
||||
fprintf(fp, "\t%.*e\n", prec, 0.0);
|
||||
} else {
|
||||
fprintf(fp, "\t%.*e,%.*e\n",
|
||||
prec, 0.0, prec, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (realflag) {
|
||||
fprintf(fp, "\t%.*e\n", prec, 0.0);
|
||||
} else {
|
||||
fprintf(fp, "\t%.*e,%.*e\n",
|
||||
prec, 0.0, prec, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
(void) putc('\n', fp);
|
||||
}
|
||||
}
|
||||
|
|
@ -278,8 +277,7 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
#define nonl(s) r = (s); while (*r && (*r != '\n')) r++; *r = '\0'
|
||||
|
||||
struct plot *
|
||||
raw_read(char *name)
|
||||
{
|
||||
raw_read(char *name) {
|
||||
char *title = "default title";
|
||||
char *date = 0;
|
||||
struct plot *plots = NULL, *curpl = NULL;
|
||||
|
|
@ -304,13 +302,13 @@ raw_read(char *name)
|
|||
}
|
||||
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
/* Test, whether file really ASCII, otherwise assume binary hvogt 15.3.2000 */
|
||||
/* Test, whether file really ASCII, otherwise assume binary hvogt 15.3.2000 */
|
||||
while (fgets(buf, BSIZE_SP, fp)) {
|
||||
if (ciprefix("values:", buf)) {
|
||||
binary = FALSE;
|
||||
rewind(fp); /* rewind */
|
||||
fprintf(cp_err, "\nASCII raw file\n");
|
||||
break;
|
||||
binary = FALSE;
|
||||
rewind(fp); /* rewind */
|
||||
fprintf(cp_err, "\nASCII raw file\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -319,10 +317,10 @@ raw_read(char *name)
|
|||
if ((fp = fopen(name, "rb")) == NULL) {
|
||||
perror(name);
|
||||
return (NULL);
|
||||
}
|
||||
fprintf(cp_err, "\nbinary raw file\n");
|
||||
}
|
||||
/*--------------------------------------------------------*/
|
||||
fprintf(cp_err, "\nbinary raw file\n");
|
||||
}
|
||||
/*--------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
/* Since we call cp_evloop() from here, we have to do this junk. */
|
||||
|
|
@ -364,8 +362,8 @@ raw_read(char *name)
|
|||
curpl->pl_next = plots;
|
||||
plots = curpl;
|
||||
curpl->pl_name = copy(s);
|
||||
if (!date)
|
||||
date = copy(datestring( ));
|
||||
if (!date)
|
||||
date = copy(datestring( ));
|
||||
curpl->pl_date = date;
|
||||
curpl->pl_title = copy(title);
|
||||
flags = VF_PERMANENT;
|
||||
|
|
@ -379,13 +377,13 @@ raw_read(char *name)
|
|||
else if (cieq(t, "complex"))
|
||||
flags |= VF_COMPLEX;
|
||||
else if (cieq(t, "unpadded"))
|
||||
raw_padded = FALSE;
|
||||
raw_padded = FALSE;
|
||||
else if (cieq(t, "padded"))
|
||||
raw_padded = TRUE;
|
||||
else
|
||||
raw_padded = TRUE;
|
||||
else
|
||||
fprintf(cp_err,
|
||||
"Warning: unknown flag %s\n",
|
||||
t);
|
||||
"Warning: unknown flag %s\n",
|
||||
t);
|
||||
}
|
||||
} else if (ciprefix("no. variables:", buf)) {
|
||||
s = buf;
|
||||
|
|
@ -398,35 +396,35 @@ raw_read(char *name)
|
|||
skip(s);
|
||||
npoints = scannum(s);
|
||||
} else if (ciprefix("dimensions:", buf)) {
|
||||
if (npoints == 0) {
|
||||
fprintf(cp_err,
|
||||
"Error: misplaced Dimensions: line\n");
|
||||
continue;
|
||||
}
|
||||
if (npoints == 0) {
|
||||
fprintf(cp_err,
|
||||
"Error: misplaced Dimensions: line\n");
|
||||
continue;
|
||||
}
|
||||
s = buf;
|
||||
skip(s);
|
||||
if (atodims(s, dims, &numdims)) { /* Something's wrong. */
|
||||
fprintf(cp_err,
|
||||
"Warning: syntax error in dimensions, ignored.\n");
|
||||
numdims = 0;
|
||||
continue;
|
||||
}
|
||||
if (numdims > MAXDIMS) {
|
||||
numdims = 0;
|
||||
continue;
|
||||
}
|
||||
/* Let's just make sure that the no. of points
|
||||
* and the dimensions are consistent.
|
||||
*/
|
||||
for (j = 0, ndimpoints = 1; j < numdims; j++) {
|
||||
ndimpoints *= dims[j];
|
||||
}
|
||||
|
||||
if (ndimpoints != npoints) {
|
||||
if (atodims(s, dims, &numdims)) { /* Something's wrong. */
|
||||
fprintf(cp_err,
|
||||
"Warning: dimensions inconsistent with no. of points, ignored.\n");
|
||||
numdims = 0;
|
||||
}
|
||||
"Warning: syntax error in dimensions, ignored.\n");
|
||||
numdims = 0;
|
||||
continue;
|
||||
}
|
||||
if (numdims > MAXDIMS) {
|
||||
numdims = 0;
|
||||
continue;
|
||||
}
|
||||
/* Let's just make sure that the no. of points
|
||||
* and the dimensions are consistent.
|
||||
*/
|
||||
for (j = 0, ndimpoints = 1; j < numdims; j++) {
|
||||
ndimpoints *= dims[j];
|
||||
}
|
||||
|
||||
if (ndimpoints != npoints) {
|
||||
fprintf(cp_err,
|
||||
"Warning: dimensions inconsistent with no. of points, ignored.\n");
|
||||
numdims = 0;
|
||||
}
|
||||
} else if (ciprefix("command:", buf)) {
|
||||
/* Note that we reverse these commands eventually... */
|
||||
s = buf;
|
||||
|
|
@ -440,8 +438,8 @@ raw_read(char *name)
|
|||
curpl->pl_commands->wl_prev = wl;
|
||||
curpl->pl_commands = wl;
|
||||
} else
|
||||
fprintf(cp_err,
|
||||
"Error: misplaced Command: line\n");
|
||||
fprintf(cp_err,
|
||||
"Error: misplaced Command: line\n");
|
||||
/* Now execute the command if we can. */
|
||||
(void) cp_evloop(s);
|
||||
} else if (ciprefix("option:", buf)) {
|
||||
|
|
@ -458,8 +456,8 @@ raw_read(char *name)
|
|||
else
|
||||
curpl->pl_env = cp_setparse(wl);
|
||||
} else
|
||||
fprintf(cp_err,
|
||||
"Error: misplaced Option: line\n");
|
||||
fprintf(cp_err,
|
||||
"Error: misplaced Option: line\n");
|
||||
} else if (ciprefix("variables:", buf)) {
|
||||
/* We reverse the dvec list eventually... */
|
||||
if (!curpl) {
|
||||
|
|
@ -473,14 +471,14 @@ raw_read(char *name)
|
|||
(void) fgets(buf, BSIZE_SP, fp);
|
||||
s = buf;
|
||||
}
|
||||
if (numdims == 0) {
|
||||
numdims = 1;
|
||||
dims[0] = npoints;
|
||||
}
|
||||
if (numdims == 0) {
|
||||
numdims = 1;
|
||||
dims[0] = npoints;
|
||||
}
|
||||
/* Now read all the variable lines in. */
|
||||
for (i = 0; i < nvars; i++) {
|
||||
v = alloc(struct dvec);
|
||||
ZERO(v, struct dvec);
|
||||
ZERO(v, struct dvec);
|
||||
v->v_next = curpl->pl_dvecs;
|
||||
curpl->pl_dvecs = v;
|
||||
if (!curpl->pl_scale)
|
||||
|
|
@ -488,8 +486,8 @@ raw_read(char *name)
|
|||
v->v_flags = (short)flags;
|
||||
v->v_plot = curpl;
|
||||
v->v_length = npoints;
|
||||
v->v_numdims = 0;
|
||||
/* Length and dims might be changed by options. */
|
||||
v->v_numdims = 0;
|
||||
/* Length and dims might be changed by options. */
|
||||
|
||||
if (!i)
|
||||
curpl->pl_scale = v;
|
||||
|
|
@ -501,80 +499,80 @@ raw_read(char *name)
|
|||
if ((t = gettok(&s)) != NULL)
|
||||
v->v_name = t;
|
||||
else {
|
||||
fprintf(cp_err,
|
||||
"Error: bad var line %s\n",
|
||||
buf);
|
||||
/* MW. v_name must be valid in the case that no. points = 0 */
|
||||
v->v_name = "no vars\n";
|
||||
}
|
||||
fprintf(cp_err,
|
||||
"Error: bad var line %s\n",
|
||||
buf);
|
||||
/* MW. v_name must be valid in the case that no. points = 0 */
|
||||
v->v_name = "no vars\n";
|
||||
}
|
||||
t = gettok(&s); /* The type name. */
|
||||
if (t)
|
||||
v->v_type = ft_typnum(t);
|
||||
else
|
||||
fprintf(cp_err,
|
||||
"Error: bad var line %s\n",
|
||||
buf);
|
||||
|
||||
fprintf(cp_err,
|
||||
"Error: bad var line %s\n",
|
||||
buf);
|
||||
|
||||
/* Fix the name... */
|
||||
if (isdigit(*v->v_name) && (r = ft_typabbrev(v
|
||||
->v_type)) != NULL) {
|
||||
->v_type)) != NULL) {
|
||||
(void) sprintf(buf2, "%s(%s)", r,
|
||||
v->v_name);
|
||||
v->v_name);
|
||||
v->v_name = copy(buf2);
|
||||
}
|
||||
/* Now come the strange options... */
|
||||
while ((t = gettok(&s)) != NULL) {
|
||||
if (ciprefix("min=", t)) {
|
||||
if (sscanf(t + 4, "%lf",
|
||||
&v->v_minsignal) != 1)
|
||||
&v->v_minsignal) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad arg %s\n",
|
||||
t);
|
||||
"Error: bad arg %s\n",
|
||||
t);
|
||||
v->v_flags |= VF_MINGIVEN;
|
||||
} else if (ciprefix("max=", t)) {
|
||||
if (sscanf(t + 4, "%lf",
|
||||
&v->v_maxsignal) != 1)
|
||||
&v->v_maxsignal) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad arg %s\n",
|
||||
t);
|
||||
"Error: bad arg %s\n",
|
||||
t);
|
||||
v->v_flags |= VF_MAXGIVEN;
|
||||
} else if (ciprefix("color=", t)) {
|
||||
v->v_defcolor = copy(t + 6);
|
||||
} else if (ciprefix("scale=", t)) {
|
||||
/* This is bad, but... */
|
||||
v->v_scale = (struct dvec *)
|
||||
copy(t + 6);
|
||||
copy(t + 6);
|
||||
} else if (ciprefix("grid=", t)) {
|
||||
v->v_gridtype = (GRIDTYPE)
|
||||
scannum(t + 5);
|
||||
scannum(t + 5);
|
||||
} else if (ciprefix("plot=", t)) {
|
||||
v->v_plottype = (PLOTTYPE)
|
||||
scannum(t + 5);
|
||||
scannum(t + 5);
|
||||
} else if (ciprefix("dims=", t)) {
|
||||
fixdims(v, t + 5);
|
||||
} else {
|
||||
fprintf(cp_err,
|
||||
"Warning: bad var param %s\n",
|
||||
t);
|
||||
fprintf(cp_err,
|
||||
"Warning: bad var param %s\n",
|
||||
t);
|
||||
}
|
||||
}
|
||||
/* Now we default any missing dimensions. */
|
||||
if (!v->v_numdims) {
|
||||
v->v_numdims = numdims;
|
||||
for (j = 0; j < numdims; j++)
|
||||
v->v_dims[j] = dims[j];
|
||||
}
|
||||
/* And allocate the data array. We would use
|
||||
* the desired vector length, but this would
|
||||
* be dangerous if the file is invalid.
|
||||
*/
|
||||
/* Now we default any missing dimensions. */
|
||||
if (!v->v_numdims) {
|
||||
v->v_numdims = numdims;
|
||||
for (j = 0; j < numdims; j++)
|
||||
v->v_dims[j] = dims[j];
|
||||
}
|
||||
/* And allocate the data array. We would use
|
||||
* the desired vector length, but this would
|
||||
* be dangerous if the file is invalid.
|
||||
*/
|
||||
if (isreal(v))
|
||||
v->v_realdata = TMALLOC(double, npoints);
|
||||
else
|
||||
v->v_compdata = TMALLOC(ngcomplex_t, npoints);
|
||||
}
|
||||
} else if (ciprefix("values:", buf) ||
|
||||
ciprefix("binary:", buf)) {
|
||||
} else if (ciprefix("values:", buf) ||
|
||||
ciprefix("binary:", buf)) {
|
||||
if (!curpl) {
|
||||
fprintf(cp_err, "Error: no plot name given\n");
|
||||
plots = NULL;
|
||||
|
|
@ -588,102 +586,102 @@ raw_read(char *name)
|
|||
v->v_next = curpl->pl_dvecs;
|
||||
curpl->pl_dvecs = v;
|
||||
}
|
||||
|
||||
|
||||
/* And fix the scale pointers. */
|
||||
for (v = curpl->pl_dvecs; v; v = v->v_next) {
|
||||
if (v->v_scale) {
|
||||
for (nv = curpl->pl_dvecs; nv; nv =
|
||||
nv->v_next)
|
||||
nv->v_next)
|
||||
if (cieq((char *) v->v_scale,
|
||||
nv->v_name)) {
|
||||
nv->v_name)) {
|
||||
v->v_scale = nv;
|
||||
break;
|
||||
}
|
||||
if (!nv) {
|
||||
fprintf(cp_err,
|
||||
"Error: no such vector %s\n",
|
||||
(char *) v->v_scale);
|
||||
"Error: no such vector %s\n",
|
||||
(char *) v->v_scale);
|
||||
v->v_scale = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < npoints; i++) {
|
||||
if ((*buf == 'v') || (*buf == 'V')) {
|
||||
/* It's an ASCII file. */
|
||||
(void) fscanf(fp, " %d", &j);
|
||||
for (v = curpl->pl_dvecs; v; v = v->v_next) {
|
||||
if (i < v->v_length) {
|
||||
if (flags & VF_REAL) {
|
||||
if (fscanf(fp, " %lf",
|
||||
&v->v_realdata[i]) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
} else {
|
||||
if (fscanf(fp, " %lf, %lf",
|
||||
&realpart(&v->v_compdata[i]),
|
||||
&imagpart(&v->v_compdata[i])) != 2)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
}
|
||||
} else if (raw_padded) {
|
||||
if (flags & VF_REAL) {
|
||||
if (fscanf(fp, " %lf",
|
||||
&junk) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
} else {
|
||||
if (fscanf(fp, " %lf, %lf",
|
||||
&junk, &junk) != 2)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* It's a Binary file. */
|
||||
/* It's an ASCII file. */
|
||||
(void) fscanf(fp, " %d", &j);
|
||||
for (v = curpl->pl_dvecs; v; v = v->v_next) {
|
||||
if (i < v->v_length) {
|
||||
if (flags & VF_REAL) {
|
||||
if (fread(&v->v_realdata[i],
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
} else {
|
||||
if (fread(&v->v_compdata[i].cx_real,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
if (fread(&v->v_compdata[i].cx_imag,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
}
|
||||
} else if (raw_padded) {
|
||||
if (flags & VF_REAL) {
|
||||
if (fread(&junk,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
} else {
|
||||
if (fread(&junk,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
if (fread(&junk,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i < v->v_length) {
|
||||
if (flags & VF_REAL) {
|
||||
if (fscanf(fp, " %lf",
|
||||
&v->v_realdata[i]) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
} else {
|
||||
if (fscanf(fp, " %lf, %lf",
|
||||
&realpart(&v->v_compdata[i]),
|
||||
&imagpart(&v->v_compdata[i])) != 2)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
}
|
||||
} else if (raw_padded) {
|
||||
if (flags & VF_REAL) {
|
||||
if (fscanf(fp, " %lf",
|
||||
&junk) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
} else {
|
||||
if (fscanf(fp, " %lf, %lf",
|
||||
&junk, &junk) != 2)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* It's a Binary file. */
|
||||
for (v = curpl->pl_dvecs; v; v = v->v_next) {
|
||||
if (i < v->v_length) {
|
||||
if (flags & VF_REAL) {
|
||||
if (fread(&v->v_realdata[i],
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
} else {
|
||||
if (fread(&v->v_compdata[i].cx_real,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
if (fread(&v->v_compdata[i].cx_imag,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
}
|
||||
} else if (raw_padded) {
|
||||
if (flags & VF_REAL) {
|
||||
if (fread(&junk,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
} else {
|
||||
if (fread(&junk,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
if (fread(&junk,
|
||||
sizeof (double), 1, fp) != 1)
|
||||
fprintf(cp_err,
|
||||
"Error: bad rawfile\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s = buf;
|
||||
skip(s);
|
||||
if (*s) {
|
||||
fprintf(cp_err,
|
||||
"Error: strange line in rawfile;\n\t\"%s\"\nload aborted.\n", s);
|
||||
fprintf(cp_err,
|
||||
"Error: strange line in rawfile;\n\t\"%s\"\nload aborted.\n", s);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
|
@ -716,11 +714,11 @@ fixdims(struct dvec *v, char *s)
|
|||
int i, ndimpoints;
|
||||
|
||||
if (atodims(s, v->v_dims, &(v->v_numdims))) { /* Something's wrong. */
|
||||
fprintf(cp_err,
|
||||
"Warning: syntax error in dimensions, ignored.\n");
|
||||
return;
|
||||
fprintf(cp_err,
|
||||
"Warning: syntax error in dimensions, ignored.\n");
|
||||
return;
|
||||
} else if (v->v_numdims > MAXDIMS) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the no. of points is less than the the total data length,
|
||||
|
|
@ -729,13 +727,13 @@ fixdims(struct dvec *v, char *s)
|
|||
* by setting to default dimensions when we return.
|
||||
*/
|
||||
for (i = 0, ndimpoints = 1; i < v->v_numdims; i++) {
|
||||
ndimpoints *= v->v_dims[i];
|
||||
ndimpoints *= v->v_dims[i];
|
||||
}
|
||||
|
||||
if (ndimpoints > v->v_length) {
|
||||
v->v_numdims = 0;
|
||||
v->v_numdims = 0;
|
||||
} else {
|
||||
v->v_length = ndimpoints;
|
||||
v->v_length = ndimpoints;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -752,8 +750,8 @@ spar_write(char *name, struct plot *pl, double Rbaseval)
|
|||
|
||||
/* Why bother printing out an empty plot? */
|
||||
if (!pl->pl_dvecs) {
|
||||
fprintf(cp_err, "Error writing s2p: plot is empty, nothing written.\n");
|
||||
return;
|
||||
fprintf(cp_err, "Error writing s2p: plot is empty, nothing written.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (raw_prec != -1)
|
||||
|
|
@ -766,10 +764,12 @@ spar_write(char *name, struct plot *pl, double Rbaseval)
|
|||
|
||||
/* All vectors have to have same length,
|
||||
only dimension 1 is allowed */
|
||||
if (length == 0) {length = v->v_length;}
|
||||
if (length == 0) {
|
||||
length = v->v_length;
|
||||
}
|
||||
if (length != v->v_length) {
|
||||
fprintf(stderr,"Error writing s2p: lentgth of vector %s differs from length of vector 'frequency'\n",
|
||||
v->v_name);
|
||||
v->v_name);
|
||||
return;
|
||||
}
|
||||
if (v->v_numdims != 1) {
|
||||
|
|
@ -777,22 +777,22 @@ spar_write(char *name, struct plot *pl, double Rbaseval)
|
|||
return;
|
||||
}
|
||||
|
||||
/* Find the length and dimensions of the longest vector
|
||||
* in the plot.
|
||||
* Be paranoid and assume somewhere we may have
|
||||
* forgotten to set the dimensions of 1-D vectors.
|
||||
|
||||
if (v->v_numdims <= 1) {
|
||||
v->v_numdims = 1;
|
||||
v->v_dims[0] = v->v_length;
|
||||
}
|
||||
if (v->v_length > length) {
|
||||
length = v->v_length;
|
||||
numdims = v->v_numdims;
|
||||
for (j = 0; j < numdims; j++) {
|
||||
dims[j] = v->v_dims[j];
|
||||
/* Find the length and dimensions of the longest vector
|
||||
* in the plot.
|
||||
* Be paranoid and assume somewhere we may have
|
||||
* forgotten to set the dimensions of 1-D vectors.
|
||||
|
||||
if (v->v_numdims <= 1) {
|
||||
v->v_numdims = 1;
|
||||
v->v_dims[0] = v->v_length;
|
||||
}
|
||||
}*/
|
||||
if (v->v_length > length) {
|
||||
length = v->v_length;
|
||||
numdims = v->v_numdims;
|
||||
for (j = 0; j < numdims; j++) {
|
||||
dims[j] = v->v_dims[j];
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if ((fp = fopen(name, "w")) == NULL) {
|
||||
|
|
@ -804,10 +804,10 @@ spar_write(char *name, struct plot *pl, double Rbaseval)
|
|||
fprintf(fp, "!Title: %s\n", pl->pl_title);
|
||||
fprintf(fp, "!Generated by ngspice at %s\n", pl->pl_date);
|
||||
fprintf(fp, "# Hz S RI R %g\n", Rbaseval);
|
||||
fprintf(fp, "!%-*.5s %-*.5s %-*.5s %-*.5s %-*.5s %-*.5s %-*.5s %-*.5s %-*.5s\n",
|
||||
prec+8,"freq",
|
||||
prec+8,"ReS11",prec+8,"ImS11",prec+8,"ReS21",prec+8,"ImS21",
|
||||
prec+8,"ReS12",prec+8,"ImS12",prec+8,"ReS22",prec+8,"ImS22");
|
||||
fprintf(fp, "!%-*.5s %-*.5s %-*.5s %-*.5s %-*.5s %-*.5s %-*.5s %-*.5s %-*.5s\n",
|
||||
prec+8,"freq",
|
||||
prec+8,"ReS11",prec+8,"ImS11",prec+8,"ReS21",prec+8,"ImS21",
|
||||
prec+8,"ReS12",prec+8,"ImS12",prec+8,"ReS22",prec+8,"ImS22");
|
||||
|
||||
/* Before we write the stuff out, make sure that the scale is the first
|
||||
* in the list.
|
||||
|
|
@ -820,20 +820,20 @@ spar_write(char *name, struct plot *pl, double Rbaseval)
|
|||
pl->pl_dvecs = v;
|
||||
}
|
||||
|
||||
/* print frequency first as real value, the real and imag part of
|
||||
/* print frequency first as real value, the real and imag part of
|
||||
S11, S21, S12, S22 respectively */
|
||||
for (i = 0; i < length; i++) {
|
||||
for (v = pl->pl_dvecs; v; v = v->v_next) {
|
||||
for (v = pl->pl_dvecs; v; v = v->v_next) {
|
||||
if (i < v->v_length) {
|
||||
if (cieq(v->v_name, "frequency"))
|
||||
fprintf(fp, "% .*e ", prec,
|
||||
realpart(&v->v_compdata[i]));
|
||||
fprintf(fp, "% .*e ", prec,
|
||||
realpart(&v->v_compdata[i]));
|
||||
else
|
||||
fprintf(fp, "% .*e % .*e ", prec,
|
||||
realpart(&v->v_compdata[i]),
|
||||
prec,
|
||||
imagpart(&v->v_compdata[i]));
|
||||
}
|
||||
realpart(&v->v_compdata[i]),
|
||||
prec,
|
||||
imagpart(&v->v_compdata[i]));
|
||||
}
|
||||
}
|
||||
(void) putc('\n', fp);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue