ngspice/src/frontend/typesdef.c

245 lines
5.9 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
**********/
/*
* Stuff to deal with nutmeg "types" for vectors and plots.
*/
#include "ngspice.h"
#include "cpdefs.h"
#include "ftedefs.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 "typesdef.h"
#define NUMTYPES 128+4 /* If this is too little we can use a list. */
2000-04-27 22:03:57 +02:00
#define NUMPLOTTYPES 512 /* Since there may be more than 1 pat/type. */
struct type {
char *t_name;
char *t_abbrev;
};
/* The stuff for plot names. */
struct plotab {
char *p_name;
char *p_pattern;
};
/* note: This should correspond to SV_ defined in FTEconstant.h */
struct type types[NUMTYPES] = {
{ "notype", NULL } ,
{ "time", "s" } ,
2000-04-27 22:03:57 +02:00
{ "frequency", "Hz" } ,
{ "voltage", "V" } ,
{ "current", "A" } ,
{ "onoise-spectrum", "(V or A)^2/Hz" } ,
{ "onoise-integrated", "V or A" } ,
{ "inoise-spectrum", "(V or A)^2/Hz" } ,
{ "inoise-integrated", "V or A" } ,
/* { "output-noise", NULL } , */
/* { "input-noise", NULL } , */
2000-04-27 22:03:57 +02:00
{ "pole", NULL } ,
{ "zero", NULL } ,
{ "s-param", NULL } ,
{ "temp-sweep", "Celsius" } ,/* Added by HT */
{ "res-sweep", "Ohms" } ,/* Added by HT */
{ "impedance", "Ohms" } ,/* Added by A.Roldan */
{ "admittance", "Mhos" } ,/* Added by A.Roldan */
{ "power", "W" } , /* Added by A.Roldan */
{ "phase", "Degree" } , /* Added by A.Roldan */
{ "decibel", "dB" } , /* Added by A.Roldan */
2000-04-27 22:03:57 +02:00
} ;
/* The stuff for plot names. */
struct plotab plotabs[NUMPLOTTYPES] = {
{ "tran", "transient" } ,
{ "op", "op" } ,
{ "tf", "function" },
{ "dc", "d.c." } ,
{ "dc", "dc" } ,
{ "dc", "transfer" } ,
{ "ac", "a.c." } ,
{ "ac", "ac" } ,
{ "pz", "pz" } ,
{ "pz", "p.z." } ,
{ "pz", "pole-zero"} ,
{ "disto", "disto" } ,
{ "dist", "dist" } ,
{ "noise", "noise" } ,
{ "sens", "sens" } ,
{ "sens", "sensitivity" } ,
{ "sens2", "sens2" } ,
{ "sp", "s.p." } ,
{ "sp", "sp" } ,
{ "harm", "harm" },
{ "spect", "spect" },
} ;
int notypes = 15 ;/* change 14 to 15 by H.T*/
int noplotabs = 20;/* change 18 to 20 by H.T*/
2000-04-27 22:03:57 +02:00
/* A command to define types for vectors and plots. This will generally
* be used in the Command: field of the rawfile.
* The syntax is "deftype v typename abbrev", where abbrev will be used to
* parse things like abbrev(name) and to label axes with M<abbrev>, instead
* of numbers. It may be ommitted.
* Also, the command "deftype p plottype pattern ..." will assign plottype as
* the name to any plot with one of the patterns in its Name: field.
*/
void
com_dftype(wordlist *wl)
{
char *name, *abb;
int i;
switch (*wl->wl_word) {
case 'v':
case 'V':
wl = wl->wl_next;
name = copy(wl->wl_word);
wl = wl->wl_next;
abb = copy(wl->wl_word);
for (i = 0; i < notypes; i++)
if (cieq(types[i].t_name, name)) {
types[i].t_abbrev = abb;
return;
}
if (notypes >= NUMTYPES - 1) {
fprintf(cp_err, "Error: too many types defined\n");
return;
}
types[notypes].t_name = name;
types[notypes].t_abbrev = abb;
notypes++;
break;
case 'p':
case 'P':
wl = wl->wl_next;
name = copy(wl->wl_word);
wl = wl->wl_next;
while (wl) {
for (i = 0; i < noplotabs; i++)
if (cieq(plotabs[i].p_pattern, wl->wl_word)) {
plotabs[i].p_name = name;
wl = wl->wl_next;
break;
}
if (i != noplotabs)
continue;
if (noplotabs >= NUMPLOTTYPES - 1) {
fprintf(cp_err, "Error: too many plot abs\n");
return;
}
plotabs[noplotabs].p_name = name;
plotabs[noplotabs].p_pattern = copy(wl->wl_word);
wl = wl->wl_next;
noplotabs++;
}
break;
default:
fprintf(cp_err, "Error: missing 'p' or 'v' argument\n");
break;
}
return;
}
/* Return the abbreviation associated with a number. */
char *
ft_typabbrev(int typenum)
{
if ((typenum < NUMTYPES) && (typenum >= 0))
return (types[typenum].t_abbrev);
else
return (NULL);
}
/* Return the typename associated with a number. */
char *
ft_typenames(int typenum)
{
if ((typenum < NUMTYPES) && (typenum >= 0))
return (types[typenum].t_name);
else
return (NULL);
}
/* Return the type number associated with the name. */
int
ft_typnum(char *name)
{
int i;
if (eq(name, "none"))
name = "notype";
for (i = 0; (i < NUMTYPES) && types[i].t_name; i++)
if (cieq(name, types[i].t_name))
return (i);
return (0);
}
/* For plots... */
char *
ft_plotabbrev(char *string)
{
char buf[128];
int i;
if (!string)
return (NULL);
for (i = 0; string[i]; i++)
buf[i] = isupper(string[i]) ? tolower(string[i]) : string[i];
buf[i] = '\0';
for (i = 0; plotabs[i].p_name; i++)
if (substring(plotabs[i].p_pattern, buf))
return (plotabs[i].p_name);
return (NULL);
}
/* Change the type of a vector. */
void
com_stype(wordlist *wl)
{
char *type = wl->wl_word;
int tt;
struct dvec *v, *vv;
char *s;
for (tt = 0; ; tt++) {
if (!(s = ft_typenames(tt)) || eq(type, s))
break;
}
if (!s) {
fprintf(cp_err, "Error: no such type as '%s'\n", type);
return;
}
for (wl = wl->wl_next; wl; wl = wl->wl_next) {
v = vec_get(wl->wl_word);
if (!v)
fprintf(cp_err, "Error: no such vector %s.\n",
wl->wl_word);
else
for (vv = v; vv; vv = vv->v_link2)
if (vv->v_flags & VF_PERMANENT)
vv->v_type = tt;
}
return;
}