Jspice3
outitf.c File Reference
#include "spice.h"
#include "ftedefs.h"
#include "inpdefs.h"
#include "ftegraph.h"
#include "spfteext.h"
#include "plotext.h"
#include "iferrmsg.h"
#include "outdata.h"
Include dependency graph for outitf.c:

Go to the source code of this file.

Data Structures

struct  dataDesc
 
struct  runDesc
 
struct  mesg
 

Macros

#define DOUBLE_PRECISION   15
 

Typedefs

typedef struct dataDesc dataDesc
 
typedef struct runDesc runDesc
 

Functions

static void out_destroy ()
 
static int addDataDesc ()
 
static int addSpecialDesc ()
 
static void addPointToFile ()
 
static void addPointToPlot ()
 
static void fileInit ()
 
static void fileStartPoint ()
 
static void fileAddRealValue ()
 
static void fileAddComplexValue ()
 
static void fileEndPoint ()
 
static void fileEnd ()
 
static void plotInit ()
 
static void plotAddRealValue ()
 
static void plotAddComplexValue ()
 
static void plotEnd ()
 
static bool parseSpecial ()
 
static bool name_eq ()
 
static bool getSpecial ()
 
static void freeRun ()
 
char * OUTcntrlInit ()
 
int OUTbeginPlot (GENERIC *outdp)
 
static int addDataDesc (runDesc *run, char *name, int type, int ind)
 
static int addSpecialDesc (runDesc *run, char *name, char *devname, char *param, int depind)
 
int OUTdata (GENERIC *plotPtr, IFvalue *refValue, IFvalue *valuePtr)
 
int OUTsetDims (GENERIC *plotPtr, int *dims, int numDims)
 
static void addPointToFile (runDesc *run, IFvalue *refValue, IFvalue *valuePtr)
 
static void addPointToPlot (runDesc *run, IFvalue *refValue, IFvalue *valuePtr, bool inc)
 
int OUTendPlot (GENERIC *plotPtr)
 
static void fileInit (runDesc *run)
 
static void fileStartPoint (FILE *fp, bool bin, int num)
 
static void fileAddRealValue (FILE *fp, bool bin, double value)
 
static void fileAddComplexValue (FILE *fp, bool bin, IFcomplex value)
 
static void fileEndPoint (FILE *fp, bool bin)
 
static void fileEnd (runDesc *run)
 
static void plotInit (runDesc *run, double tstart, double tstop, double tstep, struct plot *plot)
 
static void plotAddRealValue (dataDesc *desc, double value, bool inc)
 
static void plotAddComplexValue (dataDesc *desc, IFcomplex value, bool inc)
 
static void plotEnd (runDesc *run)
 
static bool parseSpecial (char *name, char *dev, char *param, char *ind)
 
static bool name_eq (char *n1, char *n2)
 
static bool getSpecial (dataDesc *desc, runDesc *run, IFvalue *val)
 
static void freeRun (runDesc *run)
 
int OUTstopnow ()
 
int OUTerror (int flags, char *format, IFuid *names)
 

Variables

bool OUTendit
 
static struct sOUTcontrol OUTcntrl
 
static bool shouldstop = false
 
static bool printinfo = false
 
static struct mesg msgs []
 

Macro Definition Documentation

#define DOUBLE_PRECISION   15

Definition at line 24 of file outitf.c.

Typedef Documentation

typedef struct dataDesc dataDesc
typedef struct runDesc runDesc

Function Documentation

static int addDataDesc ( )
static
static int addDataDesc ( runDesc run,
char *  name,
int  type,
int  ind 
)
static

Definition at line 321 of file outitf.c.

327 {
328  dataDesc *data;
329 
330  if (!run->numData)
331  run->data = (dataDesc *) tmalloc(sizeof (dataDesc));
332  else
333  run->data = (dataDesc *) trealloc((char *) run->data,
334  sizeof (dataDesc) * (run->numData + 1));
335  data = &run->data[run->numData];
336  /* so freeRun will get nice NULL pointers for the fields we don't set */
337  bzero(data, sizeof(dataDesc));
338 
339  data->name = copy(name);
340  data->type = type;
341  data->regular = true;
342  data->outIndex = ind;
343 
344  if (ind == -1) {
345  /* It's the reference vector. */
346  run->refIndex = run->numData;
347  }
348 
349  run->numData++;
350 
351  return (OK);
352 }
bool regular
Definition: outitf.c:29
int type
Definition: outitf.c:28
char * name
Definition: outitf.c:27
int outIndex
Definition: outitf.c:30
dataDesc * data
Definition: outitf.c:47
int bzero(char *ptr, int num)
Definition: string.c:357
int numData
Definition: outitf.c:45
char * copy()
#define OK
Definition: iferrmsg.h:17
char * tmalloc()
Definition: types.c:18
int refIndex
Definition: outitf.c:46
char * trealloc()
struct dataDesc dataDesc
static void addPointToFile ( )
static
static void addPointToFile ( runDesc run,
IFvalue refValue,
IFvalue valuePtr 
)
static

Definition at line 471 of file outitf.c.

476 {
477  int i;
478  IFvalue val;
479 
480  fileStartPoint(run->fp, run->binary, run->pointCount);
481 
482  if (run->refIndex != -1) {
483  if (run->isComplex)
484  fileAddComplexValue(run->fp, run->binary, refValue->cValue);
485  else
486  fileAddRealValue(run->fp, run->binary, refValue->rValue);
487  }
488 
489  for (i = 0; i < run->numData; i++) {
490  /* we've already printed reference vec first */
491  if (run->data[i].outIndex == -1) continue;
492 
493  if (run->data[i].regular) {
494  if(run->data[i].type == IF_REAL)
495  fileAddRealValue(run->fp, run->binary,
496  valuePtr->v.vec.rVec
497  [run->data[i].outIndex]);
498  else if (run->data[i].type == IF_COMPLEX)
499  fileAddComplexValue(run->fp, run->binary,
500  valuePtr->v.vec.cVec
501  [run->data[i].outIndex]);
502  else
503  fprintf(stderr, "OUTdata: unsupported data type\n");
504  }
505  else {
506  /* should pre-check instance */
507  if (!getSpecial(&run->data[i], run, &val))
508  continue;
509  if (run->data[i].type == IF_REAL)
510  fileAddRealValue(run->fp, run->binary,
511  val.rValue);
512  else if (run->data[i].type == IF_COMPLEX)
513  fileAddComplexValue(run->fp, run->binary,
514  val.cValue);
515  else
516  fprintf(stderr, "OUTdata: unsupported data type\n");
517  }
518  }
519  fileEndPoint(run->fp, run->binary);
520 }
FILE * fp
Definition: outitf.c:51
int isComplex
Definition: outitf.c:55
#define IF_COMPLEX
Definition: ifsim.h:109
bool regular
Definition: outitf.c:29
static void fileAddComplexValue()
static void fileStartPoint()
union uIFvalue::@13::@14 vec
int type
Definition: outitf.c:28
int outIndex
Definition: outitf.c:30
dataDesc * data
Definition: outitf.c:47
static void fileAddRealValue()
double rValue
Definition: ifsim.h:233
int numData
Definition: outitf.c:45
IFcomplex cValue
Definition: ifsim.h:234
int pointCount
Definition: outitf.c:53
#define IF_REAL
Definition: ifsim.h:108
bool binary
Definition: outitf.c:49
static void fileEndPoint()
int refIndex
Definition: outitf.c:46
struct uIFvalue::@13 v
static bool getSpecial()
static void addPointToPlot ( )
static
static void addPointToPlot ( runDesc run,
IFvalue refValue,
IFvalue valuePtr,
bool  inc 
)
static

Definition at line 524 of file outitf.c.

530 {
531  int i;
532  IFvalue val;
533 
534  for (i = 0; i < run->numData; i++) {
535  if (run->data[i].outIndex == -1) {
536  if (run->data[i].type == IF_REAL)
537  plotAddRealValue(&run->data[i],
538  refValue->rValue,inc);
539  else if (run->data[i].type == IF_COMPLEX)
540  plotAddComplexValue(&run->data[i],
541  refValue->cValue,inc);
542  }
543  else if (run->data[i].regular) {
544  if (run->data[i].type == IF_REAL)
545  plotAddRealValue(&run->data[i],
546  valuePtr->v.vec.rVec
547  [run->data[i].outIndex],inc);
548  else if (run->data[i].type == IF_COMPLEX)
549  plotAddComplexValue(&run->data[i],
550  valuePtr->v.vec.cVec
551  [run->data[i].outIndex],inc);
552  }
553  else {
554  /* should pre-check instance */
555  if (!getSpecial(&run->data[i], run, &val))
556  continue;
557  if (run->data[i].type == IF_REAL)
558  plotAddRealValue(&run->data[i],
559  val.rValue,inc);
560  else if (run->data[i].type == IF_COMPLEX)
561  plotAddComplexValue(&run->data[i],
562  val.cValue,inc);
563  else
564  fprintf(stderr, "OUTdata: unsupported data type\n");
565  }
566  }
567 }
#define IF_COMPLEX
Definition: ifsim.h:109
bool regular
Definition: outitf.c:29
union uIFvalue::@13::@14 vec
int type
Definition: outitf.c:28
int outIndex
Definition: outitf.c:30
dataDesc * data
Definition: outitf.c:47
double rValue
Definition: ifsim.h:233
int numData
Definition: outitf.c:45
IFcomplex cValue
Definition: ifsim.h:234
#define IF_REAL
Definition: ifsim.h:108
static void plotAddComplexValue()
struct uIFvalue::@13 v
static void plotAddRealValue()
static bool getSpecial()
static int addSpecialDesc ( )
static
static int addSpecialDesc ( runDesc run,
char *  name,
char *  devname,
char *  param,
int  depind 
)
static

Definition at line 356 of file outitf.c.

363 {
364  dataDesc *data;
365  char *unique; /* unique char * from back-end */
366 
367  if (!run->numData)
368  run->data = (dataDesc *) tmalloc(sizeof (dataDesc));
369  else
370  run->data = (dataDesc *) trealloc((char *) run->data,
371  sizeof (dataDesc) * (run->numData + 1));
372  data = &run->data[run->numData];
373  /* so freeRun will get nice NULL pointers for the fields we don't set */
374  bzero(data, sizeof(dataDesc));
375 
376  data->name = copy(name);
377 
378  unique = devname;
379  INPinsert(&unique, (INPtables *) ft_curckt->ci_symtab);
380  data->specName = unique;
381 
382  data->specParamName = copy(param);
383 
384  data->specIndex = depind;
385  data->specType = -1;
386  data->specFast = NULL;
387  data->regular = false;
388 
389  run->numData++;
390 
391  return (OK);
392 }
bool regular
Definition: outitf.c:29
char * name
Definition: outitf.c:27
dataDesc * data
Definition: outitf.c:47
int specType
Definition: outitf.c:34
char * specParamName
Definition: outitf.c:32
int bzero(char *ptr, int num)
Definition: string.c:357
int numData
Definition: outitf.c:45
char * copy()
int INPinsert()
#define OK
Definition: iferrmsg.h:17
char * tmalloc()
#define NULL
Definition: spdefs.h:121
struct circ * ft_curckt
Definition: main.c:184
GENERIC * specFast
Definition: outitf.c:35
int specIndex
Definition: outitf.c:33
char * specName
Definition: outitf.c:31
char * ci_symtab
Definition: ftedefs.h:28
char * trealloc()
struct dataDesc dataDesc
static void fileAddComplexValue ( )
static
static void fileAddComplexValue ( FILE *  fp,
bool  bin,
IFcomplex  value 
)
static

Definition at line 688 of file outitf.c.

693 {
694 
695  if (bin) {
696  fwrite((char *) &value.real, sizeof (double), 1, fp);
697  fwrite((char *) &value.imag, sizeof (double), 1, fp);
698  }
699  else {
700  fprintf(fp, "\t%.*e,%.*e\n", DOUBLE_PRECISION, value.real,
701  DOUBLE_PRECISION, value.imag);
702  }
703 
704 }
#define DOUBLE_PRECISION
Definition: outitf.c:24
double imag
Definition: ifsim.h:227
double real
Definition: ifsim.h:226
static void fileAddRealValue ( )
static
static void fileAddRealValue ( FILE *  fp,
bool  bin,
double  value 
)
static

Definition at line 672 of file outitf.c.

677 {
678  if (bin)
679  fwrite((char *) &value, sizeof (double), 1, fp);
680  else
681  fprintf(fp, "\t%.*e\n", DOUBLE_PRECISION, value);
682 
683  return;
684 }
#define DOUBLE_PRECISION
Definition: outitf.c:24
static void fileEnd ( )
static
static void fileEnd ( runDesc run)
static

Definition at line 721 of file outitf.c.

724 {
725  long place;
726 
727  if (run->fp == stdout)
728  return;
729  fflush(run->fp); /* For LATTICE... */
730  place = ftell(run->fp);
731  fseek(run->fp, run->pointPos, 0);
732  fprintf(run->fp, "%d", run->pointCount);
733  fseek(run->fp, place, 0);
734  fflush(run->fp);
735 
736  return;
737 }
FILE * fp
Definition: outitf.c:51
long pointPos
Definition: outitf.c:52
int pointCount
Definition: outitf.c:53
static void fileEndPoint ( )
static
static void fileEndPoint ( FILE *  fp,
bool  bin 
)
static

Definition at line 709 of file outitf.c.

713 {
714  return;
715 }
static void fileInit ( )
static
static void fileInit ( runDesc run)
static

Definition at line 603 of file outitf.c.

606 {
607  int i;
608  char *name, buf[BSIZE_SP];
609  int type;
610 
611  /* This is a hack. */
612  run->isComplex = false;
613  for (i = 0; i < run->numData; i++)
614  if (run->data[i].type == IF_COMPLEX)
615  run->isComplex = true;
616 
617  fprintf(run->fp, "Title: %s\n", run->name);
618  fprintf(run->fp, "Date: %s\n", datestring());
619  fprintf(run->fp, "Plotname: %s\n", run->type);
620  fprintf(run->fp, "Flags: %s\n", run->isComplex ? "complex" : "real");
621  fprintf(run->fp, "No. Variables: %d\n", run->numData);
622  fprintf(run->fp, "No. Points: ");
623 
624  fflush(run->fp); /* Gotta do this for LATTICE. */
625  run->pointPos = ftell(run->fp);
626  fprintf(run->fp, "0 \n"); /* Save 8 spaces here. */
627 
628  fprintf(run->fp, "Command: version %s\n", ft_sim->version);
629  fprintf(run->fp, "Variables:\n");
630 
631  for (i = 0; i < run->numData; i++) {
632  if (isdigit(*run->data[i].name)) {
633  (void) sprintf(buf, "v(%s)", run->data[i].name);
634  name = buf;
635  }
636  else {
637  name = run->data[i].name;
638  }
639  if (substring("#branch", name))
640  type = SV_CURRENT;
641  else if (cieq(name, "time"))
642  type = SV_TIME;
643  else if (cieq(name, "frequency"))
644  type = SV_FREQUENCY;
645  else
646  type = SV_VOLTAGE;
647  fprintf(run->fp, "\t%d\t%s\t%s\n", i, name,
648  ft_typenames(type));
649  }
650 
651  fprintf(run->fp, "%s:\n", run->binary ? "Binary" : "Values");
652 
653  return;
654 }
FILE * fp
Definition: outitf.c:51
int isComplex
Definition: outitf.c:55
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
#define IF_COMPLEX
Definition: ifsim.h:109
IFsimulator * ft_sim
Definition: main.c:111
int cieq()
int type
Definition: outitf.c:28
char * name
Definition: outitf.c:27
char * datestring()
Definition: time.c:37
dataDesc * data
Definition: outitf.c:47
#define SV_VOLTAGE
Definition: fteconst.h:14
int numData
Definition: outitf.c:45
long pointPos
Definition: outitf.c:52
int substring()
Definition: types.c:18
char * type
Definition: outitf.c:44
char * ft_typenames()
#define SV_CURRENT
Definition: fteconst.h:15
bool binary
Definition: outitf.c:49
char * name
Definition: outitf.c:43
char * version
Definition: ifsim.h:359
#define SV_FREQUENCY
Definition: fteconst.h:13
#define SV_TIME
Definition: fteconst.h:12
static void fileStartPoint ( )
static
static void fileStartPoint ( FILE *  fp,
bool  bin,
int  num 
)
static

Definition at line 658 of file outitf.c.

663 {
664  if (!bin)
665  fprintf(fp, "%d", num - 1);
666 
667  return;
668 }
static void freeRun ( )
static
static void freeRun ( runDesc run)
static

Definition at line 1012 of file outitf.c.

1015 {
1016 
1017  int i;
1018 
1019  for (i = 0; i < run->numData; i++) {
1020  txfree(run->data[i].name);
1021  txfree(run->data[i].specParamName);
1022  }
1023  txfree((char*)run->data);
1024  txfree(run->type);
1025  txfree(run->name);
1026  txfree((char*)run);
1027 
1028 }
char * name
Definition: outitf.c:27
dataDesc * data
Definition: outitf.c:47
char * specParamName
Definition: outitf.c:32
int numData
Definition: outitf.c:45
void txfree()
char * type
Definition: outitf.c:44
char * name
Definition: outitf.c:43
static bool getSpecial ( )
static
static bool getSpecial ( dataDesc desc,
runDesc run,
IFvalue val 
)
static

Definition at line 975 of file outitf.c.

980 {
981  IFvalue selector;
982  struct variable *vv;
983 
984  selector.iValue = desc->specIndex;
985  if (INPaName(desc->specParamName, val, run->circuit, &desc->specType,
986  desc->specName, &desc->specFast, ft_sim, &desc->type,
987  &selector) == OK) {
988  desc->type &= (IF_REAL | IF_COMPLEX); /* mask out other bits */
989  return (true);
990  }
991  if (vv = if_getstat(run->circuit, &desc->name[1],
992  (wordlist **)NULL)) {
993  /* skip @ sign */
994  desc->type = IF_REAL;
995  if (vv->va_type == VT_REAL)
996  val->rValue = vv->va_real;
997  else if (vv->va_type == VT_NUM)
998  val->rValue = vv->va_num;
999  else if (vv->va_type == VT_BOOL)
1000  val->rValue = (vv->va_bool ? 1.0 : 0.0);
1001  else {
1002  return (false); /* not a real */
1003  }
1004  tfree(vv);
1005  return (true);
1006  }
1007  return (false);
1008 }
#define IF_COMPLEX
Definition: ifsim.h:109
IFsimulator * ft_sim
Definition: main.c:111
GENERIC * circuit
Definition: outitf.c:42
int type
Definition: outitf.c:28
char * name
Definition: outitf.c:27
int specType
Definition: outitf.c:34
char * specParamName
Definition: outitf.c:32
int iValue
Definition: ifsim.h:232
double rValue
Definition: ifsim.h:233
char va_type
Definition: cpstd.h:42
#define OK
Definition: iferrmsg.h:17
#define tfree(x)
Definition: cdmacs.h:22
#define NULL
Definition: spdefs.h:121
struct variable * if_getstat(char *n, char *c, wordlist **w)
Definition: main.c:248
GENERIC * specFast
Definition: outitf.c:35
#define VT_NUM
Definition: cpstd.h:61
int specIndex
Definition: outitf.c:33
#define VT_BOOL
Definition: cpstd.h:60
Definition: cpstd.h:21
#define IF_REAL
Definition: ifsim.h:108
char * specName
Definition: outitf.c:31
#define VT_REAL
Definition: cpstd.h:62
int INPaName()
Definition: cpstd.h:41
static bool name_eq ( )
static
static bool name_eq ( char *  n1,
char *  n2 
)
static

Definition at line 949 of file outitf.c.

952 {
953  char *s;
954 
955  if (!n1 || !n2)
956  return (false);
957  s = strchr(n1,'(');
958  if (s)
959  n1 = s+1;
960  s = strchr(n2,'(');
961  if (s)
962  n2 = s+1;
963 
964  for ( ; ; n1++,n2++) {
965  if ((*n1 == 0 || *n1 == ')') && (*n2 == 0 || *n2 == ')'))
966  return (true);
967  if (*n1 != *n2)
968  break;
969  }
970  return (false);
971 }
Definition: cddefs.h:119
static void out_destroy ( )
static

Definition at line 130 of file outitf.c.

131 {
132  if (OUTcntrl.out_rundesc) {
135  }
136  OUTcntrl.out_check = false;
137  OUTcntrl.out_usecurplot = false;
138  OUTcntrl.out_keepplot = false;
140  OUTcntrl.out_index = 0;
141  OUTcntrl.out_max = 0;
142  OUTcntrl.out_fail = 0;
145 }
int out_max
Definition: outdata.h:42
int out_keepplot
Definition: outdata.h:39
int out_index
Definition: outdata.h:41
int out_usecurplot
Definition: outdata.h:38
Definition: outitf.c:40
char * out_rundesc
Definition: outdata.h:44
double * out_points
Definition: outdata.h:40
#define NULL
Definition: spdefs.h:121
static struct sOUTcontrol OUTcntrl
Definition: outitf.c:62
static void freeRun()
int out_fail
Definition: outdata.h:43
int out_check
Definition: outdata.h:37
void(* out_end)()
Definition: outdata.h:51
int(* out_evaluate)()
Definition: outdata.h:50
int OUTbeginPlot ( GENERIC outdp)

Definition at line 149 of file outitf.c.

152 {
153  struct sOUTdata *outd = (struct sOUTdata*)outdp;
154  struct plot *plot = NULL;
155  runDesc *run;
156  char **saves;
157  char *cktName;
158  bool *savesused;
159  int numsaves;
160  int i, j, depind;
161  char namebuf[BSIZE_SP], parambuf[BSIZE_SP], depbuf[BSIZE_SP];
162  bool saveall = true;
163  extern char *kw_printinfo;
164 
165  shouldstop = false;
166 
167  if (OUTcntrl.out_check) {
168  OUTcntrl.out_index = 0;
169  }
170  if (OUTcntrl.out_usecurplot) {
171  plot = plot_cur;
172  }
174  *outd->plotPtr = (GENERIC*)OUTcntrl.out_rundesc;
175  return (OK);
176  }
177 
178  if (ft_curckt && ft_curckt->ci_ckt == outd->circuitPtr)
179  cktName = ft_curckt->ci_name;
180  else {
181  /* hack for test system interface */
182  if (outd->circuitPtr == NULL)
183  cktName = (char*)outd->refName + (strlen(outd->refName) + 1);
184  else
185  cktName = "circuit name";
186  }
187 
188  /* Check to see if we want to print informational data. */
189  if (cp_getvar(kw_printinfo, VT_BOOL, (char *) &printinfo))
190  fprintf(cp_err, "(debug printing enabled)\n");
191 
192  run = alloc(struct runDesc);
193  *outd->plotPtr = (GENERIC*)run;
194 
195  /* First fill in some general stuff. */
196  run->analysis = outd->analysisPtr;
197  run->circuit = outd->circuitPtr;
198  run->name = copy(cktName);
199  run->type = copy(outd->analName);
200  if (outd->numPts <= 0)
201  run->numPoints = 1;
202  else
203  run->numPoints = outd->numPts;
204 
205  if (OUTcntrl.out_check) {
206  run->numPoints = 1;
207  }
208  if (OUTcntrl.out_keepplot) {
209  OUTcntrl.out_rundesc = (char*)run;
210  }
211 
212  /* Now let's see which of these things we need. First toss in the
213  * reference vector. Then toss in anything that getSaves() tells
214  * us to save that we can find in the name list. Finally unpack
215  * the remaining saves into parameters.
216  */
217  numsaves = ft_getSaves(&saves);
218  if (numsaves) {
219  savesused = (bool *) tmalloc(sizeof (bool) * numsaves);
220  saveall = false;
221  for (i = 0; i < numsaves; i++)
222  if (cieq(saves[i], "all")) {
223  saveall = true;
224  savesused[i] = true;
225  break;
226  }
227  }
228 
229  /* Pass 0. */
230  if (outd->refName) {
231  addDataDesc(run, outd->refName, outd->refType, -1);
232  for (i = 0; i < numsaves; i++)
233  if (name_eq(saves[i], outd->refName)) {
234  savesused[i] = true;
235  }
236  }
237  else {
238  run->refIndex = -1;
239  }
240 
241  /* Pass 1. */
242  if (numsaves && !saveall) {
243  for (i = 0; i < numsaves; i++) {
244  for (j = 0; j < outd->numNames; j++)
245  if (name_eq(saves[i], outd->dataNames[j])) {
246  addDataDesc(run, outd->dataNames[j],
247  outd->dataType, j);
248  savesused[i] = true;
249  break;
250  }
251  }
252  }
253  else {
254  for (i = 0; i < outd->numNames; i++)
255  if (!outd->refName ||
256  !name_eq(outd->dataNames[i], outd->refName)) {
257  addDataDesc(run, outd->dataNames[i], outd->dataType, i);
258  }
259  }
260 
261  /* Pass 2. */
262  for (i = 0; i < numsaves; i++) {
263  if (savesused[i])
264  continue;
265  if (!parseSpecial(saves[i], namebuf, parambuf, depbuf)) {
266  if (numsaves == 1 && !saves[0])
267  fprintf(cp_err, "Warning: no variables saved\n");
268  else
269  fprintf(cp_err, "Warning: can't parse '%s': ignored\n",
270  saves[i]);
271  continue;
272  }
273  /* Now, if there's a dep variable, do we already have it? */
274  if (*depbuf) {
275  for (j = 0; j < run->numData; j++)
276  if (name_eq(depbuf, run->data[j].name))
277  break;
278  if (j == run->numData) {
279  /* Better add it. */
280  for (j = 0; j < outd->numNames; j++)
281  if (name_eq(depbuf, outd->dataNames[j]))
282  break;
283  if (j == outd->numNames) {
284  fprintf(cp_err,
285  "Warning: can't find '%s': value '%s' ignored\n",
286  depbuf, saves[i]);
287  continue;
288  }
289  addDataDesc(run, outd->dataNames[j], outd->dataType, j);
290  savesused[i] = true;
291  depind = j;
292  }
293  else
294  depind = run->data[j].outIndex;
295  }
296  addSpecialDesc(run, saves[i], namebuf, parambuf, depind);
297  }
298 
299  if (numsaves)
300  txfree((char*)savesused);
301 
302  /* Now that we have our own data structures built up, let's see what
303  * nutmeg wants us to do.
304  */
305  run->writeOut = ft_getOutReq(&run->fp, &run->runPlot, &run->binary,
306  run->type, run->name);
307 
308  if (run->writeOut)
309  fileInit(run);
310  else
311  plotInit(run,outd->initValue,outd->finalValue,outd->step,plot);
312 
313  if (outd->refName && run->runPlot)
314  run->runPlot->pl_ndims = 1;
315 
316  return (OK);
317 }
FILE * fp
Definition: outitf.c:51
int numPts
Definition: outdata.h:22
#define BSIZE_SP
Definition: misc.h:19
double initValue
Definition: outdata.h:24
static bool name_eq()
bool cp_getvar(char *n, int t, char *r)
Definition: help.c:184
int out_keepplot
Definition: outdata.h:39
int out_index
Definition: outdata.h:41
int cieq()
bool writeOut
Definition: outitf.c:48
int out_usecurplot
Definition: outdata.h:38
GENERIC * circuit
Definition: outitf.c:42
int refType
Definition: outdata.h:17
char * kw_printinfo
Definition: options.c:406
IFuid * dataNames
Definition: outdata.h:19
struct plot * plot_cur
Definition: vectors.c:43
IFuid analName
Definition: outdata.h:15
GENERIC * analysis
Definition: outitf.c:41
int numNames
Definition: outdata.h:18
char * name
Definition: outitf.c:27
int outIndex
Definition: outitf.c:30
dataDesc * data
Definition: outitf.c:47
char * ci_ckt
Definition: ftedefs.h:27
Definition: ftedata.h:61
double step
Definition: outdata.h:26
Definition: outitf.c:40
char * out_rundesc
Definition: outdata.h:44
static void fileInit()
int numPoints
Definition: outitf.c:54
#define alloc(type)
Definition: cdmacs.h:21
static bool parseSpecial()
int numData
Definition: outitf.c:45
char * copy()
static int addDataDesc()
FILE * cp_err
Definition: help.c:101
#define OK
Definition: iferrmsg.h:17
char * tmalloc()
static void plotInit()
struct plot * runPlot
Definition: outitf.c:50
void txfree()
#define NULL
Definition: spdefs.h:121
struct circ * ft_curckt
Definition: main.c:184
GENERIC * circuitPtr
Definition: outdata.h:13
char * type
Definition: outitf.c:44
bool ft_getOutReq(FILE **fpp, struct plot **plotp, bool *binp, char *name, char *title)
Definition: runcoms.c:385
static struct sOUTcontrol OUTcntrl
Definition: outitf.c:62
int ft_getSaves()
#define VT_BOOL
Definition: cpstd.h:60
int pl_ndims
Definition: ftedata.h:74
double finalValue
Definition: outdata.h:25
return(True)
static bool shouldstop
Definition: outitf.c:106
bool binary
Definition: outitf.c:49
GENERIC * analysisPtr
Definition: outdata.h:14
static bool printinfo
Definition: outitf.c:107
char * name
Definition: outitf.c:43
int refIndex
Definition: outitf.c:46
char * ci_name
Definition: ftedefs.h:26
int out_check
Definition: outdata.h:37
GENERIC ** plotPtr
Definition: outdata.h:21
IFuid refName
Definition: outdata.h:16
char GENERIC
Definition: ifsim.h:27
int dataType
Definition: outdata.h:20
static int addSpecialDesc()
char* OUTcntrlInit ( )

Definition at line 111 of file outitf.c.

112 {
113  /* return the OUTcntrl structure */
116  OUTcntrl.out_check = false;
117  OUTcntrl.out_usecurplot = false;
118  OUTcntrl.out_keepplot = false;
120  OUTcntrl.out_index = 0;
121  OUTcntrl.out_max = 0;
122  OUTcntrl.out_fail = 0;
125  return (char *)&OUTcntrl;
126 }
int out_max
Definition: outdata.h:42
int out_keepplot
Definition: outdata.h:39
int out_index
Definition: outdata.h:41
int out_usecurplot
Definition: outdata.h:38
char * out_rundesc
Definition: outdata.h:44
void(* out_destroy)()
Definition: outdata.h:52
double * out_points
Definition: outdata.h:40
#define NULL
Definition: spdefs.h:121
static struct sOUTcontrol OUTcntrl
Definition: outitf.c:62
int out_fail
Definition: outdata.h:43
static void out_destroy()
Definition: outitf.c:130
int out_check
Definition: outdata.h:37
void(* out_end)()
Definition: outdata.h:51
int(* out_evaluate)()
Definition: outdata.h:50
int OUTdata ( GENERIC plotPtr,
IFvalue refValue,
IFvalue valuePtr 
)

Definition at line 396 of file outitf.c.

401 {
402  runDesc *run = (runDesc *) plotPtr;
403 
404  if (OUTcntrl.out_check) {
405 
406  if (refValue->rValue < OUTcntrl.out_points[OUTcntrl.out_index])
407  return (OK);
408 
409  addPointToPlot(run,refValue,valuePtr,false);
412  else
413  OUTcntrl.out_fail = false;
414 
417  OUTendit = true;
418  }
419  return (OK);
420  }
421 
422  run->pointCount++;
423 
424  if (run->writeOut) {
425  addPointToFile(run,refValue,valuePtr);
426  }
427  else {
428  addPointToPlot(run,refValue,valuePtr,true);
429  gr_iplot(run->runPlot);
430  }
431 
432  if (ft_bpcheck(run->runPlot, run->pointCount) == false)
433  shouldstop = true;
434 
435  vec_gc();
436  return (OK);
437 }
int out_max
Definition: outdata.h:42
static void addPointToFile()
int out_index
Definition: outdata.h:41
bool writeOut
Definition: outitf.c:48
void vec_gc()
Definition: vectors.c:681
Definition: outitf.c:40
double rValue
Definition: ifsim.h:233
bool ft_bpcheck()
#define OK
Definition: iferrmsg.h:17
double * out_points
Definition: outdata.h:40
static void addPointToPlot()
struct plot * runPlot
Definition: outitf.c:50
static struct sOUTcontrol OUTcntrl
Definition: outitf.c:62
int pointCount
Definition: outitf.c:53
bool OUTendit
Definition: outitf.c:60
void gr_iplot()
static bool shouldstop
Definition: outitf.c:106
int out_fail
Definition: outdata.h:43
int out_check
Definition: outdata.h:37
int(* out_evaluate)()
Definition: outdata.h:50
int OUTendPlot ( GENERIC plotPtr)

Definition at line 571 of file outitf.c.

574 {
575  runDesc *run = (runDesc *) plotPtr;
576 
577  if (OUTcntrl.out_check) {
578  if (OUTcntrl.out_end)
579  (*OUTcntrl.out_end)();
580  OUTendit = false;
581  return (OK);
582  }
583  else if (OUTcntrl.out_keepplot) {
584  return (OK);
585  }
586 
587  if (run->writeOut)
588  fileEnd(run);
589  else {
590  gr_end_iplot();
591  plotEnd(run);
592  }
593 
594  freeRun(run);
595 
596  return (OK);
597 }
int out_keepplot
Definition: outdata.h:39
bool writeOut
Definition: outitf.c:48
Definition: outitf.c:40
#define OK
Definition: iferrmsg.h:17
static void fileEnd()
static struct sOUTcontrol OUTcntrl
Definition: outitf.c:62
bool OUTendit
Definition: outitf.c:60
static void freeRun()
void gr_end_iplot()
Definition: iplot.c:397
int out_check
Definition: outdata.h:37
void(* out_end)()
Definition: outdata.h:51
static void plotEnd()
int OUTerror ( int  flags,
char *  format,
IFuid names 
)

Definition at line 1062 of file outitf.c.

1067 {
1068 
1069  struct mesg *m;
1070  char buf[BSIZE_SP], *s, *bptr;
1071  int nindex = 0;
1072 
1073  if ((flags == ERR_INFO) && !printinfo)
1074  return (OK);
1075 
1076  for (m = msgs; m->flag; m++)
1077  if (flags & m->flag)
1078  fprintf(cp_err, "%s: ", m->string);
1079 
1080  for (s = format, bptr = buf; *s; s++) {
1081  if (*s == '%' && (s == format || *(s-1) != '%') && *(s+1) == 's') {
1082  strcpy(bptr, names[nindex]);
1083  bptr += strlen(names[nindex]);
1084  s++;
1085  nindex++;
1086  }
1087  else {
1088  *bptr++ = *s;
1089  }
1090  }
1091  *bptr = '\0';
1092  fprintf(cp_err, "%s\n", buf);
1093  fflush(cp_err);
1094  return (OK);
1095 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
Definition: outitf.c:1049
char * strcpy()
Definition: cddefs.h:119
static struct mesg msgs[]
FILE * m
Definition: proc2mod.c:47
#define ERR_INFO
Definition: ifsim.h:520
FILE * cp_err
Definition: help.c:101
#define OK
Definition: iferrmsg.h:17
static bool printinfo
Definition: outitf.c:107
long flag
Definition: outitf.c:1051
char * string
Definition: outitf.c:1050
int OUTsetDims ( GENERIC plotPtr,
int *  dims,
int  numDims 
)

Definition at line 441 of file outitf.c.

445 {
446  runDesc *run = (runDesc *) plotPtr;
447  struct dvec *v;
448  int i, j;
449 
450  if (OUTcntrl.out_check) {
451  OUTcntrl.out_index = 0;
452  if (OUTcntrl.out_fail)
453  OUTendit = true;
454  return (OK);
455  }
456 
457  if (run->writeOut)
458  return (OK);
459 
460  for (i = 0; i < run->numData; i++) {
461  v = run->data[i].vec;
462  for (j = 0; j < numDims; j++)
463  v->v_dims[j] = dims[j];
464  v->v_numdims = numDims;
465  }
466  return (OK);
467 }
int out_index
Definition: outdata.h:41
bool writeOut
Definition: outitf.c:48
dataDesc * data
Definition: outitf.c:47
int v_dims[MAXDIMS]
Definition: ftedata.h:41
Definition: outitf.c:40
int numData
Definition: outitf.c:45
#define OK
Definition: iferrmsg.h:17
static struct sOUTcontrol OUTcntrl
Definition: outitf.c:62
Definition: ftedata.h:24
bool OUTendit
Definition: outitf.c:60
int out_fail
Definition: outdata.h:43
struct dvec * vec
Definition: outitf.c:37
int v_numdims
Definition: ftedata.h:40
int out_check
Definition: outdata.h:37
int OUTstopnow ( )

Definition at line 1032 of file outitf.c.

1033 {
1034  static REQUEST reqst = { checkup_option, 0 };
1035 
1036  if (!ft_batchmode)
1037  DevInput(&reqst, 0);
1038  if (ft_intrpt || shouldstop) {
1039  ft_intrpt = shouldstop = false;
1040  return (1);
1041  }
1042  else
1043  return (0);
1044 }
bool ft_intrpt
Definition: main.c:47
void DevInput()
static bool shouldstop
Definition: outitf.c:106
bool ft_batchmode
Definition: main.c:98
static bool parseSpecial ( )
static
static bool parseSpecial ( char *  name,
char *  dev,
char *  param,
char *  ind 
)
static

Definition at line 902 of file outitf.c.

908 {
909  char *s;
910 
911  *dev = *param = *ind = '\0';
912 
913  if (*name != '@')
914  return (false);
915  name++;
916 
917  s = dev;
918  while (*name && (*name != '['))
919  *s++ = *name++;
920  *s = '\0';
921  if (!*name)
922  return (true);
923  name++;
924 
925  s = param;
926  while (*name && (*name != ',') && (*name != ']'))
927  *s++ = *name++;
928  *s = '\0';
929  if (*name == ']')
930  return (!name[1] ? true : false);
931  else if (!*name)
932  return (false);
933  name++;
934 
935  s = ind;
936  while (*name && (*name != ']'))
937  *s++ = *name++;
938  *s = '\0';
939  if (*name && !name[1])
940  return (true);
941  else
942  return (false);
943 }
Definition: cddefs.h:119
static void plotAddComplexValue ( )
static
static void plotAddComplexValue ( dataDesc desc,
IFcomplex  value,
bool  inc 
)
static

Definition at line 860 of file outitf.c.

865 {
866  struct dvec *v = desc->vec;
867 
868  if (!inc) {
869  v->v_compdata[0].cx_real = value.real;
870  v->v_compdata[0].cx_imag = value.imag;
871  v->v_length = 1;
872  return;
873  }
874  if (v->v_length >= v->v_rlength) {
875  v->v_compdata = (complex *) trealloc((char *) v->v_compdata,
876  sizeof (complex) * (v->v_length + 1));
877  v->v_rlength = v->v_length + 1;
878  }
879  v->v_compdata[v->v_length].cx_real = value.real;
880  v->v_compdata[v->v_length].cx_imag = value.imag;
881  v->v_length++;
882 
883  return;
884 }
int v_rlength
Definition: ftedata.h:35
double cx_imag
Definition: cpstd.h:31
Definition: cpstd.h:29
complex * v_compdata
Definition: ftedata.h:29
double cx_real
Definition: cpstd.h:30
Definition: ftedata.h:24
struct _complex complex
Definition: cpstd.h:33
struct dvec * vec
Definition: outitf.c:37
int v_length
Definition: ftedata.h:34
double imag
Definition: ifsim.h:227
char * trealloc()
double real
Definition: ifsim.h:226
static void plotAddRealValue ( )
static
static void plotAddRealValue ( dataDesc desc,
double  value,
bool  inc 
)
static

Definition at line 816 of file outitf.c.

821 {
822  struct dvec *v = desc->vec;
823 
824  if (isreal(v)) {
825  if (!inc) {
826  v->v_realdata[0] = value;
827  v->v_length = 1;
828  return;
829  }
830  if (v->v_length >= v->v_rlength) {
831  v->v_realdata = (double *) trealloc((char *) v->v_realdata,
832  sizeof (double) * (v->v_length + 1));
833  v->v_rlength = v->v_length + 1;
834  }
835  v->v_realdata[v->v_length] = value;
836  }
837  else {
838  /* a real parading as a VF_COMPLEX */
839  if (!inc) {
840  v->v_compdata[0].cx_real = value;
841  v->v_compdata[0].cx_imag = (double) 0;
842  v->v_length = 1;
843  return;
844  }
845  if (v->v_length >= v->v_rlength) {
846  v->v_compdata = (complex *) trealloc((char *) v->v_compdata,
847  sizeof (complex) * (v->v_length + 1));
848  v->v_rlength = v->v_length + 1;
849  }
850  v->v_compdata[v->v_length].cx_real = value;
851  v->v_compdata[v->v_length].cx_imag = (double) 0;
852  }
853  v->v_length++;
854 
855  return;
856 }
int v_rlength
Definition: ftedata.h:35
double cx_imag
Definition: cpstd.h:31
Definition: cpstd.h:29
complex * v_compdata
Definition: ftedata.h:29
double cx_real
Definition: cpstd.h:30
#define isreal(v)
Definition: ftedata.h:54
Definition: ftedata.h:24
struct _complex complex
Definition: cpstd.h:33
struct dvec * vec
Definition: outitf.c:37
int v_length
Definition: ftedata.h:34
double * v_realdata
Definition: ftedata.h:28
char * trealloc()
static void plotEnd ( )
static
static void plotEnd ( runDesc run)
static

Definition at line 889 of file outitf.c.

892 {
893  return;
894 }
static void plotInit ( )
static
static void plotInit ( runDesc run,
double  tstart,
double  tstop,
double  tstep,
struct plot plot 
)
static

Definition at line 743 of file outitf.c.

748 {
749  struct plot *pl;
750  char buf[100];
751  struct dvec *v;
752  dataDesc *dd;
753  int i;
754 
755  if (plot == NULL) {
756  pl = plot_alloc(run->type);
757  plot_new(pl);
759  }
760  else
761  pl = plot;
762  pl->pl_title = copy(run->name);
763  pl->pl_name = copy(run->type);
764  pl->pl_date = copy(datestring( ));
765  pl->pl_ndims = 0;
766  pl->pl_start = tstart;
767  pl->pl_stop = tstop;
768  pl->pl_step = tstep;
769  run->runPlot = pl;
770 
771  /* This is a hack. */
772  /* if any of them are complex, make them all complex */
773  run->isComplex = false;
774  for (i = 0; i < run->numData; i++) {
775  if (run->data[i].type == IF_COMPLEX) run->isComplex = true;
776  }
777 
778  for (i = 0; i < run->numData; i++) {
779  dd = &run->data[i];
780  v = alloc(struct dvec);
781  if (isdigit(*dd->name)) {
782  (void) sprintf(buf, "v(%s)", dd->name);
783  v->v_name = copy(buf);
784  }
785  else
786  v->v_name = copy(dd->name);
787  if (substring("#branch", v->v_name) || eq(v->v_name,"isweep"))
788  v->v_type = SV_CURRENT;
789  else if (cieq(v->v_name, "time"))
790  v->v_type = SV_TIME;
791  else if (cieq(v->v_name, "frequency"))
792  v->v_type = SV_FREQUENCY;
793  else
794  v->v_type = SV_VOLTAGE;
795  v->v_length = 0;
796  v->v_rlength = run->numPoints;
797  v->v_scale = NULL;
798 
799  if (!run->isComplex) {
800  v->v_flags = VF_REAL;
801  v->v_realdata = (double *)
802  tmalloc(v->v_rlength * sizeof(double));
803  }
804  else {
805  v->v_flags = VF_COMPLEX;
806  v->v_compdata = (complex *)
807  tmalloc(v->v_rlength * sizeof(complex));
808  }
809  vec_newperm(v);
810  dd->vec = v;
811  }
812 }
int isComplex
Definition: outitf.c:55
static char buf[MAXPROMPT]
Definition: arg.c:18
#define eq(a, b)
Definition: misc.h:29
#define IF_COMPLEX
Definition: ifsim.h:109
struct plot * plot_alloc()
int v_rlength
Definition: ftedata.h:35
void plot_new()
char * pl_typename
Definition: ftedata.h:65
char * pl_date
Definition: ftedata.h:63
#define VF_REAL
Definition: fteconst.h:39
int cieq()
char * pl_title
Definition: ftedata.h:62
char * pl_name
Definition: ftedata.h:64
double pl_step
Definition: ftedata.h:78
int type
Definition: outitf.c:28
char * name
Definition: outitf.c:27
char * datestring()
Definition: time.c:37
dataDesc * data
Definition: outitf.c:47
Definition: cpstd.h:29
#define SV_VOLTAGE
Definition: fteconst.h:14
int numPoints
Definition: outitf.c:54
#define alloc(type)
Definition: cdmacs.h:21
complex * v_compdata
Definition: ftedata.h:29
int numData
Definition: outitf.c:45
char * copy()
char * tmalloc()
int substring()
struct plot * runPlot
Definition: outitf.c:50
#define NULL
Definition: spdefs.h:121
void vec_newperm()
char * type
Definition: outitf.c:44
struct dvec * v_scale
Definition: ftedata.h:45
Definition: ftedata.h:24
char * v_name
Definition: ftedata.h:25
int pl_ndims
Definition: ftedata.h:74
#define SV_CURRENT
Definition: fteconst.h:15
int v_type
Definition: ftedata.h:26
double pl_start
Definition: ftedata.h:76
char * name
Definition: outitf.c:43
struct dvec * vec
Definition: outitf.c:37
int v_length
Definition: ftedata.h:34
double pl_stop
Definition: ftedata.h:77
short v_flags
Definition: ftedata.h:27
double * v_realdata
Definition: ftedata.h:28
void plot_setcur()
#define SV_FREQUENCY
Definition: fteconst.h:13
#define VF_COMPLEX
Definition: fteconst.h:40
#define SV_TIME
Definition: fteconst.h:12

Variable Documentation

struct mesg msgs[]
static
Initial value:
= {
{ "Warning", ERR_WARNING } ,
{ "Fatal error", ERR_FATAL } ,
{ "Panic", ERR_PANIC } ,
{ "Note", ERR_INFO } ,
{ NULL, 0 }
}
#define ERR_PANIC
Definition: ifsim.h:519
#define ERR_FATAL
Definition: ifsim.h:518
#define ERR_INFO
Definition: ifsim.h:520
#define NULL
Definition: spdefs.h:121
#define ERR_WARNING
Definition: ifsim.h:517
struct sOUTcontrol OUTcntrl
static

Definition at line 62 of file outitf.c.

bool OUTendit

Definition at line 60 of file outitf.c.

bool printinfo = false
static

Definition at line 107 of file outitf.c.

bool shouldstop = false
static

Definition at line 106 of file outitf.c.