Jspice3
cktsetbk.c File Reference
#include "spice.h"
#include <stdio.h>
#include "cktdefs.h"
#include "sperror.h"
#include "util.h"
#include "cktext.h"
Include dependency graph for cktsetbk.c:

Go to the source code of this file.

Functions

int CKTsetBreak (CKTcircuit *ckt, double time)
 

Function Documentation

int CKTsetBreak ( CKTcircuit ckt,
double  time 
)

Definition at line 21 of file cktsetbk.c.

25 {
26  double *tmp;
27  int i,j;
28 
29  if (ckt->CKTtime > time) {
30  (*(SPfrontEnd->IFerror))(ERR_PANIC,"breakpoint in the past - HELP!",
31  (IFuid *)NULL);
32  return (E_INTERN);
33  }
34 
35  for (i = 0; i < ckt->CKTbreakSize; i++) {
36  if (*(ckt->CKTbreaks + i) > time) { /* passed */
37  if ((*(ckt->CKTbreaks + i) - time) <= ckt->CKTminBreak) {
38  /* very close together - take earlier point */
39  *(ckt->CKTbreaks+i) = time;
40  return (OK);
41  }
42  if (time - *(ckt->CKTbreaks + i-1) <= ckt->CKTminBreak) {
43  /* very close together, but after, so skip */
44  return (OK);
45  }
46  /* fits in middle - new array & insert */
47  tmp = (double *)MALLOC((ckt->CKTbreakSize + 1)*sizeof(double));
48  if (tmp == (double *)NULL) return(E_NOMEM);
49  for (j = 0; j < i; j++) {
50  *(tmp + j) = *(ckt->CKTbreaks + j);
51  }
52  *(tmp + i) = time;
53  for (j = i; j < ckt->CKTbreakSize; j++) {
54  *(tmp + j+1) = *(ckt->CKTbreaks + j);
55  }
56  FREE(ckt->CKTbreaks);
57  ckt->CKTbreakSize++;
58  ckt->CKTbreaks = tmp;
59  return (OK);
60  }
61  }
62  /* never found it - beyond end of time - extend out idea of time */
63  if (time - ckt->CKTbreaks[ckt->CKTbreakSize-1] <= ckt->CKTminBreak) {
64  /* very close tegether - keep earlier, throw out new point */
65  return (OK);
66  }
67  /* fits at end - grow array & add on */
68  ckt->CKTbreaks = (double *)REALLOC(ckt->CKTbreaks,
69  (ckt->CKTbreakSize + 1)*sizeof(double));
70  ckt->CKTbreakSize++;
71  ckt->CKTbreaks[ckt->CKTbreakSize - 1] = time;
72  return (OK);
73 }
double CKTtime
Definition: cktdefs.h:77
#define E_INTERN
Definition: sperror.h:15
double CKTminBreak
Definition: cktdefs.h:178
#define ERR_PANIC
Definition: ifsim.h:519
IFfrontEnd * SPfrontEnd
Definition: main.c:917
#define FREE(ptr)
Definition: spdefs.h:436
#define OK
Definition: iferrmsg.h:17
GENERIC * IFuid
Definition: ifsim.h:72
#define MALLOC(x)
Definition: util.h:9
#define NULL
Definition: spdefs.h:121
#define E_NOMEM
Definition: iferrmsg.h:27
double * CKTbreaks
Definition: cktdefs.h:179
#define REALLOC(ptr, type, number)
Definition: spdefs.h:434
int CKTbreakSize
Definition: cktdefs.h:175