Jspice3
cktsetbk.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3f2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1985 Thomas L. Quarles
5  1993 Stephen R. Whiteley
6 ****************************************************************************/
7 
8  /* CKTsetBreak(ckt,time)
9  * add the given time to the breakpoint table for the given circuit
10  */
11 
12 #include "spice.h"
13 #include <stdio.h>
14 #include "cktdefs.h"
15 #include "sperror.h"
16 #include "util.h"
17 #include "cktext.h"
18 
19 
20 int
21 CKTsetBreak(ckt,time)
22 
23 CKTcircuit *ckt;
24 double time;
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 }
#define E_INTERN
Definition: sperror.h:15
#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
int CKTsetBreak(CKTcircuit *ckt, double time)
Definition: cktsetbk.c:21
#define REALLOC(ptr, type, number)
Definition: spdefs.h:434