Jspice3
ptfuncs.c File Reference
#include "spice.h"
#include <stdio.h>
#include <math.h>
#include "inpptree.h"
Include dependency graph for ptfuncs.c:

Go to the source code of this file.

Macros

#define MODULUS(NUM, LIMIT)   ((NUM) - ((int) ((NUM) / (LIMIT))) * (LIMIT))
 
#define V1   p->tranparms[0]
 
#define V2   p->tranparms[1]
 
#define TD   p->tranparms[2]
 
#define TR   p->tranparms[3]
 
#define TF   p->tranparms[4]
 
#define PW   p->tranparms[5]
 
#define PER   p->tranparms[6]
 
#define SPER   p->tranparms[2]
 
#define SDEL   p->tranparms[3]
 
#define VO   p->tranparms[0]
 
#define VA   p->tranparms[1]
 
#define FREQ   p->tranparms[2]
 
#define TDL   p->tranparms[3]
 
#define THETA   p->tranparms[4]
 
#define TD1   p->tranparms[2]
 
#define TAU1   p->tranparms[3]
 
#define TD2   p->tranparms[4]
 
#define TAU2   p->tranparms[5]
 
#define FC   p->tranparms[2]
 
#define MDI   p->tranparms[3]
 
#define FS   p->tranparms[4]
 

Functions

double asinh ()
 
double acosh ()
 
double atanh ()
 
static double PTtPulse ()
 
static double PTtPwl ()
 
static double PTtSin ()
 
static double PTtSpulse ()
 
static double PTtExp ()
 
static double PTtSffm ()
 
static double PTabs ()
 
static double PTsgn ()
 
static double PTplus ()
 
static double PTminus ()
 
static double PTtimes ()
 
static double PTdivide ()
 
static double PTpower ()
 
static double PTacos ()
 
static double PTasin ()
 
static double PTatan ()
 
static double PTcos ()
 
static double PTcosh ()
 
static double PTexp ()
 
static double PTln ()
 
static double PTlog ()
 
static double PTsin ()
 
static double PTsinh ()
 
static double PTsqrt ()
 
static double PTtan ()
 
static double PTtanh ()
 
static double PTuminus ()
 
static double PTtPulse (INPparseNode *p, double *t)
 
static double PTtPwl (INPparseNode *p, double *t)
 
static double PTtSin (INPparseNode *p, double *t)
 
static double PTtSpulse (INPparseNode *p, double *t)
 
static double PTtExp (INPparseNode *p, double *t)
 
static double PTtSffm (INPparseNode *p, double *t)
 
static double PTabs (double arg)
 
static double PTsgn (double arg)
 
static double PTplus (double arg1, double arg2)
 
static double PTminus (double arg1, double arg2)
 
static double PTtimes (double arg1, double arg2)
 
static double PTdivide (double arg1, double arg2)
 
static double PTpower (double arg1, double arg2)
 
static double PTacos (double arg)
 
static double PTasin (double arg)
 
static double PTatan (double arg)
 
static double PTcos (double arg)
 
static double PTcosh (double arg)
 
static double PTexp (double arg)
 
static double PTln (double arg)
 
static double PTlog (double arg)
 
static double PTsin (double arg)
 
static double PTsinh (double arg)
 
static double PTsqrt (double arg)
 
static double PTtan (double arg)
 
static double PTtanh (double arg)
 
static double PTuminus (double arg)
 

Variables

double PTfudge_factor
 
struct sPTop PTops []
 
struct sPTfunc PTfuncs []
 
struct sPTfunc PTtFuncs []
 

Macro Definition Documentation

#define FC   p->tranparms[2]

Definition at line 164 of file ptfuncs.c.

#define FREQ   p->tranparms[2]

Definition at line 155 of file ptfuncs.c.

#define FS   p->tranparms[4]

Definition at line 166 of file ptfuncs.c.

#define MDI   p->tranparms[3]

Definition at line 165 of file ptfuncs.c.

#define MODULUS (   NUM,
  LIMIT 
)    ((NUM) - ((int) ((NUM) / (LIMIT))) * (LIMIT))

Definition at line 92 of file ptfuncs.c.

#define PER   p->tranparms[6]

Definition at line 148 of file ptfuncs.c.

#define PW   p->tranparms[5]

Definition at line 147 of file ptfuncs.c.

#define SDEL   p->tranparms[3]

Definition at line 151 of file ptfuncs.c.

#define SPER   p->tranparms[2]

Definition at line 150 of file ptfuncs.c.

#define TAU1   p->tranparms[3]

Definition at line 160 of file ptfuncs.c.

#define TAU2   p->tranparms[5]

Definition at line 162 of file ptfuncs.c.

#define TD   p->tranparms[2]

Definition at line 144 of file ptfuncs.c.

#define TD1   p->tranparms[2]

Definition at line 159 of file ptfuncs.c.

#define TD2   p->tranparms[4]

Definition at line 161 of file ptfuncs.c.

#define TDL   p->tranparms[3]

Definition at line 156 of file ptfuncs.c.

#define TF   p->tranparms[4]

Definition at line 146 of file ptfuncs.c.

#define THETA   p->tranparms[4]

Definition at line 157 of file ptfuncs.c.

#define TR   p->tranparms[3]

Definition at line 145 of file ptfuncs.c.

#define V1   p->tranparms[0]

Definition at line 142 of file ptfuncs.c.

#define V2   p->tranparms[1]

Definition at line 143 of file ptfuncs.c.

#define VA   p->tranparms[1]

Definition at line 154 of file ptfuncs.c.

#define VO   p->tranparms[0]

Definition at line 153 of file ptfuncs.c.

Function Documentation

double acosh ( )
double asinh ( )
double atanh ( )
static double PTabs ( )
static
static double PTabs ( double  arg)
static

Definition at line 318 of file ptfuncs.c.

321 { return arg >= 0.0 ? arg : -arg; }
static double PTacos ( )
static
static double PTacos ( double  arg)
static

Definition at line 377 of file ptfuncs.c.

380 { return (acos(arg)); }
static double PTasin ( )
static
static double PTasin ( double  arg)
static

Definition at line 384 of file ptfuncs.c.

387 { return (asin(arg)); }
static double PTatan ( )
static
static double PTatan ( double  arg)
static

Definition at line 391 of file ptfuncs.c.

394 { return (atan(arg)); }
static double PTcos ( )
static
static double PTcos ( double  arg)
static

Definition at line 423 of file ptfuncs.c.

426 { return (cos(MODULUS(arg, 2 * M_PI))); }
#define M_PI
Definition: spice.h:132
double cos()
#define MODULUS(NUM, LIMIT)
Definition: ptfuncs.c:92
static double PTcosh ( )
static
static double PTcosh ( double  arg)
static

Definition at line 430 of file ptfuncs.c.

433 { return (cosh(arg)); }
static double PTdivide ( )
static
static double PTdivide ( double  arg1,
double  arg2 
)
static

Definition at line 353 of file ptfuncs.c.

356 {
357  if (arg2 >= 0.0)
358  arg2 += PTfudge_factor;
359  else
360  arg2 -= PTfudge_factor;
361 
362  if (arg2 == 0.0)
363  return (HUGE);
364 
365  return (arg1 / arg2);
366 }
double PTfudge_factor
Definition: ptfuncs.c:90
#define HUGE
Definition: spice.h:128
static double PTexp ( )
static
static double PTexp ( double  arg)
static

Definition at line 437 of file ptfuncs.c.

440 { return (exp(arg)); }
static double PTln ( )
static
static double PTln ( double  arg)
static

Definition at line 444 of file ptfuncs.c.

447 {
448  if (arg < 0.0)
449  arg = -arg;
450  return (log(arg));
451 }
static double PTlog ( )
static
static double PTlog ( double  arg)
static

Definition at line 455 of file ptfuncs.c.

458 {
459  if (arg < 0.0)
460  arg = -arg;
461  return (log10(arg));
462 }
static double PTminus ( )
static
static double PTminus ( double  arg1,
double  arg2 
)
static

Definition at line 339 of file ptfuncs.c.

342 { return (arg1 - arg2); }
static double PTplus ( )
static
static double PTplus ( double  arg1,
double  arg2 
)
static

Definition at line 332 of file ptfuncs.c.

335 { return (arg1 + arg2); }
static double PTpower ( )
static
static double PTpower ( double  arg1,
double  arg2 
)
static

Definition at line 370 of file ptfuncs.c.

373 { return (pow(arg1, arg2)); }
static double PTsgn ( )
static
static double PTsgn ( double  arg)
static

Definition at line 325 of file ptfuncs.c.

328 { return arg > 0.0 ? 1.0 : arg < 0.0 ? -1.0 : 0.0; }
static double PTsin ( )
static
static double PTsin ( double  arg)
static

Definition at line 466 of file ptfuncs.c.

469 { return (sin(MODULUS(arg, 2 * M_PI))); }
#define M_PI
Definition: spice.h:132
double sin()
#define MODULUS(NUM, LIMIT)
Definition: ptfuncs.c:92
static double PTsinh ( )
static
static double PTsinh ( double  arg)
static

Definition at line 473 of file ptfuncs.c.

476 { return (sinh(arg)); }
static double PTsqrt ( )
static
static double PTsqrt ( double  arg)
static

Definition at line 480 of file ptfuncs.c.

483 {
484  if (arg < 0.0)
485  arg = -arg;
486  return (sqrt(arg));
487 }
static double PTtan ( )
static
static double PTtan ( double  arg)
static

Definition at line 491 of file ptfuncs.c.

494 { return (tan(MODULUS(arg, M_PI))); }
#define M_PI
Definition: spice.h:132
#define MODULUS(NUM, LIMIT)
Definition: ptfuncs.c:92
static double PTtanh ( )
static
static double PTtanh ( double  arg)
static

Definition at line 498 of file ptfuncs.c.

501 { return (tanh(arg)); }
static double PTtExp ( )
static
static double PTtExp ( INPparseNode p,
double *  t 
)
static

Definition at line 286 of file ptfuncs.c.

290 {
291  double value;
292 
293  value = V1;
294  if (*t <= TD1)
295  return (value);
296  value += (V2-V1)*(1-exp(-(*t-TD1)/TAU1));
297  if (*t <= TD2)
298  return (value);
299  value += (V1-V2)*(1-exp(-(*t-TD2)/TAU2));
300  return (value);
301 }
#define TAU1
Definition: ptfuncs.c:160
#define V2
Definition: ptfuncs.c:143
#define V1
Definition: ptfuncs.c:142
#define TD1
Definition: ptfuncs.c:159
#define TD2
Definition: ptfuncs.c:161
Definition: cddefs.h:192
#define TAU2
Definition: ptfuncs.c:162
static double PTtimes ( )
static
static double PTtimes ( double  arg1,
double  arg2 
)
static

Definition at line 346 of file ptfuncs.c.

349 { return (arg1 * arg2); }
static double PTtPulse ( )
static
static double PTtPulse ( INPparseNode p,
double *  t 
)
static

Definition at line 171 of file ptfuncs.c.

175 {
176  double time, basetime, value;
177  double pw = TR + PW;
178  int i;
179 
180  time = *t - TD;
181  if (time > PER) {
182  /* repeating signal - figure out where we are in period */
183  basetime = PER * (int)(time/PER);
184  time -= basetime;
185  }
186  if (time < TR || time >= pw + TF) {
187  value = V1;
188  if (time > 0 && time < TR)
189  value += time* *p->trancache;
190  }
191  else {
192  value = V2;
193  if (time > pw)
194  value += (time - pw)* *(p->trancache+1);
195  }
196 
197  /* new feature: additional entries are added as in
198  * pulse(V1 V2 TD ...) + pulse(0 V2-V1 TD1 ...) + ...
199  * extra entries have offset subtracted
200  */
201  for (i = 7; i < p->numtrancoeffs; i++) {
202  time = *t - p->trancoeffs[i];
203  if (time > PER) {
204  /* repeating signal - figure out where we are in period */
205  basetime = PER * (int)(time/PER);
206  time -= basetime;
207  }
208  if (time < TR || time >= pw + TF) {
209  if (time > 0 && time < TR)
210  value += time* *p->trancache;
211  }
212  else {
213  value += (V2-V1);
214  if (time > pw)
215  value += (time - pw)* *(p->trancache+1);
216  }
217  }
218  return (value);
219 }
#define V2
Definition: ptfuncs.c:143
#define PW
Definition: ptfuncs.c:147
#define V1
Definition: ptfuncs.c:142
#define PER
Definition: ptfuncs.c:148
#define TD
Definition: ptfuncs.c:144
#define TF
Definition: ptfuncs.c:146
double * trancoeffs
Definition: inpptree.h:55
#define TR
Definition: ptfuncs.c:145
int numtrancoeffs
Definition: inpptree.h:58
double * trancache
Definition: inpptree.h:57
Definition: cddefs.h:192
static double PTtPwl ( )
static
static double PTtPwl ( INPparseNode p,
double *  t 
)
static

Definition at line 223 of file ptfuncs.c.

227 {
228  if (*t >= (*p->trancoeffs+p->numtrancoeffs-2))
229  return (*(p->trancoeffs+p->numtrancoeffs-1));
230  if (p->pwlindex + 2 < p->numtrancoeffs) {
231  for (;;) {
232  if (*t <= *(p->trancoeffs+p->pwlindex+2)) break;
233  p->pwlindex += 2;
234  if (p->pwlindex >= p->numtrancoeffs) break;
235  }
236  }
237  for (;;) {
238  if (*t < *(p->trancoeffs+p->pwlindex) && p->pwlindex)
239  p->pwlindex -= 2;
240  else break;
241  }
242  if (!p->pwlindex && *t <= *(p->trancoeffs)) {
243  return (*(p->trancoeffs+1));
244  }
245  if (p->pwlindex >= p->numtrancoeffs) {
246  return (*(p->trancoeffs+p->numtrancoeffs-1));
247  }
248  return ( *(p->trancoeffs+p->pwlindex+1) +
249  *(p->trancache + (p->pwlindex >> 1)) *
250  (*t - *(p->trancoeffs+p->pwlindex)) );
251 }
double * trancoeffs
Definition: inpptree.h:55
int numtrancoeffs
Definition: inpptree.h:58
double * trancache
Definition: inpptree.h:57
Definition: cddefs.h:192
int pwlindex
Definition: inpptree.h:59
static double PTtSffm ( )
static
static double PTtSffm ( INPparseNode p,
double *  t 
)
static

Definition at line 305 of file ptfuncs.c.

309 {
310  return (VO + VA*sin((2*M_PI * FC * *t) +
311  MDI * sin(2*M_PI * FS * *t)));
312 }
#define MDI
Definition: ptfuncs.c:165
#define VA
Definition: ptfuncs.c:154
#define M_PI
Definition: spice.h:132
#define VO
Definition: ptfuncs.c:153
double sin()
#define FC
Definition: ptfuncs.c:164
#define FS
Definition: ptfuncs.c:166
Definition: cddefs.h:192
static double PTtSin ( )
static
static double PTtSin ( INPparseNode p,
double *  t 
)
static

Definition at line 255 of file ptfuncs.c.

259 {
260  double time, value;
261 
262  time = *t - TDL;
263  if (time <= 0)
264  return (VO);
265  return (VO + VA*sin(FREQ * time * 2*M_PI)*exp(-time*THETA));
266 }
#define TDL
Definition: ptfuncs.c:156
#define VA
Definition: ptfuncs.c:154
#define M_PI
Definition: spice.h:132
#define THETA
Definition: ptfuncs.c:157
#define FREQ
Definition: ptfuncs.c:155
#define VO
Definition: ptfuncs.c:153
double sin()
Definition: cddefs.h:192
static double PTtSpulse ( )
static
static double PTtSpulse ( INPparseNode p,
double *  t 
)
static

Definition at line 270 of file ptfuncs.c.

274 {
275  double time;
276 
277  time = *t - SDEL;
278  if (time <= 0)
279  return (V1);
280  return (V1 +
281  (V2-V1)*( 1 - cos(2*M_PI*time/SPER)*exp(-time*THETA) )/2);
282 }
#define V2
Definition: ptfuncs.c:143
#define M_PI
Definition: spice.h:132
#define V1
Definition: ptfuncs.c:142
#define THETA
Definition: ptfuncs.c:157
#define SPER
Definition: ptfuncs.c:150
double cos()
#define SDEL
Definition: ptfuncs.c:151
Definition: cddefs.h:192
static double PTuminus ( )
static
static double PTuminus ( double  arg)
static

Definition at line 505 of file ptfuncs.c.

508 { return (- arg); }

Variable Documentation

double PTfudge_factor

Definition at line 90 of file ptfuncs.c.

struct sPTfunc PTfuncs[]
Initial value:
= {
{ "abs", PTF_ABS, PTabs } ,
{ "acos", PTF_ACOS, PTacos } ,
{ "asin", PTF_ASIN, PTasin } ,
{ "atan", PTF_ATAN, PTatan } ,
{ "cos", PTF_COS, PTcos } ,
{ "cosh", PTF_COSH, PTcosh } ,
{ "exp", PTF_EXP, PTexp } ,
{ "ln", PTF_LN, PTln } ,
{ "log", PTF_LOG, PTlog } ,
{ "sgn", PTF_SGN, PTsgn } ,
{ "sin", PTF_SIN, PTsin } ,
{ "sinh", PTF_SINH, PTsinh } ,
{ "sqrt", PTF_SQRT, PTsqrt } ,
{ "tan", PTF_TAN, PTtan } ,
{ "tanh", PTF_TANH, PTtanh } ,
{ "-", PTF_UMINUS, PTuminus },
{ NULL, 0, (double(*)())NULL }
}
#define PTF_SQRT
Definition: inpptree.h:97
static double PTexp()
#define PTF_ACOS
Definition: inpptree.h:84
#define PTF_COS
Definition: inpptree.h:90
static double PTsin()
#define PTF_TANH
Definition: inpptree.h:99
#define PTF_COSH
Definition: inpptree.h:91
static double PTabs()
static double PTtanh()
static double PTatan()
#define PTF_EXP
Definition: inpptree.h:92
static double PTln()
#define PTF_SIN
Definition: inpptree.h:95
static double PTsinh()
static double PTtan()
#define NULL
Definition: spdefs.h:121
static double PTcosh()
static double PTasin()
static double PTuminus()
#define PTF_UMINUS
Definition: inpptree.h:100
#define PTF_ASIN
Definition: inpptree.h:86
static double PTsgn()
static double PTsqrt()
#define PTF_LN
Definition: inpptree.h:93
static double PTacos()
#define PTF_ABS
Definition: inpptree.h:101
#define PTF_LOG
Definition: inpptree.h:94
static double PTlog()
#define PTF_SINH
Definition: inpptree.h:96
#define PTF_ATAN
Definition: inpptree.h:88
#define PTF_SGN
Definition: inpptree.h:102
#define PTF_TAN
Definition: inpptree.h:98
static double PTcos()

Definition at line 107 of file ptfuncs.c.

struct sPTop PTops[]
Initial value:
= {
{ PT_COMMA, ",", NULL } ,
{ PT_PLUS, "+", PTplus } ,
{ PT_MINUS, "-", PTminus } ,
{ PT_TIMES, "*", PTtimes } ,
{ PT_DIVIDE, "/", PTdivide },
{ PT_POWER, "^", PTpower },
{ PT_PLACEHOLDER, NULL, (double(*)())NULL }
}
#define PT_DIVIDE
Definition: inpptree.h:72
#define PT_PLACEHOLDER
Definition: inpptree.h:68
#define NULL
Definition: spdefs.h:121
static double PTpower()
#define PT_PLUS
Definition: inpptree.h:69
#define PT_MINUS
Definition: inpptree.h:70
#define PT_COMMA
Definition: inpptree.h:78
static double PTdivide()
static double PTtimes()
#define PT_POWER
Definition: inpptree.h:73
static double PTplus()
#define PT_TIMES
Definition: inpptree.h:71
static double PTminus()

Definition at line 97 of file ptfuncs.c.

struct sPTfunc PTtFuncs[]
Initial value:
= {
{ "pulse", PTF_tPULSE, PTtPulse } ,
{ "pwl", PTF_tPWL, PTtPwl } ,
{ "sin", PTF_tSIN, PTtSin } ,
{ "spulse", PTF_tSPULSE,PTtSpulse } ,
{ "exp", PTF_tEXP, PTtExp } ,
{ "sffm", PTF_tSFFM, PTtSffm } ,
{ NULL, 0, (double(*)())NULL }
}
static double PTtPulse()
#define PTF_tPULSE
Definition: inpptree.h:106
#define PTF_tSIN
Definition: inpptree.h:108
#define PTF_tSFFM
Definition: inpptree.h:111
static double PTtSin()
static double PTtExp()
static double PTtPwl()
#define NULL
Definition: spdefs.h:121
static double PTtSpulse()
static double PTtSffm()
#define PTF_tPWL
Definition: inpptree.h:107
#define PTF_tEXP
Definition: inpptree.h:110
#define PTF_tSPULSE
Definition: inpptree.h:109

Definition at line 132 of file ptfuncs.c.