Jspice3
swask.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: 1987 Thomas L. Quarles
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * This routine gives access to the internal device parameters
10  * of voltage controlled SWitch
11  */
12 
13 #include "spice.h"
14 #include <stdio.h>
15 #include "swdefs.h"
16 #include "tskdefs.h"
17 #include "sperror.h"
18 #include "util.h"
19 
20 
21 /* ARGSUSED */
22 int
23 SWask(ckt,inst,which,value,select)
24 
25 CKTcircuit *ckt;
26 GENinstance *inst;
27 int which;
28 IFvalue *value;
29 IFvalue *select;
30 {
31  SWinstance *here = (SWinstance *)inst;
32  static char *msg = "Current and power not available in ac analysis";
33 
34  switch (which) {
35 
36  case SW_POS_NODE:
37  value->iValue = here->SWposNode;
38  break;
39  case SW_NEG_NODE:
40  value->iValue = here->SWnegNode;
41  break;
42  case SW_CONTROL:
43  value->uValue = here->SWcontName;
44  break;
45  case SW_POS_CONT_NODE:
46  value->iValue = here->SWposCntrlNode;
47  break;
48  case SW_NEG_CONT_NODE:
49  value->iValue = here->SWnegCntrlNode;
50  break;
51  case SW_CURRENT:
52  if (ckt->CKTcurrentAnalysis & DOING_AC) {
53  errMsg = MALLOC(strlen(msg)+1);
54  errRtn = "SWask";
55  strcpy(errMsg,msg);
56  return (E_ASKCURRENT);
57  }
58  if (ckt->CKTrhsOld) {
59  value->rValue = (*(ckt->CKTrhsOld + here->SWposNode)
60  - *(ckt->CKTrhsOld + here->SWnegNode)) *
61  here->SWcond;
62  }
63  break;
64  case SW_POWER:
65  if (ckt->CKTcurrentAnalysis & DOING_AC) {
66  errMsg = MALLOC(strlen(msg)+1);
67  errRtn = "SWask";
68  strcpy(errMsg,msg);
69  return (E_ASKPOWER);
70  }
71  if (ckt->CKTrhsOld) {
72  value->rValue = (*(ckt->CKTrhsOld + here->SWposNode)
73  - *(ckt->CKTrhsOld + here->SWnegNode)) *
74  (*(ckt->CKTrhsOld + here->SWposNode)
75  - *(ckt->CKTrhsOld + here->SWnegNode)) *
76  here->SWcond;
77  }
78  break;
79  default:
80  return (E_BADPARM);
81  }
82  return (OK);
83 }
#define E_ASKCURRENT
Definition: sperror.h:26
IFuid SWcontName
Definition: swdefs.h:30
#define SW_POS_CONT_NODE
Definition: swdefs.h:90
int SWask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value, IFvalue *select)
Definition: swask.c:23
char * strcpy()
char * errMsg
Definition: main.c:42
#define E_BADPARM
Definition: iferrmsg.h:26
int SWnegNode
Definition: swdefs.h:26
int iValue
Definition: ifsim.h:232
double rValue
Definition: ifsim.h:233
int SWposCntrlNode
Definition: swdefs.h:27
#define DOING_AC
Definition: tskdefs.h:24
#define OK
Definition: iferrmsg.h:17
int SWnegCntrlNode
Definition: swdefs.h:28
#define MALLOC(x)
Definition: util.h:9
#define SW_NEG_NODE
Definition: swdefs.h:89
#define SW_POS_NODE
Definition: swdefs.h:88
#define SW_CURRENT
Definition: swdefs.h:93
char * errRtn
Definition: main.c:41
#define SW_CONTROL
Definition: swdefs.h:92
#define E_ASKPOWER
Definition: sperror.h:27
int SWposNode
Definition: swdefs.h:25
double SWcond
Definition: swdefs.h:41
#define SW_POWER
Definition: swdefs.h:94
#define SW_NEG_CONT_NODE
Definition: swdefs.h:91
IFuid uValue
Definition: ifsim.h:236