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          1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 #include "spice.h"
9 #include <stdio.h>
10 #include <math.h>
11 #include "capdefs.h"
12 #include "tskdefs.h"
13 #include "sperror.h"
14 #include "util.h"
15 
16 
17 /* ARGSUSED */
18 int
CAPask(ckt,inst,which,value,select)19 CAPask(ckt,inst, which, value, select)
20 
21 CKTcircuit *ckt;
22 GENinstance *inst;
23 int which;
24 IFvalue *value;
25 IFvalue *select;
26 {
27     CAPinstance *here = (CAPinstance *)inst;
28     static char *msg = "Current and power not available for ac analysis";
29 
30     switch (which) {
31 
32         case CAP_CAP:
33             value->rValue = here->CAPcapac;
34             break;
35         case CAP_IC:
36             value->rValue = here->CAPinitCond;
37             break;
38         case CAP_WIDTH:
39             value->rValue = here->CAPwidth;
40             break;
41         case CAP_LENGTH:
42             value->rValue = here->CAPlength;
43             break;
44         case CAP_CURRENT:
45             if (ckt->CKTcurrentAnalysis & DOING_AC) {
46                 errMsg = MALLOC(strlen(msg)+1);
47                 errRtn = "CAPask";
48                 strcpy(errMsg,msg);
49                 return (E_ASKCURRENT);
50             }
51             if (ckt->CKTcurrentAnalysis & DOING_TRAN) {
52                 if (!(ckt->CKTmode & MODETRANOP)) {
53                     if (ckt->CKTstate0)
54                         value->rValue = *(ckt->CKTstate0 + here->CAPccap);
55                 }
56             }
57             break;
58         case CAP_POWER:
59             if (ckt->CKTcurrentAnalysis & DOING_AC) {
60                 errMsg = MALLOC(strlen(msg)+1);
61                 errRtn = "CAPask";
62                 strcpy(errMsg,msg);
63                 return (E_ASKPOWER);
64             }
65             if (ckt->CKTcurrentAnalysis & DOING_TRAN) {
66                 if (!(ckt->CKTmode & MODETRANOP)) {
67                     if (ckt->CKTstate0 && ckt->CKTrhsOld)
68                         value->rValue = *(ckt->CKTstate0 + here->CAPccap) *
69                             (*(ckt->CKTrhsOld + here->CAPposNode) -
70                             *(ckt->CKTrhsOld + here->CAPnegNode));
71                 }
72             }
73             break;
74         default:
75             return (E_BADPARM);
76     }
77     return (OK);
78 }
79 
80