Jspice3
mutual.c File Reference
#include "spice.h"
#include "sced.h"
#include "scedmacs.h"
Include dependency graph for mutual.c:

Go to the source code of this file.

Functions

static int mut_kb ()
 
static int add_mutual ()
 
static struct oselect_inductor ()
 
static struct oget_mut ()
 
void ShowMutual (int *LookedAhead)
 
static int mut_kb (struct prpty *PDesc, struct o *Pointer1, struct o *Pointer2, int *LookedAhead)
 
static int add_mutual (int *LookedAhead)
 
static struct oselect_inductor (long X, long Y, struct s *CellDesc)
 
static struct oget_mut (long X, long Y, struct s *CellDesc)
 
struct linePrintMutual (struct s *CellDesc)
 
char * GetName (struct prpty *PDesc)
 

Variables

char * MenuMUTUL
 

Function Documentation

static int add_mutual ( )
static
static int add_mutual ( int *  LookedAhead)
static

Definition at line 139 of file mutual.c.

143 {
144  struct o *Pointer1,*Pointer2;
145  struct prpty *PDesc;
146  char value[32],*TypeIn;
147  double kv;
148  int ret = True;
149 
150 top:
151  ShowPrompt("Point to first coupled inductor.");
152  loop {
153  switch (PointLoop(LookedAhead)) {
154  case PL_UND:
155  case PL_CMD:
156  case PL_ESC:
157  ret = False;
158  goto quit;
159  case PL_PCW:
160  if ((Pointer1 =
162  Parameters.kpCellDesc)) != NULL) {
163  ShowCurrentObject(Pointer1,DISPLAY);
164  break;
165  }
166  continue;
167  }
168  break;
169  }
170 
171  ShowPrompt("Point to second coupled inductor.");
172  loop {
173  switch (PointLoop(LookedAhead)) {
174  case PL_UND:
175  goto top;
176  case PL_ESC:
177  case PL_CMD:
178  ret = False;
179  goto quit;
180  case PL_PCW:
181  if ((Pointer2 =
183  Parameters.kpCellDesc)) != NULL &&
184  Pointer2 != Pointer1) {
185  ShowCurrentObject(Pointer2,DISPLAY);
186  break;
187  }
188  continue;
189  }
190  break;
191  }
192 
193  do {
194  ShowPrompt("Enter SPICE coupling factor: k = ");
195  if ((TypeIn = FBEdit(NULL)) == NULL) {
196  ret = False;
197  goto quit;
198  }
199  strcpy(value,TypeIn);
200  }
201  while (sscanf(value,"%le",&kv) < 1 || kv < 0 || kv > 1);
202 
203  /* see if this mutual already exists */
205  for (; PDesc; PDesc = PDesc->prpty_Succ) {
206  if (PDesc->prpty_Value != P_MUT) continue;
207  if ((Pointer1->oLeft == PDesc->prpty_Data->p_mut.x1 &&
208  Pointer1->oBottom == PDesc->prpty_Data->p_mut.y1 &&
209  Pointer2->oLeft == PDesc->prpty_Data->p_mut.x2 &&
210  Pointer2->oBottom == PDesc->prpty_Data->p_mut.y2) ||
211  (Pointer2->oLeft == PDesc->prpty_Data->p_mut.x1 &&
212  Pointer2->oBottom == PDesc->prpty_Data->p_mut.y1 &&
213  Pointer1->oLeft == PDesc->prpty_Data->p_mut.x2 &&
214  Pointer1->oBottom == PDesc->prpty_Data->p_mut.y2)) {
215  PDesc->prpty_Data->p_mut.coeff = kv;
216  ShowPromptAndWait("Existing mutual inductor updated");
217  goto quit;
218  }
219  }
220 
221  sprintf(TypeOut,"%ld %ld %ld %ld %s",
222  Pointer1->oLeft,Pointer1->oBottom,
223  Pointer2->oLeft,Pointer2->oBottom,
224  value);
226 
227 quit:
228  ShowCurrentObject((struct o *)NULL,ERASE);
229  return (ret);
230 }
struct prpty * sPrptyList
Definition: cddefs.h:133
#define PL_ESC
Definition: sced.h:62
#define loop
Definition: cdmacs.h:11
int prpty_Value
Definition: cdprpty.h:67
long kcRawY
Definition: sced.h:103
#define PL_UND
Definition: sced.h:63
long kcRawX
Definition: sced.h:103
char * strcpy()
int PointLoop()
struct kc SCursor
Definition: init.c:21
void ShowCurrentObject()
#define ERASE
Definition: scedmacs.h:11
struct s * kpCellDesc
Definition: sced.h:207
int x1
Definition: cdprpty.h:31
#define PL_PCW
Definition: sced.h:65
void ShowPromptAndWait()
union prp_data * prpty_Data
Definition: cdprpty.h:65
long oBottom
Definition: cddefs.h:143
Definition: sced.h:146
int CDAddProperty()
#define NULL
Definition: spdefs.h:121
char TypeOut[200]
Definition: init.c:23
struct kp Parameters
Definition: init.c:19
int y1
Definition: cdprpty.h:32
#define True
Definition: scedstub.c:16
static struct o * select_inductor()
int y2
Definition: cdprpty.h:34
#define DISPLAY
Definition: scedmacs.h:12
Definition: cddefs.h:142
#define P_MUT
Definition: cdprpty.h:14
struct prpty * prpty_Succ
Definition: cdprpty.h:66
long oLeft
Definition: cddefs.h:143
char * FBEdit()
double coeff
Definition: cdprpty.h:35
#define False
Definition: scedstub.c:15
#define PL_CMD
Definition: sced.h:64
int x2
Definition: cdprpty.h:33
struct prp_mut p_mut
Definition: cdprpty.h:53
Definition: cdprpty.h:62
void ShowPrompt(char *str)
Definition: scedstub.c:71
static struct o* get_mut ( )
static
static struct o* get_mut ( long  X,
long  Y,
struct s CellDesc 
)
static

Definition at line 262 of file mutual.c.

267 {
268  struct g *GenDesc;
269  struct o *Pointer;
270  char *name;
271 
272  if (Not CDInitGen(CellDesc,0,
273  X+100,Y+100,X+100,Y+100,&GenDesc)) MallocFailed();
274 
275  loop {
276  CDGen(CellDesc,GenDesc,&Pointer);
277  if (Pointer == NULL) break;
278  if (Pointer->oInfo == SQ_GONE) continue;
279 
280  name = ((struct c *)Pointer->oRep)->cMaster->mName;
281  if (!cieq(name,"ind")) continue;
282  if (X == Pointer->oLeft && Y == Pointer->oBottom) {
283  tfree(GenDesc);
284  return (Pointer);
285  }
286  }
287  return (NULL);
288 }
#define loop
Definition: cdmacs.h:11
int struct o * Pointer
Definition: cd.c:1311
#define SQ_GONE
Definition: sced.h:347
int cieq()
#define Not
Definition: cdmacs.h:16
void CDGen()
void MallocFailed()
Definition: scedintr.c:857
long oBottom
Definition: cddefs.h:143
long X
Definition: actions.c:450
#define tfree(x)
Definition: cdmacs.h:22
int CDInitGen()
#define NULL
Definition: spdefs.h:121
struct o * oRep
Definition: cddefs.h:144
Definition: cddefs.h:142
Definition: cddefs.h:177
long oLeft
Definition: cddefs.h:143
Definition: cddefs.h:227
long Y
Definition: actions.c:450
short oInfo
Definition: cddefs.h:147
char* GetName ( struct prpty PDesc)

Definition at line 333 of file mutual.c.

337 {
338  static char nbuf[8];
339 
340  for (; PDesc; PDesc = PDesc->prpty_Succ) {
341  if (PDesc->prpty_Value != P_NAME) continue;
342  sprintf(nbuf,"%s%d",PDesc->prpty_Data->p_name.name,
343  PDesc->prpty_Data->p_name.num);
344  return (nbuf);
345  }
346  return (NULL);
347 }
int prpty_Value
Definition: cdprpty.h:67
union prp_data * prpty_Data
Definition: cdprpty.h:65
#define NULL
Definition: spdefs.h:121
#define P_NAME
Definition: cdprpty.h:13
int num
Definition: cdprpty.h:47
struct prpty * prpty_Succ
Definition: cdprpty.h:66
char * name
Definition: cdprpty.h:46
struct prp_name p_name
Definition: cdprpty.h:55
static int mut_kb ( )
static
static int mut_kb ( struct prpty PDesc,
struct o Pointer1,
struct o Pointer2,
int *  LookedAhead 
)
static

Definition at line 93 of file mutual.c.

99 {
100  struct prpty *pd;
101  char InChar;
102 
103  InChar = FBGetchar(DISPLAY);
104 
105  if (Pointer1 != NULL)
106  ShowCurrentObject(Pointer1,ERASE);
107  if (Pointer2 != NULL)
108  ShowCurrentObject(Pointer2,ERASE);
109 
110  if (InChar == ESCAPE)
111  return (-1);
112  if (InChar == '\0' || InChar == '\n' || InChar == '\r')
113  return (0);
114  if (InChar == 'a' || InChar == 'A')
115  return (add_mutual(LookedAhead));
116  if (InChar == 'd' || InChar == 'D') {
117  if (PDesc == NULL) {
118  ShowPromptAndWait("No mutual inductor to delete.");
119  return (0);
120  }
122  if (pd == PDesc)
124  else {
125  /* must be in the list */
126  for (; pd && pd->prpty_Succ != PDesc; pd = pd->prpty_Succ) ;
127  pd->prpty_Succ = PDesc->prpty_Succ;
128  }
129  free(PDesc->prpty_Data);
130  tfree(PDesc);
132  ShowPromptAndWait("Mutual inductance deleted.");
133  }
134  return (0);
135 }
struct prpty * sPrptyList
Definition: cddefs.h:133
int kpModified
Definition: sced.h:261
static int add_mutual()
void ShowCurrentObject()
#define ERASE
Definition: scedmacs.h:11
struct s * kpCellDesc
Definition: sced.h:207
void ShowPromptAndWait()
union prp_data * prpty_Data
Definition: cdprpty.h:65
#define tfree(x)
Definition: cdmacs.h:22
#define NULL
Definition: spdefs.h:121
struct kp Parameters
Definition: init.c:19
#define True
Definition: scedstub.c:16
short FBGetchar()
#define DISPLAY
Definition: scedmacs.h:12
struct prpty * prpty_Succ
Definition: cdprpty.h:66
#define ESCAPE
Definition: sced.h:91
Definition: cdprpty.h:62
void free()
struct line* PrintMutual ( struct s CellDesc)

Definition at line 292 of file mutual.c.

296 {
297  struct prpty *PDesc,*pd1,*pd2;
298  struct o *Pointer1,*Pointer2;
299  struct line *d,*d0 = NULL;
300  char name1[8],name2[8],value[32];
301  long L1X,L2X,L1Y,L2Y;
302  int count = 0;
303 
304  PDesc = CellDesc->sPrptyList;
305  for (; PDesc; PDesc = PDesc->prpty_Succ) {
306  if (PDesc->prpty_Value != P_MUT) continue;
307  L1X = PDesc->prpty_Data->p_mut.x1;
308  L1Y = PDesc->prpty_Data->p_mut.y1;
309  L2X = PDesc->prpty_Data->p_mut.x2;
310  L2Y = PDesc->prpty_Data->p_mut.y2;
311  Pointer1 = get_mut(L1X,L1Y,CellDesc);
312  Pointer2 = get_mut(L2X,L2Y,CellDesc);
313  if (Pointer1 == NULL || Pointer2 == NULL)
314  continue;
315 
316  strcpy(name1,GetName(Pointer1->oPrptyList));
317  strcpy(name2,GetName(Pointer2->oPrptyList));
318  count++;
319  sprintf(TypeOut,"K%d %s %s %g",count,name1,name2,
320  PDesc->prpty_Data->p_mut.coeff);
321  if (d0 == NULL)
322  d = d0 = AllocateLine(TypeOut);
323  else {
325  d = d->li_next;
326  }
327  }
328  return (d0);
329 }
struct prpty * sPrptyList
Definition: cddefs.h:133
int prpty_Value
Definition: cdprpty.h:67
char * strcpy()
struct line * AllocateLine()
int x1
Definition: cdprpty.h:31
union prp_data * prpty_Data
Definition: cdprpty.h:65
Definition: fteinp.h:14
Definition: cddefs.h:237
#define NULL
Definition: spdefs.h:121
char TypeOut[200]
Definition: init.c:23
int y1
Definition: cdprpty.h:32
int y2
Definition: cdprpty.h:34
struct line * li_next
Definition: fteinp.h:18
Definition: cddefs.h:142
#define P_MUT
Definition: cdprpty.h:14
struct prpty * prpty_Succ
Definition: cdprpty.h:66
int count
Definition: output.c:152
double coeff
Definition: cdprpty.h:35
static struct o * get_mut()
int x2
Definition: cdprpty.h:33
struct prp_mut p_mut
Definition: cdprpty.h:53
Definition: cdprpty.h:62
char * GetName(struct prpty *PDesc)
Definition: mutual.c:333
struct prpty * oPrptyList
Definition: cddefs.h:146
static struct o* select_inductor ( )
static
static struct o* select_inductor ( long  X,
long  Y,
struct s CellDesc 
)
static

Definition at line 234 of file mutual.c.

238 {
239  struct g *GenDesc;
240  struct o *Pointer;
241  char *name;
242 
243  if (Not CDInitGen(CellDesc,0,
244  X,Y,X,Y,&GenDesc)) MallocFailed();
245 
246  loop {
247  CDGen(CellDesc,GenDesc,&Pointer);
248  if (Pointer == NULL) break;
249  if (Pointer->oInfo == SQ_GONE) continue;
250 
251  name = ((struct c *)Pointer->oRep)->cMaster->mName;
252  if (!cieq(name,"ind")) continue;
253  /* folks, we have an inductor */
254  tfree(GenDesc);
255  return (Pointer);
256  }
257  return (NULL);
258 }
#define loop
Definition: cdmacs.h:11
int struct o * Pointer
Definition: cd.c:1311
#define SQ_GONE
Definition: sced.h:347
int cieq()
#define Not
Definition: cdmacs.h:16
void CDGen()
void MallocFailed()
Definition: scedintr.c:857
long X
Definition: actions.c:450
#define tfree(x)
Definition: cdmacs.h:22
int CDInitGen()
#define NULL
Definition: spdefs.h:121
struct o * oRep
Definition: cddefs.h:144
Definition: cddefs.h:142
Definition: cddefs.h:177
Definition: cddefs.h:227
long Y
Definition: actions.c:450
short oInfo
Definition: cddefs.h:147
void ShowMutual ( int *  LookedAhead)

Definition at line 41 of file mutual.c.

45 {
46  struct prpty *PDesc,*PNext;
47  struct o *Pointer1,*Pointer2;
48  char *TypeIn;
49  long L1X,L2X,L1Y,L2Y;
50  int i, mutfound = False;
51 
53 
54 again:
55  for (PDesc = Parameters.kpCellDesc->sPrptyList; PDesc; PDesc = PNext) {
56  PNext = PDesc->prpty_Succ;
57  if (PDesc->prpty_Value != P_MUT) continue;
58  /* Referenced by lower left corner */
59  L1X = PDesc->prpty_Data->p_mut.x1;
60  L1Y = PDesc->prpty_Data->p_mut.y1;
61  L2X = PDesc->prpty_Data->p_mut.x2;
62  L2Y = PDesc->prpty_Data->p_mut.y2;
63  Pointer1 = get_mut(L1X,L1Y,Parameters.kpCellDesc);
64  Pointer2 = get_mut(L2X,L2Y,Parameters.kpCellDesc);
65  if (Pointer1 == NULL || Pointer2 == NULL)
66  continue;
67  mutfound = True;
68  ShowCurrentObject(Pointer1,DISPLAY);
69  ShowCurrentObject(Pointer2,DISPLAY);
70  sprintf(TypeOut,"k = %g (a add, d delete) > ",
71  PDesc->prpty_Data->p_mut.coeff);
73  i = mut_kb(PDesc,Pointer1,Pointer2,LookedAhead);
74  if (i < 0)
75  goto quit;
76  if (i > 0)
77  goto again;
78  }
79  if (mutfound == False) {
80  ShowPrompt(
81  "No mutual inductors found. Enter 'a' to add mutual inductor > ");
82  if (mut_kb(NULL,NULL,NULL,LookedAhead) > 0)
83  goto again;
84  }
85 quit:
86  ShowCurrentObject((struct o *)NULL,ERASE);
88  ErasePrompt();
89 }
struct prpty * sPrptyList
Definition: cddefs.h:133
void ErasePrompt()
Definition: viewport.c:538
int prpty_Value
Definition: cdprpty.h:67
void ShowCurrentObject()
#define ERASE
Definition: scedmacs.h:11
struct s * kpCellDesc
Definition: sced.h:207
int x1
Definition: cdprpty.h:31
union prp_data * prpty_Data
Definition: cdprpty.h:65
char * MenuMUTUL
Definition: scedintr.c:89
void MenuDeselect()
#define NULL
Definition: spdefs.h:121
char TypeOut[200]
Definition: init.c:23
struct kp Parameters
Definition: init.c:19
int y1
Definition: cdprpty.h:32
#define True
Definition: scedstub.c:16
int y2
Definition: cdprpty.h:34
#define DISPLAY
Definition: scedmacs.h:12
Definition: cddefs.h:142
static int mut_kb()
#define P_MUT
Definition: cdprpty.h:14
struct prpty * prpty_Succ
Definition: cdprpty.h:66
double coeff
Definition: cdprpty.h:35
#define False
Definition: scedstub.c:15
static struct o * get_mut()
int x2
Definition: cdprpty.h:33
void MenuSelect()
struct prp_mut p_mut
Definition: cdprpty.h:53
Definition: cdprpty.h:62
void ShowPrompt(char *str)
Definition: scedstub.c:71

Variable Documentation

char* MenuMUTUL

Definition at line 89 of file scedintr.c.