ngspice/src/frontend/newcoms.c

215 lines
4.1 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1992 Regents of the University of California. All rights reserved.
**********/
/*
* Some new post-processor commands having to do with vectors.
*/
#include "ngspice.h"
#include "cpdefs.h"
#include "ftedefs.h"
#include "fteparse.h"
* src/Makefile.am src/main.c src/sconvert.c src/analysis/cktdisto.c src/analysis/cktnoise.c src/analysis/noisean.c: Updates for the new header files. * src/maths/cmaths/cmath1.c src/maths/cmaths/cmath2.c src/maths/cmaths/cmath3.c src/maths/cmaths/cmath4.c: Updates for the new header files. * src/frontend/.cvsignore src/frontend/Makefile.am: Updates for the new files. * src/frontend/agraf.c src/frontend/aspice.c src/frontend/breakp.c src/frontend/breakp2.c src/frontend/circuits.c src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/define.c src/frontend/diff.c src/frontend/dimens.c src/frontend/display.c src/frontend/doplot.c src/frontend/dotcards.c src/frontend/evaluate.c src/frontend/fourier.c src/frontend/graf.c src/frontend/grid.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/interp.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/misccoms.h src/frontend/miscvars.c src/frontend/mw_coms.c src/frontend/newcoms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/plotcurv.c src/frontend/points.c src/frontend/postcoms.c src/frontend/rawfile.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/typesdef.c src/frontend/vectors.c src/frontend/where.c src/frontend/postcoms.c: Updates for the new header files. Some commands have moved into the new files below. * src/frontend/README src/frontend/com_compose.c src/frontend/com_compose.h src/frontend/com_display.c src/frontend/com_display.h src/frontend/com_let.c src/frontend/com_let.h src/frontend/com_setscale.c src/frontend/com_setscale.h src/frontend/commands.c src/frontend/commands.h src/frontend/completion.h src/frontend/streams.h src/frontend/testcommands.c: Separation into different com_* commands. This is a start. The rest of the subdirectory needs doing. * src/include/complex.h src/include/cpdefs.h src/include/cpextern.h src/include/cpstd.h src/include/fteconst.h src/include/ftedata.h src/include/ftedev.h src/include/fteext.h src/include/ftegraph.h src/include/fteparse.h src/include/dvec.h src/include/grid.h src/include/plot.h src/include/pnode.h src/include/sim.h src/include/variable.h src/include/wordlist.h src/include/bool.h: Separation of header files into smaller pieces. This limits recompilation to only the affected source files. The original header files have a warning message embedded to flag obsoleted use. * src/frontend/compose.c src/frontend/compose.h src/frontend/nutctab.c src/frontend/nutctab.h src/frontend/plot5.c src/frontend/plot5.h src/frontend/spcmdtab.c src/frontend/x11.c src/frontend/x11.h src/frontend/xgraph.c src/frontend/xgraph.h: Moved these files into src/frontend/plotting subdirectory. * src/frontend/plotting/.cvsignore src/frontend/plotting/Makefile.am src/frontend/plotting/plot5.c src/frontend/plotting/plot5.h src/frontend/plotting/plotting.c src/frontend/plotting/plotting.h src/frontend/plotting/pvec.c src/frontend/plotting/pvec.h src/frontend/plotting/x11.c src/frontend/plotting/x11.h src/frontend/plotting/xgraph.c src/frontend/plotting/xgraph.h: The new libplotting library with automake and CVS infrastructure.
2000-05-06 16:12:51 +02:00
#include "dvec.h"
2000-04-27 22:03:57 +02:00
#include "newcoms.h"
#include "quote.h"
2000-04-27 22:03:57 +02:00
/*
* reshape v(1) vxx#branch [10]
* reshape v(1) vxx#branch [10,4]
* reshape v(1) [,4]
*/
void
com_reshape(wordlist *wl)
{
wordlist *w, *w2, *wlast, *wsave;
char *p;
struct dvec *dv, *d;
int numdims;
int *dims;
int local_dims[MAXDIMS];
int state;
int empty;
int err;
int missing, nprod, prod;
char *vname;
int i;
do {
if (!wl)
return;
/* find the first '[' */
p = NULL;
for (w = wl; w; w = w->wl_next) {
if ((p = strchr(w->wl_word, '[')) != NULL)
2000-04-27 22:03:57 +02:00
break;
}
if (p && *p) {
if (p != w->wl_word)
w = w->wl_next;
wlast = w;
*p++ = 0;
} else
wlast = NULL;
/* get the dimensions */
dims = local_dims;
numdims = 0;
state = 0;
empty = -1;
err = 0;
wsave = NULL;
do {
if (!p || !*p) {
if (!wlast)
break;
p = wlast->wl_word;
if (state == 2)
wsave = wlast;
else
wsave = NULL;
wlast = wlast->wl_next;
}
while (*p && isspace(*p))
p++;
switch (state) {
case 0: /* p just at or before a number */
if (numdims >= MAXDIMS) {
if (numdims == MAXDIMS)
printf("Maximum of %d dimensions possible\n", MAXDIMS);
numdims += 1;
} else if (!isdigit(*p)) {
if (empty > -1) {
printf("dimensions underspecified at dimension %d\n",
numdims++);
err = 1;
} else {
empty = numdims;
dims[numdims++] = 1;
}
} else {
dims[numdims++] = atoi(p);
while (isdigit(*p))
p++;
}
state = 1;
break;
case 1: /* p after a number, looking for ',' or ']' */
if (*p == ']') {
p++;
state = 2;
} else if (*p == ',') {
p++;
state = 0;
} else if (isdigit(*p)) {
state = 0;
break;
} else if (!isspace(*p))
/* error */
state = 4;
break;
case 2: /* p after a ']', either at the end or looking for '[' */
if (*p == '[') {
p++;
state = 0;
} else {
state = 3;
}
}
while (*p && isspace(*p))
p++;
} while (state < 3);
if (state == 2) {
wlast = wsave;
} else if ((state == 4 || state < 2) && ((state != 0 || p) && *p)) {
printf("syntax error specifying dimensions\n");
return;
}
if (numdims > MAXDIMS)
continue;
if (err)
continue;
/* Copy dimensions from the first item if none are explicitly given */
if (!numdims) {
/* Copy from the first */
vname = cp_unquote(wl->wl_word);
dv = vec_get(vname);
if (!dv) {
printf("'%s' dimensions vector not found\n", vname);
return;
}
numdims = dv->v_numdims;
dims = dv->v_dims;
wl = wl->wl_next;
empty = -1; /* just in case */
}
prod = 1;
for (i = 0; i < numdims; i++)
prod *= dims[i];
/* resize each vector */
for (w2 = wl; w2 && w2 != w; w2 = w2->wl_next) {
vname = cp_unquote(w2->wl_word);
dv = vec_get(vname);
if (!dv) {
printf("'%s' vector not found\n", vname);
continue;
}
/* The name may expand to several vectors */
for (d = dv; d; d = d->v_link2) {
nprod = 1;
for (i = 0; i < d->v_numdims; i++)
nprod *= d->v_dims[i];
if (nprod != d->v_length) {
printf("dimensions of \"%s\" were inconsistent\n",
d->v_name);
nprod = d->v_length;
}
missing = nprod / prod;
if (missing * prod != nprod) {
printf("dimensions don't fit \"%s\" (total size = %d)\n",
d->v_name, nprod);
continue;
}
if (missing > 1 && empty < 0) {
/* last dimension unspecified */
d->v_numdims = numdims + 1;
d->v_dims[numdims] = missing;
} else
d->v_numdims = numdims;
/* fill in dimensions */
for (i = 0; i < numdims; i++) {
if (i == empty)
d->v_dims[i] = missing;
else
d->v_dims[i] = dims[i];
}
}
if (vname)
tfree(vname);
}
} while ((wl = wlast) != NULL);
2000-04-27 22:03:57 +02:00
}