New capability of print command for sin source print @vin_sin[sin] and

alter command for sin source alter @vin_sin[sin] = ( 1 1 3000Hx ). Patch
from Espice - A. Roldan
This commit is contained in:
pnenzi 2009-01-15 22:16:32 +00:00
parent f543aa8c06
commit 8c3ca11c62
6 changed files with 231 additions and 23 deletions

View File

@ -1,3 +1,18 @@
2009-01-15 Paolo Nenzi
* src/spicelib/devices/vsrc/vsrc.c,
* src/spicelib/devices/isrc/isrc.c,
* src/frontend/spiceif.c,
* src/frontend/device.c,
* src/frontend/postcoms.c,
* src/frontend/vectors.c:
17: New capability of print command. It is now possible to print and
alter vectors of reals like print @vin_sin[sin] to print the vector
of parameters defining the sinusoidal source (it works with both the
sources type). It is possible to alter the parameters with the command
alter @vin_sin[sin] = ( 1 1 3000Hz ). A. Roldan -Espice
Note: alter syntax does not work in full yet, it still generate an
error but modifies the parameters. P. Nenzi
2009-01-15 Paolo Nenzi
* src/frontend/vectors.c:
57: Fixed I(vx), before the if I(*) (upper case) was not recognized as the

View File

@ -931,8 +931,53 @@ com_alter_common(wordlist *wl, int do_model)
words = eqword->wl_next;
names = ft_getpnames(words, FALSE);
if (!names) {
fprintf(cp_err, "Error: cannot parse new parameter value.\n");
return;
/* Put this to try to resolve the case of
* alter vin_sin@[sin] = (10 12 3000)
*/
char *xsbuf;
int type = IF_REALVEC,i=0;
double *list;
double tmp;
int error;
xsbuf = wl_flatten(words);
/* fprintf(cp_err, "Chain converted %s \n",xsbuf); */
dv=(struct dvec *)MALLOC(sizeof(struct dvec));
dv->v_name = (char *)MALLOC(sizeof("real vector"));
dv->v_name = "real vector";
type &= IF_VARTYPES;
if (type == IF_REALVEC)
{
list = (double *)MALLOC(sizeof(double));
tmp = INPevaluate(&xsbuf,&error,1);
while (error == 0)
{
/*printf(" returning vector value %g\n",tmp); */
i++;
list=(double *)REALLOC((char *)list,i*sizeof(double));
*(list+i-1) = tmp;
tmp = INPevaluate(&xsbuf,&error,1);
}
dv->v_realdata=list;
}
dv->v_length=i;
if (!dv)
return;
if (dv->v_length < 1)
{
fprintf(cp_err, "Error: cannot evaluate new parameter value.\n");
return;
}
/* Here I was, to change the inclusion in the circuit.
* will have to revise that dv is right for its insertion.
*/
if_setparam(ft_curckt->ci_ckt, &dev, param, dv, do_model);
return;
}
dv = ft_evaluate(names);
if (!dv)

View File

@ -120,8 +120,19 @@ com_print(wordlist *wl)
for (v = vecs; v; v = v->v_link2)
if (v->v_length > 1) {
col = TRUE;
/* Improvement made to print cases @[sin] = (0 12 13 100K) */
if ( (v->v_length != v->v_plot->pl_scale->v_length) && ( (*(v->v_name))=='@') )
{
col = FALSE;
}
break;
}
/* With this I have found that the vector has less elements than the SCALE vector
* in the linked PLOT. But now I must make sure in case of a print @vin[sin] or
* @vin[pulse]
* for it appear that the v->v_name begins with '@'
* And then be in this case.
*/
}
out_init();
@ -141,8 +152,18 @@ com_print(wordlist *wl)
s--;
}
ll = 10;
if (v->v_length == 1) {
if (isreal(v)) {
/* v->v_rlength = 1 when it comes to make a print @ M1 and does not want to come out on screen
* Multiplier factor [m]=1
* @M1 = 0,00e+00
* In any other case rlength not used for anything and only applies in the copy of the vectors.
*/
if (v->v_rlength == 0)
{
if (v->v_length == 1)
{
if (isreal(v))
{
printnum(numbuf, *v->v_realdata);
out_printf("%s = %s\n", buf, numbuf);
} else {
@ -194,7 +215,8 @@ com_print(wordlist *wl)
out_send("\t");
}
out_send(")\n");
}
} //end if (v->v_length == 1)
} //end if (v->v_rlength == 1)
}
} else { /* Print in columns. */
if (cp_getvar("width", VT_NUM, (char *) &i))

View File

@ -387,8 +387,14 @@ vec_get(char *word)
if (ft_curckt) {
vv = (*if_getparam)(ft_curckt->ci_ckt, &name, param, 0, 0);
/*
* This is what is done in case of "alter r1 resistance = 1234"
* r1 resistance, 0
* if_setparam(ft_curckt->ci_ckt, &dev, param, dv, do_model);
*/
/* vv = (*if_getparam)(ft_curckt->ci_ckt, &name, param, 0, 0); */
vv = (*if_getparam)(ft_curckt->ci_ckt, &name, param, 0, 0);
if (!vv) {
tfree(whole);
tfree(wd);
@ -408,7 +414,124 @@ vec_get(char *word)
d->v_flags |= VF_REAL; /* No complex values yet... */
d->v_realdata = (double *) tmalloc(sizeof (double));
d->v_length = 1;
*d->v_realdata = vv->va_real;
/* In case the represented variable is a REAL vector this takes
* the actual value of the first element of the linked list which
* does not make sense.
* This is an error.
*/
/* This will copy the contents of the structure vv in another structure
* dvec (FTEDATA.H) that do not have INTEGER so that those parameters
* defined as IF_INTEGER are not given their value when using
* print @pot[pos_node]
* To fix this, it is necessary to define:
* OPU( "pos_node", POT_QUEST_POS_NODE, IF_REAL,"Positive node of potenciometer"),
* int POTnegNode; // number of negative node of potenciometer (Nodo_3)
* case POT_QUEST_POS_NODE:
* value->rValue = (double)fast->POTposNode;
* return(OK);
* Works but with the format 1.00000E0
*/
/* We must make a change in format between the data that carries a variable to
* put in a dvec.
*/
/*
* #define va_bool va_V.vV_bool
* #define va_num va_V.vV_num
*#define va_real va_V.vV_real
*#define va_string va_V.vV_string
*#define va_vlist va_V.vV_list
*enum vt_types {
* VT_BOOL,
* VT_NUM,
* VT_REAL,
* VT_STRING,
* VT_LIST
° };
*/
/* The variable is a vector */
if (vv->va_type == VT_LIST)
{
/* Compute the length of the vector,
* used with the parameters of isrc and vsrc
*/
struct variable *nv;
double *list;
list = (double *)MALLOC(sizeof(double));
nv = alloc(struct variable);
nv = vv->va_vlist;
for(i=1; ;i++)
{
list=(double *)REALLOC((char *)list,i*sizeof(double));
*(list+i-1) = nv->va_real;
nv = nv->va_next;
if (nv==NULL) break;
}
d->v_realdata=list;
d->v_length = i;
/* To be able to identify the vector to represent
* belongs to a special "conunto" and should be printed in a
* special way.
*/
d->v_dims[1]=1;
}
else if (vv->va_type == VT_NUM) /* Variable is an integer */
{
*d->v_realdata = (double) vv->va_num;
}
else if (vv->va_type == VT_REAL) /* Variable is a real */
{
if (!(vv->va_next))
{
/* Only a real data
* usually normal
*/
*d->v_realdata = vv->va_real;
}
else
{
/* Real data set
* When you print a model @ [all]
* Just print numerical values, not the string
*/
struct variable *nv;
/* We go to print the list of values
* nv->va_name = Parameter description
* nv->va_string = Parameter
* nv->va_real= Value
*/
nv=vv;
for(i=1; ;i++)
{
switch(nv->va_type)
{
case VT_REAL:
fprintf(stdout,"%s=%g\n",nv->va_name,nv->va_real);
break;
case VT_STRING:
fprintf(stdout,"%s=%s\n",nv->va_name,nv->va_string);
break;
case VT_NUM:
fprintf(stdout,"%s=%d\n",nv->va_name,nv->va_num);
break;
}
nv = nv->va_next;
if (nv==NULL) break;
}
/* To distinguish those does not take anything for print screen to
* make a print or M1 @ @ M1 [all] leaving only the correct data
* and not the last
*/
d->v_rlength=1;
}
}
tfree(vv->va_name);
tfree(vv); /* va: tfree vv->va_name and vv (avoid memory leakages) */

View File

@ -13,13 +13,14 @@ IFparm ISRCpTable[] = { /* parameters */
IOPP( "dc", ISRC_DC, IF_REAL ,"DC value of source"),
IOPPA( "acmag", ISRC_AC_MAG, IF_REAL ,"AC magnitude"),
IOPAAU( "acphase", ISRC_AC_PHASE, IF_REAL ,"AC phase"),
IP ( "pulse", ISRC_PULSE, IF_REALVEC,"Pulse description"),
IP ( "sine", ISRC_SINE, IF_REALVEC,"Sinusoidal source description"),
IP ( "sin", ISRC_SINE, IF_REALVEC,"Sinusoidal source description"),
IP ( "exp", ISRC_EXP, IF_REALVEC,"Exponential source description"),
IP ( "pwl", ISRC_PWL, IF_REALVEC,"Piecewise linear description"),
IP ( "sffm", ISRC_SFFM, IF_REALVEC,"Single freq. FM description"),
IP ( "am", ISRC_AM, IF_REALVEC,"Amplitude modulation description"),
/* Modified to allow print @Iin[sin] A.Roldan */
IOP ( "pulse", ISRC_PULSE, IF_REALVEC,"Pulse description"),
IOP ( "sine", ISRC_SINE, IF_REALVEC,"Sinusoidal source description"),
IOP ( "sin", ISRC_SINE, IF_REALVEC,"Sinusoidal source description"),
IOP ( "exp", ISRC_EXP, IF_REALVEC,"Exponential source description"),
IOP ( "pwl", ISRC_PWL, IF_REALVEC,"Piecewise linear description"),
IOP ( "sffm", ISRC_SFFM, IF_REALVEC,"Single freq. FM description"),
IOP ( "am", ISRC_AM, IF_REALVEC,"Amplitude modulation description"),
OPU ( "neg_node",ISRC_NEG_NODE, IF_INTEGER,"Negative node of source"),
OPU ( "pos_node",ISRC_POS_NODE, IF_INTEGER,"Positive node of source"),
OPU ( "acreal", ISRC_AC_REAL, IF_REAL ,"AC real part"),

View File

@ -13,14 +13,16 @@ IFparm VSRCpTable[] = { /* parameters */
IOPP("dc", VSRC_DC, IF_REAL ,"D.C. source value"),
IOPPA("acmag", VSRC_AC_MAG, IF_REAL ,"A.C. Magnitude"),
IOPAAU("acphase", VSRC_AC_PHASE, IF_REAL ,"A.C. Phase"),
IP ("pulse", VSRC_PULSE, IF_REALVEC,"Pulse description"),
IP ("sine", VSRC_SINE, IF_REALVEC,"Sinusoidal source description"),
IP ("sin", VSRC_SINE, IF_REALVEC,"Sinusoidal source description"),
IP ("exp", VSRC_EXP, IF_REALVEC,"Exponential source description"),
IP ("pwl", VSRC_PWL, IF_REALVEC,"Piecewise linear description"),
IP ("sffm", VSRC_SFFM, IF_REALVEC,"Single freq. FM descripton"),
IP ("am", VSRC_AM, IF_REALVEC,"Amplitude modulation descripton"),
OPU ("pos_node",VSRC_POS_NODE, IF_INTEGER,"Positive node of source"),
/* Modified to allow print @vin[sin] A.Roldan */
IOP ("pulse", VSRC_PULSE, IF_REALVEC,"Pulse description"),
IOP ("sine", VSRC_SINE, IF_REALVEC,"Sinusoidal source description"),
IOP ("sin", VSRC_SINE, IF_REALVEC,"Sinusoidal source description"),
IOP ("exp", VSRC_EXP, IF_REALVEC,"Exponential source description"),
IOP ("pwl", VSRC_PWL, IF_REALVEC,"Piecewise linear description"),
IOP ("sffm", VSRC_SFFM, IF_REALVEC,"Single freq. FM descripton"),
IOP ("am", VSRC_AM, IF_REALVEC,"Amplitude modulation descripton"),
OPU ("pos_node",VSRC_POS_NODE, IF_INTEGER,"Positive node of source"),
OPU ("neg_node",VSRC_NEG_NODE, IF_INTEGER,"Negative node of source"),
OPU ("function",VSRC_FCN_TYPE, IF_INTEGER,"Function of the source"),
OPU ("order", VSRC_FCN_ORDER, IF_INTEGER,"Order of the source function"),