Formatting cktpzstr.c

This commit is contained in:
Holger Vogt 2023-09-11 14:28:49 +02:00
parent dfeb0bdb4e
commit b7993bb530
1 changed files with 762 additions and 713 deletions

View File

@ -167,18 +167,22 @@ CKTpzFindZeros(CKTcircuit *ckt, PZtrial **rootinfo, int *rootcount)
if (CKTpzVerify(neighborhood, new_trial)) {
NIter = 0;
CKTpzReset(neighborhood);
} else
}
else
/* XXX Verify fails ?!? */
CKTpzUpdateSet(neighborhood, new_trial);
} else if (new_trial->flags & ISANABERRATION) {
}
else if (new_trial->flags & ISANABERRATION) {
CKTpzReset(neighborhood);
Aberr_Num += 1;
tfree(new_trial);
} else if (new_trial->flags & ISAMINIMA) {
}
else if (new_trial->flags & ISAMINIMA) {
neighborhood[0] = NULL;
neighborhood[1] = new_trial;
neighborhood[2] = NULL;
} else {
}
else {
CKTpzUpdateSet(neighborhood, new_trial); /* Replace a value */
}
@ -207,7 +211,8 @@ CKTpzFindZeros(CKTcircuit *ckt, PZtrial **rootinfo, int *rootcount)
*rootinfo = NULL;
*rootcount = 0;
MERROR(E_SHORT, "The input signal is shorted on the way to the output");
} else
}
else
clear_trials(0);
*rootinfo = Trials;
@ -248,7 +253,8 @@ PZeval(int strat, PZtrial **set, PZtrial **new_trial_p)
Guess_Param = High_Guess * 10.0;
else
Guess_Param = 1.0;
} else {
}
else {
if (Low_Guess < 0.0)
Guess_Param = Low_Guess * 10.0;
else
@ -281,7 +287,8 @@ PZeval(int strat, PZtrial **set, PZtrial **new_trial_p)
#endif
new_trial->s.real = (set[0]->s.real + set[1]->s.real) / 2.0;
}
} else if (CKTpzTrapped == 2) {
}
else if (CKTpzTrapped == 2) {
if (new_trial->s.real < set[1]->s.real
|| new_trial->s.real > set[2]->s.real) {
#ifdef PZDEBUG
@ -292,7 +299,8 @@ PZeval(int strat, PZtrial **set, PZtrial **new_trial_p)
#endif
new_trial->s.real = (set[1]->s.real + set[2]->s.real) / 2.0;
}
} else if (CKTpzTrapped == 3) {
}
else if (CKTpzTrapped == 3) {
if (new_trial->s.real <= set[0]->s.real
|| (new_trial->s.real == set[1]->s.real
&& new_trial->s.imag == set[1]->s.imag)
@ -348,7 +356,8 @@ PZeval(int strat, PZtrial **set, PZtrial **new_trial_p)
NIpzK_mag += 1;
}
new_trial->s.imag = NIpzK;
} else
}
else
new_trial->s.imag = 10000.0;
/*
@ -364,7 +373,8 @@ PZeval(int strat, PZtrial **set, PZtrial **new_trial_p)
if (!set[2]) {
new_trial->s.real = set[0]->s.real;
new_trial->s.imag = 1.0e8;
} else {
}
else {
new_trial->s.real = set[0]->s.real;
new_trial->s.imag = 1.0e12;
}
@ -410,23 +420,28 @@ int CKTpzStrat(PZtrial **set)
if (set[1] && (set[1]->flags & ISAMINIMA)) {
suggestion = COMPLEX_INIT;
} else if (set[0] && set[0]->s.imag != 0.0) {
}
else if (set[0] && set[0]->s.imag != 0.0) {
if (!set[1] || !set[2])
suggestion = COMPLEX_GUESS;
else
suggestion = MULLER;
} else if (!set[0] || !set[1] || !set[2]) {
}
else if (!set[0] || !set[1] || !set[2]) {
suggestion = INIT;
} else {
}
else {
if (sgn(set[0]->f_def.real) != sgn(set[1]->f_def.real)) {
/* Zero crossing between s[0] and s[1] */
new_trap = 1;
suggestion = SYM2;
} else if (sgn(set[1]->f_def.real) != sgn(set[2]->f_def.real)) {
}
else if (sgn(set[1]->f_def.real) != sgn(set[2]->f_def.real)) {
/* Zero crossing between s[1] and s[2] */
new_trap = 2;
suggestion = SYM2;
} else {
}
else {
zaddeq(&a, &a_mag, set[1]->f_def.real, set[1]->mag_def,
-set[0]->f_def.real, set[0]->mag_def);
@ -445,7 +460,8 @@ int CKTpzStrat(PZtrial **set)
suggestion = SKIP_RIGHT;
else
suggestion = SKIP_LEFT;
} else if (sgn(a) != -sgn(b)) {
}
else if (sgn(a) != -sgn(b)) {
if (a == 0.0)
suggestion = SKIP_LEFT;
else if (b == 0.0)
@ -454,23 +470,27 @@ int CKTpzStrat(PZtrial **set)
suggestion = SHIFT_LEFT;
else
suggestion = SHIFT_RIGHT;
} else if (sgn(a) == -sgn(set[1]->f_def.real)) {
}
else if (sgn(a) == -sgn(set[1]->f_def.real)) {
new_trap = 3;
/* minima in magnitude above the x axis */
/* Search for exact mag. minima, look for complex pair */
suggestion = SYM;
} else if (k1 > k2)
}
else if (k1 > k2)
suggestion = SKIP_RIGHT;
else
suggestion = SKIP_LEFT;
} else {
}
else {
new_trap = 3; /* still */
/* XXX ? Are these tests needed or is SYM safe all the time? */
if (sgn(a) != sgn(b)) {
/* minima in magnitude */
/* Search for exact mag. minima, look for complex pair */
suggestion = SYM;
} else if (a_mag > b_mag || (a_mag == b_mag
}
else if (a_mag > b_mag || (a_mag == b_mag
&& fabs(a) > fabs(b)))
suggestion = SPLIT_LEFT;
else
@ -554,7 +574,8 @@ CKTpzRunTrial(CKTcircuit *ckt, PZtrial **new_trialp, PZtrial **set)
if (p->flags & ISAROOT) {
abstol = 1e-5;
reltol = 1e-6;
} else {
}
else {
abstol = 1e-20;
reltol = 1e-12;
}
@ -577,13 +598,15 @@ CKTpzRunTrial(CKTcircuit *ckt, PZtrial **new_trialp, PZtrial **set)
p->count = 0;
pretest = 1;
break;
} else
}
else
p->count += 1; /* try to shift */
shifted = 1; /* Re-calculate deflation */
break;
} else {
}
else {
if (!CKTpzTrapped)
p->count = 0;
if (p->flags & ISAROOT) {
@ -600,7 +623,8 @@ CKTpzRunTrial(CKTcircuit *ckt, PZtrial **new_trialp, PZtrial **set)
def_mag += diff_mag;
C_NORM(def_frac, def_mag);
}
} else if (!match)
}
else if (!match)
match = p;
}
}
@ -636,7 +660,8 @@ CKTpzRunTrial(CKTcircuit *ckt, PZtrial **new_trialp, PZtrial **set)
tfree(new_trial);
*new_trialp = p;
repeat = 1;
} else if (p->flags & ISAROOT) {
}
else if (p->flags & ISAROOT) {
#ifdef PZDEBUG
DEBUG(1) fprintf(stderr, "Repeat at %.30g %.30g\n",
p->s.real, p->s.imag);
@ -645,7 +670,8 @@ CKTpzRunTrial(CKTcircuit *ckt, PZtrial **new_trialp, PZtrial **set)
p->flags |= ISAREPEAT;
p->multiplicity += 1;
repeat = 1;
} else {
}
else {
/* Regular zero, as precise as we can get it */
error = E_SINGULAR;
}
@ -670,7 +696,8 @@ CKTpzRunTrial(CKTcircuit *ckt, PZtrial **new_trialp, PZtrial **set)
DEBUG(1) printf("Needs reordering\n");
#endif
ckt->CKTniState |= NIPZSHOULDREORDER;
} else if (error != OK)
}
else if (error != OK)
return error;
}
if (ckt->CKTniState & NIPZSHOULDREORDER) {
@ -703,7 +730,8 @@ CKTpzRunTrial(CKTcircuit *ckt, PZtrial **new_trialp, PZtrial **set)
new_trial->mag_def = 0;
new_trial->flags = ISAROOT;
/*printf("SMP Det: Singular\n");*/
} else if (error != OK)
}
else if (error != OK)
return error;
else {
@ -731,7 +759,8 @@ CKTpzRunTrial(CKTcircuit *ckt, PZtrial **new_trialp, PZtrial **set)
if (prev->next)
prev->next->prev = new_trial;
prev->next = new_trial;
} else {
}
else {
if (Trials)
Trials->prev = new_trial;
else
@ -833,7 +862,8 @@ CKTpzVerify(PZtrial **set, PZtrial *new_trial)
Trials = t->next;
}
tfree(t);
} else {
}
else {
if (prev)
check_flat(prev, t);
@ -891,7 +921,8 @@ clear_trials(int mode)
next = t->next;
if (mode || !(t->flags & ISAROOT)) {
tfree(t);
} else {
}
else {
if (prev)
prev->next = t;
else
@ -918,20 +949,25 @@ CKTpzUpdateSet(PZtrial **set, PZtrial *new)
set[2] = set[1];
set[1] = set[0];
set[0] = new;
} else if (!set[1])
}
else if (!set[1])
set[1] = new;
else if (!set[2] && new->s.real > set[1]->s.real) {
set[2] = new;
} else if (!set[0]) {
}
else if (!set[0]) {
set[0] = new;
} else if (new->flags & ISAMINIMA) {
}
else if (new->flags & ISAMINIMA) {
set[1] = new;
} else if (new->s.real < set[0]->s.real) {
}
else if (new->s.real < set[0]->s.real) {
set[2] = set[1];
set[1] = set[0];
set[0] = new;
this_move = FAR_LEFT;
} else if (new->s.real < set[1]->s.real) {
}
else if (new->s.real < set[1]->s.real) {
if (!CKTpzTrapped || new->mag_def < set[1]->mag_def
|| (new->mag_def == set[1]->mag_def
&& fabs(new->f_def.real) < fabs(set[1]->f_def.real))) {
@ -939,11 +975,13 @@ CKTpzUpdateSet(PZtrial **set, PZtrial *new)
set[2] = set[1]; /* XXX = set[2]->prev :: possible opt */
set[1] = new;
this_move = MID_LEFT;
} else {
}
else {
set[0] = new;
this_move = NEAR_LEFT;
}
} else if (new->s.real < set[2]->s.real) {
}
else if (new->s.real < set[2]->s.real) {
if (!CKTpzTrapped || new->mag_def < set[1]->mag_def
|| (new->mag_def == set[1]->mag_def
&& fabs(new->f_def.real) < fabs(set[1]->f_def.real))) {
@ -951,11 +989,13 @@ CKTpzUpdateSet(PZtrial **set, PZtrial *new)
set[0] = set[1];
set[1] = new;
this_move = MID_RIGHT;
} else {
}
else {
set[2] = new;
this_move = NEAR_RIGHT;
}
} else {
}
else {
set[0] = set[1];
set[1] = set[2];
set[2] = new;
@ -980,7 +1020,8 @@ zaddeq(double *a, int *amag, double x, int xmag, double y, int ymag)
else
for (xmag -= ymag; xmag > 0; xmag--)
y /= 2.0;
} else {
}
else {
*amag = ymag;
if (ymag > 50 + xmag)
x = 0.0;
@ -1015,7 +1056,8 @@ show_trial(PZtrial *new_trial, char x)
new_trial->f_def.real, new_trial->f_def.imag, new_trial->mag_def);
if (new_trial->flags & ISANABERRATION)
fprintf(stderr, "*** numerical aberration ***\n");
} else {
}
else {
fprintf(stderr, "%c (%3d/---) new_trial = nil\n", x, NIter);
}
}
@ -1053,7 +1095,8 @@ CKTpzStep(int strat, PZtrial **set)
case INIT:
if (!set[1]) {
set[1] = pzseek(ZeroTrial, 0);
} else if (!set[2])
}
else if (!set[2])
set[2] = pzseek(set[1], 1);
else if (!set[0])
set[0] = pzseek(set[1], -1);
@ -1096,7 +1139,8 @@ CKTpzReset(PZtrial **set)
if (set[1] != NULL) {
set[0] = pzseek(set[1], -1);
set[2] = pzseek(set[1], 1);
} else {
}
else {
set[0] = NULL;
set[2] = NULL;
}
@ -1130,11 +1174,13 @@ alter(PZtrial *new, PZtrial *nearto, double abstol, double reltol)
#ifdef PZDEBUG
DEBUG(1) fprintf(stderr, "p1 %g\n", p1);
#endif
} else
}
else
p1 -= 10.0 * (fabs(p1) + 1.0);
p1 /= 2.0;
} else
}
else
p1 = nearto->s.real;
if (CKTpzTrapped != 1) {
@ -1149,11 +1195,13 @@ alter(PZtrial *new, PZtrial *nearto, double abstol, double reltol)
#ifdef PZDEBUG
DEBUG(1) fprintf(stderr, "p2 %g\n", p2);
#endif
} else
}
else
p2 += 10.0 * (fabs(p2) + 1.0);
p2 /= 2.0;
} else
}
else
p2 = nearto->s.real;
if ((nearto->prev &&
@ -1177,7 +1225,8 @@ alter(PZtrial *new, PZtrial *nearto, double abstol, double reltol)
DEBUG(1) fprintf(stderr, "take p1\n");
#endif
new->s.real = p1;
} else {
}
else {
#ifdef PZDEBUG
DEBUG(1) fprintf(stderr, "take p2\n");
#endif