From af31904f99ebdc1a67328db46e1faa91ab5f0633 Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Mon, 18 Dec 2023 18:14:28 +0000 Subject: [PATCH] The previous fix for Bug #467 - ".OPTION INTERP has accuracy issue" (359e3d46) updated variable timeold inside a loop so that all interpolations after the first caused division by zero. That caused the xspice/delta-sigma example to fail. Set the variable once at the end of the function. --- src/frontend/outitf.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/frontend/outitf.c b/src/frontend/outitf.c index b4d6955ac..29d3fb54f 100644 --- a/src/frontend/outitf.c +++ b/src/frontend/outitf.c @@ -1469,21 +1469,18 @@ InterpFileAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) if (run->refIndex != -1) { /* Save first time step */ if (refValue->rValue == run->circuit->CKTinitTime) { - timeold = refValue->rValue; fileStartPoint(run->fp, run->binary, run->pointCount); fileAddRealValue(run->fp, run->binary, run->circuit->CKTinitTime); interpolatenow = nodata = FALSE; } /* Save last time step */ else if (refValue->rValue == run->circuit->CKTfinalTime) { - timeold = refValue->rValue; fileStartPoint(run->fp, run->binary, run->pointCount); fileAddRealValue(run->fp, run->binary, run->circuit->CKTfinalTime); interpolatenow = nodata = FALSE; } /* Save exact point */ else if (refValue->rValue == timestep) { - timeold = refValue->rValue; fileStartPoint(run->fp, run->binary, run->pointCount); fileAddRealValue(run->fp, run->binary, timestep); timestep += run->circuit->CKTstep; @@ -1501,7 +1498,6 @@ InterpFileAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) else { /* Do not save this step */ run->pointCount--; - timeold = refValue->rValue; nodata = TRUE; interpolatenow = FALSE; } @@ -1542,7 +1538,6 @@ InterpFileAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) newval = (timestep - run->circuit->CKTstep - timeold)/(timenew - timeold) * (valuenew[i] - valueold[i]) + valueold[i]; fileAddRealValue(run->fp, run->binary, newval); valueold[i] = valuenew[i]; - timeold = refValue->rValue; } else if (nodata) /* Just keep the transient output value corresponding to timeold, @@ -1574,7 +1569,6 @@ InterpFileAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) newval = (timestep - run->circuit->CKTstep - timeold)/(timenew - timeold) * (valuenew[i] - valueold[i]) + valueold[i]; fileAddRealValue(run->fp, run->binary, newval); valueold[i] = valuenew[i]; - timeold = refValue->rValue; } else if (nodata) /* Just keep the transient output value corresponding to timeold, @@ -1587,7 +1581,7 @@ InterpFileAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) #endif } - + timeold = refValue->rValue; fileEndPoint(run->fp, run->binary); /* Check that the write to disk completed successfully, otherwise abort */ @@ -1634,19 +1628,16 @@ InterpPlotAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) /* Save first time step */ if (refValue->rValue == run->circuit->CKTinitTime) { - timeold = refValue->rValue; plotAddRealValue(&run->data[iscale], refValue->rValue); interpolatenow = nodata = FALSE; } /* Save last time step */ else if (refValue->rValue == run->circuit->CKTfinalTime) { - timeold = refValue->rValue; plotAddRealValue(&run->data[iscale], run->circuit->CKTfinalTime); interpolatenow = nodata = FALSE; } /* Save exact point */ else if (refValue->rValue == timestep) { - timeold = refValue->rValue; plotAddRealValue(&run->data[iscale], timestep); timestep += run->circuit->CKTstep; interpolatenow = nodata = FALSE; @@ -1662,7 +1653,6 @@ InterpPlotAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) else { /* Do not save this step */ run->pointCount--; - timeold = refValue->rValue; nodata = TRUE; interpolatenow = FALSE; } @@ -1707,7 +1697,6 @@ InterpPlotAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) newval = (timestep - run->circuit->CKTstep - timeold)/(timenew - timeold) * (valuenew[i] - valueold[i]) + valueold[i]; plotAddRealValue(&run->data[i], newval); valueold[i] = valuenew[i]; - timeold = refValue->rValue; } else if (nodata) /* Just keep the transient output value corresponding to timeold, @@ -1730,7 +1719,6 @@ InterpPlotAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) newval = (timestep - run->circuit->CKTstep - timeold)/(timenew - timeold) * (valuenew[i] - valueold[i]) + valueold[i]; plotAddRealValue(&run->data[i], newval); valueold[i] = valuenew[i]; - timeold = refValue->rValue; } else if (nodata) /* Just keep the transient output value corresponding to timeold, @@ -1744,7 +1732,7 @@ InterpPlotAdd(runDesc *run, IFvalue *refValue, IFvalue *valuePtr) #endif } - + timeold = refValue->rValue; gr_iplot(run->runPlot); if (ft_bpcheck(run->runPlot, run->pointCount) == FALSE)