Fixed assorted compiler warnings, memory leaks, etc.

This commit is contained in:
Jim Monte 2020-03-07 23:46:58 -05:00
parent 8d903d8e30
commit 88653fa998
130 changed files with 1886 additions and 1174 deletions

View File

@ -1333,4 +1333,9 @@ else
AC_SUBST([CMPP], ['$(top_builddir)/src/xspice/cmpp/cmpp$(EXEEXT)'])
fi
# See https://github.com/kimwalisch/primesieve/issues/16
# Silence warning: ar: 'u' modifier ignored since 'D' is the default
AC_SUBST(AR_FLAGS, [cr])
AC_OUTPUT

View File

@ -4,18 +4,19 @@ Author: 1991 David A. Gates, U. C. Berkeley CAD Group
Modifed: 2001 Paolo Nenzi
**********/
#include "ngspice/ngspice.h"
#include "ngspice/carddefs.h"
#include "ngspice/cidersupt.h"
#include "ngspice/cktdefs.h"
#include "ngspice/numenum.h"
#include "ngspice/ciderinp.h"
#include "ngspice/cpextern.h"
#include "ngspice/dopdefs.h"
#include "ngspice/meshext.h"
#include "ngspice/ngspice.h"
#include "ngspice/numenum.h"
#include "ngspice/profile.h"
#include "ngspice/gendev.h"
#include "ngspice/sperror.h"
#include "ngspice/suffix.h"
#include "ngspice/cidersupt.h"
#include "ngspice/carddefs.h"
#include "ngspice/ciderinp.h"
/*
@ -234,17 +235,29 @@ DOPsetup(DOPcard *cardList, DOPprofile **profileList, DOPtable **tableList,
break;
case DOP_SUPREM3:
newProfile->type = LOOKUP;
readSupremData( card->DOPinFile, 0, card->DOPimpurityType, tableList );
if (readSupremData( card->DOPinFile, 0, card->DOPimpurityType,
tableList) != 0) {
(void) fprintf(cp_err, "Doping setup failed.\n");
return -1;
}
newProfile->IMPID = ++impurityId;
break;
case DOP_SUPASCII:
newProfile->type = LOOKUP;
readSupremData( card->DOPinFile, 1, card->DOPimpurityType, tableList );
if (readSupremData( card->DOPinFile, 1, card->DOPimpurityType,
tableList) != 0) {
(void) fprintf(cp_err, "Doping setup failed.\n");
return -1;
}
newProfile->IMPID = ++impurityId;
break;
case DOP_ASCII:
newProfile->type = LOOKUP;
readAsciiData( card->DOPinFile, card->DOPimpurityType, tableList );
if (readAsciiData(card->DOPinFile, card->DOPimpurityType,
tableList) != 0) {
(void) fprintf(cp_err, "Doping setup failed.\n");
return -1;
}
newProfile->IMPID = ++impurityId;
break;
default:

View File

@ -40,7 +40,7 @@ NUMDadmittance(ONEdevice *pDevice, double omega, SPcomplex *yd)
int index, i;
double yReal, yImag;
double *solutionReal, *solutionImag;
SPcomplex yAc, cOmega;
SPcomplex yAc_adm, cOmega;
SPcomplex *y;
BOOLEAN SORFailed;
double startTime;
@ -146,13 +146,13 @@ NUMDadmittance(ONEdevice *pDevice, double omega, SPcomplex *yd)
startTime = SPfrontEnd->IFseconds();
pNode = pDevice->elemArray[1]->pLeftNode;
y = computeAdmittance(pNode, FALSE, solutionReal, solutionImag, &cOmega);
CMPLX_ASSIGN_VALUE(yAc, -y->real, -y->imag);
CMPLX_ASSIGN(*yd, yAc);
CMPLX_ASSIGN_VALUE(yAc_adm, -y->real, -y->imag);
CMPLX_ASSIGN(*yd, yAc_adm);
CMPLX_MULT_SELF_SCALAR(*yd, GNorm * pDevice->area);
pDevice->pStats->miscTime[STAT_AC] += SPfrontEnd->IFseconds() - startTime;
return (AcAnalysisMethod);
}
} /* end of function NUMDadmittance */
int

View File

@ -77,6 +77,7 @@ ONEdopingValue(DOPprofile *pProfile, DOPtable *pTable, double x)
} else {
value = pProfile->PEAK_CONC * exp(-argP);
}
break;
case EXP:
argP = ABS(argP);
if (argP > 80.0) {

View File

@ -5,26 +5,36 @@ Author: 1991 David A. Gates, U. C. Berkeley CAD Group
**********/
/* Functions to read SUPREM (Binary or Ascii) & ASCII input files */
#include <errno.h>
#include <string.h>
#include "ngspice/cidersupt.h"
#include "ngspice/cpextern.h"
#include "ngspice/ngspice.h"
#include "ngspice/profile.h"
#include "ngspice/cidersupt.h"
void
readAsciiData( char *fileName, int impType, DOPtable **ppTable )
static void free_profile_data(double **p);
static double **alloc_profile_data(size_t n);
int readAsciiData(const char *fileName, int impType, DOPtable **ppTable)
{
FILE *fpAscii;
int xrc = 0;
FILE *fpAscii = (FILE *) NULL;
int index;
double x, y;
int numPoints;
DOPtable *tmpTable;
double **profileData;
DOPtable *tmpTable = (DOPtable *) NULL;
double **profileData = (double **) NULL;
double sign;
/* Open Input File */
if ((fpAscii = fopen( fileName, "r" )) == NULL) {
perror( fileName );
exit(-1);
(void) fprintf(cp_err, "unable to open SUPREM file \"%s\": %s\n",
fileName, strerror(errno));
xrc = -1;
goto EXITPOINT;
}
/* Get sign of concentrations */
@ -35,31 +45,43 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable )
}
/* read the number of points */
fscanf( fpAscii, "%d", &numPoints );
if (fscanf(fpAscii, "%d", &numPoints) != 1) {
(void) fprintf(cp_err, "unable to read point count "
"from SUPREM file \"%s\"\n",
fileName);
xrc = -1;
goto EXITPOINT;
}
/* allocate 2-D array to read in data of x-coordinate and N(x) */
XCALLOC( profileData, double *, 2 );
for( index = 0; index <= 1; index++ ) {
XCALLOC( profileData[ index ], double, 1 + numPoints );
}
profileData = alloc_profile_data((size_t) numPoints + 1);
/* the number of points is stored as profileData[0][0] */
profileData[0][0] = numPoints;
for( index = 1; index <= numPoints; index++ ) {
fscanf( fpAscii, "%lf %lf ", &x, &y );
profileData[ 0 ][ index ] = x;
profileData[ 1 ][ index ] = sign * ABS(y);
}
for (index = 1; index <= numPoints; index++ ) {
if (fscanf(fpAscii, "%lf %lf ", &x, &y) != 2) {
(void) fprintf(cp_err, "unable to read point %d"
"from SUPREM file \"%s\"\n",
index + 1, fileName);
xrc = -1;
goto EXITPOINT;
}
profileData[0][index] = x;
profileData[1][index] = sign * ABS(y);
} /* end of loop over points */
/* Now create a new lookup table */
XCALLOC( tmpTable, DOPtable, 1 );
if ( *ppTable == NULL ) {
XCALLOC(tmpTable, DOPtable, 1);
if (*ppTable == NULL) {
/* First Entry */
tmpTable->impId = 1;
tmpTable->dopData = profileData;
tmpTable->next = NULL;
*ppTable = tmpTable;
} else {
}
else {
tmpTable->impId = (*ppTable)->impId + 1;
tmpTable->dopData = profileData;
tmpTable->next = *ppTable;
@ -72,9 +94,21 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable )
printf("\n %e %e", profileData[ 0 ][ index ], profileData[ 1 ][ index ]);
}
*/
fclose(fpAscii);
return;
}
EXITPOINT:
if (fpAscii != (FILE *) NULL) { /* close data file if open */
fclose(fpAscii);
}
/* Free resources on error */
if (xrc != 0) {
free_profile_data(profileData);
free(tmpTable);
}
return xrc;
} /* end of function readAsciiData */
/* interface routine based on notes provided by Steve Hansen of Stanford */
@ -108,40 +142,45 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable )
*/
void
readSupremData(char *fileName, int fileType, int impType, DOPtable **ppTable)
int readSupremData(const char *fileName, int fileType, int impType,
DOPtable **ppTable)
{
int xrc = 0;
#define MAX_GRID 500
float x[ MAX_GRID ], conc[ MAX_GRID ];
int index;
DOPtable *tmpTable;
double **profileData;
DOPtable *tmpTable = (DOPtable *) NULL;
double **profileData = (double **) NULL;
int numNodes;
/* read the Suprem data file */
if ( fileType == 0 ) { /* BINARY FILE */
SUPbinRead( fileName, x, conc, &impType, &numNodes );
const int rc = SUPbinRead(fileName, x, conc, &impType,
&numNodes);
if (rc != 0) {
(void) fprintf(cp_err, "Data input failed.\n");
xrc = -1;
goto EXITPOINT;
}
}
else {
SUPascRead( fileName, x, conc, &impType, &numNodes );
}
/* allocate 2-D array to read in data of x-coordinate and N(x) */
XCALLOC( profileData, double *, 2 );
for( index = 0; index <= 1; index++ ) {
XCALLOC( profileData[ index ], double, 1 + numNodes );
}
profileData = alloc_profile_data((size_t) numNodes + 1);
/* the number of points is stored as profileData[0][0] */
profileData[0][0] = numNodes;
for( index = 1; index <= numNodes; index++ ) {
profileData[ 0 ][ index ] = x[ index ];
profileData[ 1 ][ index ] = conc[ index ];
profileData[ 0 ][ index ] = x[ index ];
profileData[ 1 ][ index ] = conc[ index ];
}
/* Now create a new lookup table */
XCALLOC( tmpTable, DOPtable, 1 );
XCALLOC(tmpTable, DOPtable, 1);
if ( *ppTable == NULL ) {
/* First Entry */
tmpTable->impId = 1;
@ -161,8 +200,46 @@ readSupremData(char *fileName, int fileType, int impType, DOPtable **ppTable)
printf("%e %e\n", profileData[ 0 ][ index ], profileData[ 1 ][ index ]);
}
*/
return;
}
EXITPOINT:
if (xrc != 0) {
free_profile_data(profileData);
free(tmpTable);
}
return xrc;
} /* end of function readSupremData */
/* Allocate a profile data */
static double **alloc_profile_data(size_t n)
{
double **p;
XCALLOC(p, double *, 2);
XCALLOC(p[0], double, n);
XCALLOC(p[1], double, n);
return p;
} /* end of function alloc_profile_data */
/* Free a profile data */
static void free_profile_data(double **p)
{
/* Immediate exit if no allocation */
if (p == (double **) NULL) {
return;
}
free(p[0]);
free(p[1]);
free(p);
} /* end of function alloc_profile_data */
/* main program to debug readSupremData */

View File

@ -8,25 +8,31 @@ Author: 1991 David A. Gates, U. C. Berkeley CAD Group
* the data is read and stored in two arrays x and conc
*/
#include <errno.h>
#include <string.h>
#include "ngspice/ngspice.h"
#include "ngspice/cidersupt.h"
#include "ngspice/cpextern.h"
#include "ngspice/ngspice.h"
#define MAXMAT 10
#define MAXIMP 4
#define MAXLAYER 10
#define MAXGRID 500
#define GFREAD( fp, ptr, type, num ) if (num && (fread( ptr,\
sizeof(type), (unsigned)num, fp ) != (unsigned)num)) {\
return;\
}
#define GFREAD( fp, ptr, type, num )\
if (num && (fread( ptr, sizeof(type), (size_t) num,\
fp ) != (size_t) num)) {\
xrc = -1;\
goto EXITPOINT;\
}
#define DEBUG if (0)
void
SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod)
int SUPbinRead(const char *inFile, float *x, float *conc, int *impId,
int *numNod)
{
int xrc = 0;
int idata, recordMark;
int ldata;
int i, j;
@ -37,18 +43,20 @@ SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod)
float xStart;
float layerTh[10];
float con[500];
FILE *fpSuprem;
FILE *fpSuprem = (FILE *) NULL;
/* Clear Concentration Array */
for ( i=0; i < MAXGRID; i++ ) {
conc[i] = 0.0;
}
/* Open Input File */
if ((fpSuprem = fopen( inFile, "r" )) == NULL) {
perror(inFile);
return;
}
/* Open Input File */
if ((fpSuprem = fopen( inFile, "r" )) == NULL) {
(void) fprintf(cp_err, "Unable to read file \"%s\": %s.\n",
inFile, strerror(errno));
xrc = -1;
goto EXITPOINT;
}
/*
* The first record contains the number of layers (I4), the number of
@ -199,17 +207,27 @@ SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod)
DEBUG fprintf(stderr," %d\n", ldata );
GFREAD( fpSuprem, &recordMark, int, 1 );
fclose( fpSuprem );
if (fclose(fpSuprem) != 0) {
(void) fprintf(cp_err, "Unable to close file \"%s\": %s.\n",
inFile, strerror(errno));
xrc = -1;
goto EXITPOINT;
}
fpSuprem = (FILE *) NULL;
/* shift silicon layer to beginning of array */
for ( j=numLay; --j >= 0; )
if (matTyp[ j ] == 1)
break;
/* shift silicon layer to beginning of array */
for (j = numLay; --j >= 0; ) {
if (matTyp[j] == 1) {
break;
}
}
if (j < 0) {
(void) fprintf(cp_err, "internal error in %s!\n", __FUNCTION__);
xrc = -1;
goto EXITPOINT;
}
if(j < 0) {
fprintf(stderr, "internal error in %s, bye !\n", __FUNCTION__);
controlled_exit(1);
}
siIndex = j;
@ -223,15 +241,26 @@ SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod)
/* Store number of valid nodes using pointer */
*numNod = numGrid;
return;
}
void
SUPascRead(char *inFile, float *x, float *conc, int *impId, int *numNod)
EXITPOINT:
if (fpSuprem != (FILE *) NULL) {
if (fclose(fpSuprem) != 0) {
(void) fprintf(cp_err, "Unable to close \"%s\" at exit: %s\n",
inFile, strerror(errno));
xrc = -1;
}
}
return xrc;
} /* end of function SUPbinRead */
int SUPascRead(const char *inFile, float *x, float *conc, int *impId,
int *numNod)
{
int idata;
int xrc = 0;
int i, j;
float rdata;
char cdata[21];
int numLay, numImp, numGrid;
int impTyp[4], matTyp[10], topNod[10], siIndex, offset;
@ -245,119 +274,196 @@ SUPascRead(char *inFile, float *x, float *conc, int *impId, int *numNod)
conc[i] = 0.0;
}
/* Open Input File */
if ((fpSuprem = fopen( inFile, "r" )) == NULL) {
perror(inFile);
return;
}
/* Open Input File */
if ((fpSuprem = fopen( inFile, "r" )) == NULL) {
(void) fprintf(cp_err, "Unable to open file \"%s\": %s.\n",
inFile, strerror(errno));
xrc = -1;
goto EXITPOINT;
}
/*
* The first line contains the number of layers (I4), the number of
* impurities (I4), and the number of nodes (I4) present in the structure.
*/
fscanf( fpSuprem, "%d %d %d\n", &numLay, &numImp, &numGrid );
if (fscanf( fpSuprem, "%d %d %d\n", &numLay, &numImp, &numGrid) != 3) {
(void) fprintf(cp_err, "Unable to read file first line of \"%s\"\n",
inFile);
xrc = -1;
goto EXITPOINT;
}
DEBUG fprintf( stderr, "set 1: %d %d %d\n", numLay, numImp, numGrid);
/*
* The second set of lines contains, for each layer, the material name (A20),
* the material type (I4), the layer thickness (R4), and the pointer to
* the top node of the layer (I4), and an unknown int and unknown float.
* The material type code:
* 1 - Si
* 2 - SiO2
* 3 - Poly
* 4 - Si3N4
* 5 - Alum
*/
for ( i=0; i < numLay; i++ ) {
fscanf( fpSuprem, "%s\n %d %e %d %d %e\n",
cdata, &matTyp[i], &layerTh[i], &topNod[i], &idata, &rdata );
DEBUG fprintf(stderr,"set 2: %s: %d %f %d\n",
cdata, matTyp[i], layerTh[i], topNod[i] );
}
/*
* The second set of lines contains, for each layer, the material name
* (A20), the material type (I4), the layer thickness (R4), and the
* pointer to the top node of the layer (I4), and an unknown int and
* unknown float.
*
* The material type code:
* 1 - Si
* 2 - SiO2
* 3 - Poly
* 4 - Si3N4
* 5 - Alum
*/
for (i = 0; i < numLay; ++i) {
int idata;
float rdata;
if (fscanf(fpSuprem, "%s\n %d %e %d %d %e\n",
cdata, &matTyp[i], &layerTh[i], &topNod[i],
&idata, &rdata) != 6) {
(void) fprintf(cp_err, "Unable to read layer %d "
"from file \"%s\".\n",
i + 1, inFile);
xrc = -1;
goto EXITPOINT;
}
/*
* The third set of lines contains, for each impurity, the name of the
* impurity (A20) and the type of impurity (I4).
*/
for ( i=0; i < numImp; i++ ) {
fscanf( fpSuprem, "%s\n %d\n", cdata, &impTyp[i] );
DEBUG fprintf(stderr,"set 3: %s: %d\n", cdata, impTyp[i] );
}
DEBUG fprintf(stderr,"set 2: %s: %d %f %d\n",
cdata, matTyp[i], layerTh[i], topNod[i]);
} /* end of loop over layers */
/*
* The fourth set of lines contains, for each layer by each impurity, the
* integrated dopant (R4), and the interior concentration of the
* polysilicon grains (R4).
*/
for ( j=0; j < numLay; j++ ) {
for ( i=0; i < numImp; i++ ) {
fscanf( fpSuprem, "%e", &rdata );
fscanf( fpSuprem, "%e", &rdata );
/*
* The third set of lines contains, for each impurity, the name of the
* impurity (A20) and the type of impurity (I4).
*/
for (i = 0; i < numImp; ++i) {
if (fscanf( fpSuprem, "%s\n %d\n", cdata, &impTyp[i]) != 2) {
(void) fprintf(cp_err, "Unable to read impurity %d "
"from file \"%s\".\n",
i + 1, inFile);
xrc = -1;
goto EXITPOINT;
}
DEBUG fprintf(stderr,"set 3: %s: %d\n", cdata, impTyp[i]);
} /* end of loop over impurities */
/*
* The fourth set of lines contains, for each layer by each impurity,
* the integrated dopant (R4), and the interior concentration of the
* polysilicon grains (R4).
*/
for (j = 0; j < numLay; ++j) {
for (i = 0; i < numImp; ++i) {
float rdata;
if (fscanf(fpSuprem, "%e%e", &rdata, &rdata) != 2) {
(void) fprintf(cp_err, "Unable to read integrated dopant "
"and interior concentration of layer %d and "
"impurity %d from file \"%s\".\n",
j + 1, i + 1, inFile);
xrc = -1;
goto EXITPOINT;
}
}
}
}
DEBUG fprintf(stderr,"set 4:\n" );
DEBUG fprintf(stderr,"set 4:\n" );
/*
* The fifth set of lines contains, for each node in the structure,
* the distance to the next deepest node (R4), the distance from the
* surface (R4), and, for each impurity type, the impurity's
* chemical concentration (R4) and the impurity's active concentration (R4).
*/
for ( i=1; i <= numGrid; i++ ) {
fscanf( fpSuprem, "%e %e", &rdata, &x[i] );
/*
* The fifth set of lines contains, for each node in the structure,
* the distance to the next deepest node (R4), the distance from the
* surface (R4), and, for each impurity type, the impurity's
* chemical concentration (R4) and the impurity's active concentration (R4).
*/
for (i = 1; i <= numGrid; ++i) {
float rdata;
if (fscanf(fpSuprem, "%e %e", &rdata, &x[i]) != 2) {
(void) fprintf(cp_err, "Unable to read grid %d "
"from file \"%s\".\n",
i + 1, inFile);
xrc = -1;
goto EXITPOINT;
}
for ( j=0; j < numImp; j++ ) {
/* chemical concentration - not required */
fscanf( fpSuprem, "%e", &con[i] );
/* store active concentration */
fscanf( fpSuprem, "%e", &con[i] );
for (j = 0; j < numImp; j++) {
float junk;
/* chemical concentration - not required */
if (fscanf(fpSuprem, "%e", &junk) != 1) {
(void) fprintf(cp_err, "Unable to chemical concentration "
"%d of layer %d "
"from file \"%s\".\n",
j + 1, i + 1, inFile);
xrc = -1;
goto EXITPOINT;
}
/* orient sign properly */
if (impTyp[j] == *impId) {
/*...Boron...*/
if (impTyp[j] == 1) {
conc[i] = - con[i];
} else {
/*...All Other Impurities: P, As, Sb ...*/
conc[i] = con[i];
}
}
/* store active concentration */
if (fscanf(fpSuprem, "%e", &con[i]) != 1) {
(void) fprintf(cp_err, "Unable to active concentration "
"%d of layer %d "
"from file \"%s\".\n",
j + 1, i + 1, inFile);
xrc = -1;
goto EXITPOINT;
}
/* orient sign properly */
if (impTyp[j] == *impId) {
/*...Boron...*/
if (impTyp[j] == 1) {
conc[i] = - con[i];
}
else {
/*...All Other Impurities: P, As, Sb ...*/
conc[i] = con[i];
}
}
}
} /* end of loop over num grid */
DEBUG fprintf( stderr, "set 5: %e %e\n", x[1], conc[1] );
/*
* The last line in the file contains some random stuff that might be
* useful to some people, the temperature in degrees Kelvin of the last
* diffusion step (R4), the phosphorus implant dose (R4), the arsenic
* implant flag (L4). However, we can just ignore that stuff.
*/
if (fclose(fpSuprem) != 0) {
(void) fprintf(cp_err, "Unable to close file \"%s\": %s.\n",
inFile, strerror(errno));
xrc = -1;
goto EXITPOINT;
}
}
DEBUG fprintf( stderr, "set 5: %e %e\n", x[1], conc[1] );
fpSuprem = (FILE *) NULL;
/*
* The last line in the file contains some random stuff that might be
* useful to some people, the temperature in degrees Kelvin of the last
* diffusion step (R4), the phosphorus implant dose (R4), the arsenic
* implant flag (L4). However, we can just ignore that stuff.
*/
fclose( fpSuprem );
/* shift silicon layer to beginning of array */
for (j = numLay; --j >= 0; ) {
if (matTyp[j] == 1) {
break;
}
}
if (j < 0) {
(void) fprintf(cp_err, "internal error in %s!\n", __FUNCTION__);
xrc = -1;
goto EXITPOINT;
}
siIndex = j;
offset = topNod[siIndex] - 1;
numGrid -= offset;
xStart = x[1 + offset];
for (i = 1; i <= numGrid; i++) {
x[i] = x[i + offset] - xStart;
conc[i] = conc[i + offset];
}
/* Store number of valid nodes using pointer */
*numNod = numGrid;
EXITPOINT:
if (fpSuprem != (FILE *) NULL) {
if (fclose(fpSuprem) != 0) {
(void) fprintf(cp_err, "Unable to close \"%s\" at exit: %s\n",
inFile, strerror(errno));
xrc = -1;
}
}
return xrc;
} /* end of function SUPascRead */
/* shift silicon layer to beginning of array */
for ( j=numLay; --j >= 0; )
if (matTyp[ j ] == 1)
break;
if(j < 0) {
fprintf(stderr, "internal error in %s, bye !\n", __FUNCTION__);
controlled_exit(1);
}
siIndex = j;
offset = topNod[ siIndex ] - 1;
numGrid -= offset;
xStart = x[1 + offset];
for ( i=1; i <= numGrid; i++ ) {
x[i] = x[i + offset] - xStart;
conc[i] = conc[i + offset];
}
/* Store number of valid nodes using pointer */
*numNod = numGrid;
return;
}

View File

@ -153,7 +153,7 @@ extern BOOLEAN TWOdeltaConverged(TWOdevice *);
extern BOOLEAN TWOdeviceConverged(TWOdevice *);
extern void TWOresetJacobian(TWOdevice *);
extern void TWOstoreNeutralGuess(TWOdevice *);
extern void TWOequilSolve(TWOdevice *);
extern int TWOequilSolve(TWOdevice *);
extern void TWObiasSolve(TWOdevice *, int, BOOLEAN, TWOtranInfo *);
extern void TWOstoreEquilibGuess(TWOdevice *);
extern void TWOstoreInitialGuess(TWOdevice *);

View File

@ -98,6 +98,7 @@ TWOdopingValue(DOPprofile *pProfile, DOPtable *pTable, double x,
} else {
value = pProfile->PEAK_CONC * exp( -argP );
}
break;
case EXP:
argP = ABS(argP);
if ( argP > 80.0 ) {
@ -143,6 +144,7 @@ TWOdopingValue(DOPprofile *pProfile, DOPtable *pTable, double x,
} else {
value *= exp( -argL );
}
break;
case EXP:
argL = ABS(argL);
if ( argL > 80.0 ) {

View File

@ -4,21 +4,20 @@ Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
Author: 1991 David A. Gates, U. C. Berkeley CAD Group
**********/
#include "../../maths/misc/norm.h"
#include "ngspice/bool.h"
#include "ngspice/cidersupt.h"
#include "ngspice/cpextern.h"
#include "ngspice/ifsim.h"
#include "ngspice/macros.h"
#include "ngspice/ngspice.h"
#include "ngspice/numglobs.h"
#include "ngspice/numenum.h"
#include "ngspice/numglobs.h"
#include "ngspice/spmatrix.h"
#include "ngspice/twodev.h"
#include "ngspice/twomesh.h"
#include "ngspice/spmatrix.h"
#include "ngspice/bool.h"
#include "ngspice/macros.h"
#include "twoddefs.h"
#include "twodext.h"
#include "ngspice/cidersupt.h"
#include "../../maths/misc/norm.h"
#include "ngspice/ifsim.h"
extern IFfrontEnd *SPfrontEnd;
@ -96,19 +95,24 @@ TWOdcSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN newSolver,
error = spFactor(pDevice->matrix);
factorTime += SPfrontEnd->IFseconds() - startTime;
if (newSolver) {
if (pDevice->iterationNumber == 1) {
orderTime = factorTime;
} else if (pDevice->iterationNumber == 2) {
orderTime -= factorTime - orderTime;
factorTime -= orderTime;
if (pDevice->poissonOnly) {
pDevice->pStats->orderTime[STAT_SETUP] += orderTime;
} else {
pDevice->pStats->orderTime[STAT_DC] += orderTime;
}
newSolver = FALSE;
}
}
if (pDevice->iterationNumber == 1) {
orderTime = factorTime;
}
else if (pDevice->iterationNumber == 2) {
orderTime -= factorTime - orderTime;
factorTime -= orderTime;
if (pDevice->poissonOnly) {
pDevice->pStats->orderTime[STAT_SETUP] += orderTime;
}
else {
pDevice->pStats->orderTime[STAT_DC] += orderTime;
}
/* After first two iterations, no special handling for a
* new solver */
newSolver = FALSE;
} /* end of case of iteratin 2 */
} /* end of special processing for a new solver */
if (foundError(error)) {
if (error == spSINGULAR) {
int badRow, badCol;
@ -430,58 +434,69 @@ TWOstoreNeutralGuess(TWOdevice *pDevice)
/* computing the equilibrium solution; solution of Poisson's eqn */
/* the solution is used as an initial starting point for bias conditions */
void
TWOequilSolve(TWOdevice *pDevice)
int TWOequilSolve(TWOdevice *pDevice)
{
BOOLEAN newSolver = FALSE;
int error;
int nIndex, eIndex;
TWOelem *pElem;
TWOnode *pNode;
double startTime, setupTime, miscTime;
BOOLEAN newSolver = FALSE;
int error;
int nIndex, eIndex;
TWOelem *pElem;
TWOnode *pNode;
double startTime, setupTime, miscTime;
setupTime = miscTime = 0.0;
setupTime = miscTime = 0.0;
/* SETUP */
startTime = SPfrontEnd->IFseconds();
switch (pDevice->solverType) {
case SLV_SMSIG:
case SLV_BIAS:
/* free up memory allocated for the bias solution */
FREE(pDevice->dcSolution);
FREE(pDevice->dcDeltaSolution);
FREE(pDevice->copiedSolution);
FREE(pDevice->rhs);
FREE(pDevice->rhsImag);
spDestroy(pDevice->matrix);
case SLV_NONE:
pDevice->poissonOnly = TRUE;
pDevice->numEqns = pDevice->dimEquil - 1;
XCALLOC(pDevice->dcSolution, double, pDevice->dimEquil);
XCALLOC(pDevice->dcDeltaSolution, double, pDevice->dimEquil);
XCALLOC(pDevice->copiedSolution, double, pDevice->dimEquil);
XCALLOC(pDevice->rhs, double, pDevice->dimEquil);
pDevice->matrix = spCreate(pDevice->numEqns, 0, &error);
if (error == spNO_MEMORY) {
printf("TWOequilSolve: Out of Memory\n");
exit(-1);
}
newSolver = TRUE;
spSetReal(pDevice->matrix);
TWOQjacBuild(pDevice);
pDevice->numOrigEquil = spElementCount(pDevice->matrix);
pDevice->numFillEquil = 0;
case SLV_EQUIL:
pDevice->solverType = SLV_EQUIL;
break;
default:
fprintf(stderr, "Panic: Unknown solver type in equil solution.\n");
exit(-1);
break;
}
TWOstoreNeutralGuess(pDevice);
setupTime += SPfrontEnd->IFseconds() - startTime;
/* SETUP */
startTime = SPfrontEnd->IFseconds();
/* Set up pDevice to compute the equilibrium solution. If the solver
* is for bias, the arrays must be freed and allocated to the correct
* sizes for an equilibrium solution; if it is a new solver, they are
* only allocated; and if already an equilibrium solve, nothing
* needs to be done */
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (pDevice->solverType) {
case SLV_SMSIG:
case SLV_BIAS:
/* Free memory allocated for the bias solution */
FREE(pDevice->dcSolution);
FREE(pDevice->dcDeltaSolution);
FREE(pDevice->copiedSolution);
FREE(pDevice->rhs);
FREE(pDevice->rhsImag);
spDestroy(pDevice->matrix);
/* FALLTHROUGH */
case SLV_NONE: {
/* Allocate memory needed for an equilibrium solution */
const int n_dim = pDevice->dimEquil;
const int n_eqn = n_dim - 1;
pDevice->poissonOnly = TRUE;
pDevice->numEqns = n_eqn;
XCALLOC(pDevice->dcSolution, double, n_dim);
XCALLOC(pDevice->dcDeltaSolution, double, n_dim);
XCALLOC(pDevice->copiedSolution, double, n_dim);
XCALLOC(pDevice->rhs, double, n_dim);
pDevice->matrix = spCreate(n_eqn, 0, &error);
if (error == spNO_MEMORY) {
(void) fprintf(cp_err, "TWOequilSolve: Out of Memory\n");
return E_NOMEM;
}
newSolver = TRUE;
spSetReal(pDevice->matrix); /* set to a real matrix */
TWOQjacBuild(pDevice);
pDevice->numOrigEquil = spElementCount(pDevice->matrix);
pDevice->numFillEquil = 0;
pDevice->solverType = SLV_EQUIL;
break;
}
case SLV_EQUIL: /* Nothing to do if already equilibrium solver */
break;
default: /* Invalid data */
fprintf(stderr, "Panic: Unknown solver type in equil solution.\n");
return E_PANIC;
} /* end of switch over solve type */
TWOstoreNeutralGuess(pDevice);
setupTime += SPfrontEnd->IFseconds() - startTime;
/* SOLVE */
TWOdcSolve(pDevice, MaxIterations, newSolver, FALSE, NULL);
@ -510,6 +525,8 @@ TWOequilSolve(TWOdevice *pDevice)
miscTime += SPfrontEnd->IFseconds() - startTime;
pDevice->pStats->setupTime[STAT_SETUP] += setupTime;
pDevice->pStats->miscTime[STAT_SETUP] += miscTime;
return 0;
}
/* compute the solution under an applied bias */
@ -530,15 +547,20 @@ TWObiasSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN tranAnalysis,
/* SETUP */
startTime = SPfrontEnd->IFseconds();
switch (pDevice->solverType) {
case SLV_EQUIL:
/* free up the vectors allocated in the equilibrium solution */
FREE(pDevice->dcSolution);
FREE(pDevice->dcDeltaSolution);
FREE(pDevice->copiedSolution);
FREE(pDevice->rhs);
spDestroy(pDevice->matrix);
/* Set up for solving for bias */
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (pDevice->solverType) {
case SLV_EQUIL:
/* free up the vectors allocated in the equilibrium solution */
FREE(pDevice->dcSolution);
FREE(pDevice->dcDeltaSolution);
FREE(pDevice->copiedSolution);
FREE(pDevice->rhs);
spDestroy(pDevice->matrix);
/* FALLTHROUGH */
case SLV_NONE:
/* Set up for bias */
pDevice->poissonOnly = FALSE;
pDevice->numEqns = pDevice->dimBias - 1;
XCALLOC(pDevice->dcSolution, double, pDevice->dimBias);
@ -562,11 +584,13 @@ TWObiasSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN tranAnalysis,
pDevice->numOrigBias = spElementCount(pDevice->matrix);
pDevice->numFillBias = 0;
TWOstoreInitialGuess(pDevice);
/* FALLTHROUGH */
case SLV_SMSIG:
spSetReal(pDevice->matrix);
case SLV_BIAS:
pDevice->solverType = SLV_BIAS;
break;
case SLV_BIAS:
break;
default:
fprintf(stderr, "Panic: Unknown solver type in bias solution.\n");
exit(-1);

View File

@ -78,10 +78,12 @@ arg_plot(const wordlist *wl, const struct comm *command)
void
arg_load(wordlist *wl, const struct comm *command)
arg_load(const wordlist *wl_in, const struct comm *command)
{
/* just call com_load */
wordlist * const wl = wl_copy(wl_in);
command->co_func(wl);
wl_free(wl);
}
@ -91,15 +93,13 @@ void arg_let(const wordlist *wl, const struct comm *command)
}
void
arg_set(const wordlist *wl, const struct comm *command)
void arg_set(const wordlist *wl, const struct comm *command)
{
common("which variable", wl, command);
}
void
arg_display(const wordlist *wl, const struct comm *command)
void arg_display(const wordlist *wl, const struct comm *command)
{
NG_IGNORE(wl);
NG_IGNORE(command);

View File

@ -10,7 +10,7 @@ char *prompt(FILE *fp);
wordlist *process(wordlist *wlist);
void arg_print(const wordlist *wl, const struct comm *command);
void arg_plot(const wordlist *wl, const struct comm *command);
void arg_load(wordlist *wl, const struct comm *command);
void arg_load(const wordlist *wl, const struct comm *command);
void arg_let(const wordlist *wl, const struct comm *command);
void arg_set(const wordlist *wl, const struct comm *command);
void arg_display(const wordlist *wl, const struct comm *command);

View File

@ -6,6 +6,8 @@
#ifndef ngspice_COM_ALIAS_H
#define ngspice_COM_ALIAS_H
#include "ngspice/wordlist.h"
void com_alias(wordlist *wl);
void com_unalias(wordlist *wl);

View File

@ -188,9 +188,15 @@ void com_hardcopy(wordlist *wl)
if (!cp_getvar("lprplot5", CP_STRING, format, sizeof(format)))
strcpy(format, SYSTEM_PLOT5LPR);
(void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device);
(void) system(buf);
printed = 1;
if (system(buf) == -1) {
fprintf(cp_out, "Printing %s on the %s printer failed.\n",
fname, device);
}
else {
fprintf(cp_out, "Printing %s on the %s printer OK.\n",
fname, device);
printed = 1;
}
}
#endif
#ifdef SYSTEM_PSLPR
@ -199,9 +205,15 @@ void com_hardcopy(wordlist *wl)
if (!cp_getvar("lprps", CP_STRING, format, sizeof(format)))
strcpy(format, SYSTEM_PSLPR);
(void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device);
(void) system(buf);
printed = 1;
if (system(buf) == -1) {
fprintf(cp_out, "Printing %s on the %s printer failed.\n",
fname, device);
}
else {
fprintf(cp_out, "Printing %s on the %s printer OK.\n",
fname, device);
printed = 1;
}
}
#endif
}

View File

@ -192,11 +192,11 @@ void com_let(wordlist *wl)
vec_dst->v_compdata = TMALLOC(ngcomplex_t, n_elem_alloc);
}
/* Make the destination vector the right data type. A few
/* Make the destination vector the right data type. A few
* extra () added to keep some compilers from warning. */
vec_dst->v_flags =
(vec_dst->v_flags & ~(VF_REAL | VF_COMPLEX)) |
(vec_src->v_flags & (VF_REAL | VF_COMPLEX));
vec_dst->v_flags = (short int) (
((int) vec_dst->v_flags & ~(VF_REAL | VF_COMPLEX)) |
((int) vec_src->v_flags & (VF_REAL | VF_COMPLEX)));
vec_dst->v_alloc_length = vec_src->v_alloc_length;
vec_dst->v_length = vec_src->v_length;
copy_vector_data(vec_dst, vec_src);
@ -514,7 +514,7 @@ static void copy_vector_data(struct dvec *vec_dst,
const size_t length = (size_t) vec_src->v_length;
int n_dim = vec_dst->v_numdims = vec_src->v_numdims;
(void) memcpy(vec_dst->v_dims, vec_src->v_dims,
n_dim * sizeof(int));
(size_t) n_dim * sizeof(int));
if (isreal(vec_src)) {
(void) memcpy(vec_dst->v_realdata, vec_src->v_realdata,
length * sizeof(double));
@ -686,13 +686,13 @@ static void copy_vector_data_with_stride(struct dvec *vec_dst,
if (isreal(vec_src)) { /* Both real */
n_byte_elem = (int) sizeof(double);
n_byte_topdim = (int) n_elem_topdim * sizeof(double);
n_byte_topdim = n_elem_topdim * (int) sizeof(double);
p_vec_data_dst = vec_dst->v_realdata;
p_vec_data_src = vec_src->v_realdata;
}
else {
n_byte_elem = (int) sizeof(ngcomplex_t);
n_byte_topdim = (int) n_elem_topdim * sizeof(ngcomplex_t);
n_byte_topdim = n_elem_topdim * (int) sizeof(ngcomplex_t);
p_vec_data_dst = vec_dst->v_compdata;
p_vec_data_src = vec_src->v_compdata;
}
@ -733,15 +733,15 @@ static void copy_vector_data_with_stride(struct dvec *vec_dst,
{
const int n_cpy = n_dim - 2; /* index where copying done */
const void *p_vec_data_src_end = (char *) p_vec_data_src +
(size_t) vec_src->v_length *
n_byte_elem; /* end of copying */
(size_t) (vec_src->v_length * n_byte_elem);
/* end of copying */
for ( ; ; ) {
/* Copy the data currently being located by the cumulative
* offset and the source location */
(void) memcpy(
(char *) p_vec_data_dst + p_offset_level_cum[n_cpy],
p_vec_data_src,
n_byte_topdim);
(size_t) n_byte_topdim);
/* Move to the next source data and exit the loop if
* the end is reached.

View File

@ -1,6 +1,7 @@
/*************
* com_shell.c
************/
#include <stdio.h>
#include "ngspice/ngspice.h"
#include "ngspice/wordlist.h"
@ -20,7 +21,7 @@
void
com_shell(wordlist *wl)
{
char *com, *shell = NULL;
char *shell = NULL;
shell = getenv("SHELL");
if (shell == NULL) {
@ -39,8 +40,9 @@ com_shell(wordlist *wl)
execl(shell, shell, 0);
_exit(99);
} else {
com = wl_flatten(wl);
char * const com = wl_flatten(wl);
execl("/bin/sh", "sh", "-c", com, 0);
txfree(com);
}
} else {
/* XXX Better have all these signals */
@ -58,12 +60,20 @@ com_shell(wordlist *wl)
#else
/* Easier to forget about changing the io descriptors. */
if (wl) {
com = wl_flatten(wl);
system(com);
tfree(com);
} else {
system(shell);
char * const com = wl_flatten(wl);
if (system(com) == -1) {
(void) fprintf(cp_err, "Unable to execute \"%s\".\n", com);
}
txfree(com);
}
else {
if (system(shell) == -1) {
(void) fprintf(cp_err, "Unable to execute \"%s\".\n", shell);
}
}
#endif
}
} /* end of function com_shell */

View File

@ -267,7 +267,14 @@ static void set_static_system_info(void)
system_info.osName = TMALLOC(char, size + 1);
rewind(file);
fread(system_info.osName, sizeof(char), size, file);
if (fread(system_info.osName, sizeof(char), size, file) != size) {
(void) fprintf(cp_err, "Unable to read \"/proc/version\".\n");
fclose(file);
tfree(system_info.osName);
return;
}
fclose(file);
system_info.osName[size] = '\0';
@ -289,7 +296,12 @@ static void set_static_system_info(void)
/* get complete string */
inStr = TMALLOC(char, size+1);
rewind(file);
fread(inStr, sizeof(char), size, file);
if (fread(inStr, sizeof(char), size, file) != size) {
(void) fprintf(cp_err, "Unable to read \"/proc/cpuinfo\".\n");
fclose(file);
txfree(inStr);
return;
}
inStr[size] = '\0';
{
@ -379,7 +391,7 @@ static void set_static_system_info(void)
* }
*/
tfree(inStr);
txfree(inStr);
fclose(file);
} /* end of case that file was opened OK */

View File

@ -40,8 +40,7 @@ canonical_name(const char *name, DSTRINGPTR dbuf_p,
size_t n = strlen(p_start) - 1; /* copy all but final ')' */
ds_case_t case_type = make_i_name_lower ?
ds_case_lower : ds_case_as_is;
bool f_ok = ds_cat_mem_case(dbuf_p, p_start, (int) n,
case_type) == DS_E_OK;
bool f_ok = ds_cat_mem_case(dbuf_p, p_start, n, case_type) == DS_E_OK;
f_ok &= ds_cat_mem(dbuf_p, sz_branch,
sizeof sz_branch / sizeof *sz_branch - 1) == DS_E_OK;
if (!f_ok) {

View File

@ -213,7 +213,7 @@ static int atodims_bracketed(const char *p, int *data, int *p_n_dim)
int rc = get_bracketed_dim(p, data + n_dim);
if (rc <= 0) { /* error or normal exit */
*p_n_dim = n_dim;
*p_n_dim = (int) n_dim;
return !!rc;
}
p += rc; /* step after the dimension that was processed */
@ -283,10 +283,10 @@ static int atodims_csv(const char *p, int *data, int *p_n_dim)
++p;
break;
case ']': /* ] ended scan */
*p_n_dim = n_dim;
*p_n_dim = (int) n_dim;
return (int) (p - p0) + 1;
case '\0': /* end of string ended scan */
*p_n_dim = n_dim;
*p_n_dim = (int) n_dim;
return 0;
default: /* invalid char */
return -1;
@ -347,7 +347,7 @@ static int get_dim(const char *p, int *p_val)
const char *p0 = p;
for ( ; ; ++p) {
const char c_cur = *p;
unsigned int digit_cur = c_cur - '0';
unsigned int digit_cur = (unsigned int) (c_cur - '0');
unsigned int val_new;
if (digit_cur > 9) { /* not a digit */
if ((*p_val = (int) val) < 0) { /* overflow */

View File

@ -246,10 +246,9 @@ DevDrawArc(int x0, int y0, int radius, double theta, double delta_theta)
}
void
DevDrawText(char *text, int x, int y, int angle)
void DevDrawText(const char *text, int x, int y, int angle)
{
dispdev->DrawText (text, x, y, angle);
dispdev->DrawText(text, x, y, angle);
}
@ -275,9 +274,9 @@ SetLinestyle(int linestyleid)
void
SetColor(int colorid, GRAPH *graph)
SetColor(int colorid)
{
dispdev->SetColor (colorid, graph);
dispdev->SetColor(colorid);
}

View File

@ -19,11 +19,11 @@ void DevClose(void);
void DevClear(void);
void DevDrawLine(int x1, int y1, int x2, int y2, bool isgrid);
void DevDrawArc(int x0, int y0, int radius, double theta, double delta_theta);
void DevDrawText(char *text, int x, int y, int angle);
void DevDrawText(const char *text, int x, int y, int angle);
void DefineColor(int colorid, double red, double green, double blue);
void DefineLinestyle(int linestyleid, int mask);
void SetLinestyle(int linestyleid);
void SetColor(int colorid, GRAPH* graph);
void SetColor(int colorid);
void DevUpdate(void);
void DatatoScreen(GRAPH *graph, double x, double y, int *screenx, int *screeny);
void Input(REQUEST *request, RESPONSE *response);

View File

@ -5,6 +5,7 @@
*/
#include "ngspice/ngspice.h"
#include "resource.h"
#if defined(_WIN32)
#undef BOOLEAN
@ -29,7 +30,7 @@
/**
* Returns the size of available memory (RAM) in bytes.
*/
unsigned long long getAvailableMemorySize( )
unsigned long long getAvailableMemorySize(void)
{
#if defined(HAVE__PROC_MEMINFO)
/* Cygwin , Linux--------------------------------- */

View File

@ -7,6 +7,7 @@
*/
#include "ngspice/ngspice.h"
#include "resource.h"
#if defined(_WIN32)
#undef BOOLEAN
@ -29,7 +30,7 @@
/**
* Returns the size of physical memory (RAM) in bytes.
*/
unsigned long long getMemorySize()
unsigned long long getMemorySize(void)
{
#if defined(HAVE__PROC_MEMINFO)
/* Cygwin , Linux--------------------------------- */

View File

@ -7,6 +7,7 @@
*/
#include "ngspice/ngspice.h"
#include "resource.h"
#if defined(_WIN32)
#undef BOOLEAN
@ -39,7 +40,7 @@
* memory use) measured in bytes, or zero if the value cannot be
* determined on this OS.
*/
unsigned long long getPeakRSS()
unsigned long long getPeakRSS(void)
{
#if defined(HAVE__PROC_MEMINFO)
/* Linux ---------------------------------------------------- */
@ -100,7 +101,7 @@ unsigned long long getPeakRSS()
* Returns the current resident set size (physical memory use) measured
* in bytes, or zero if the value cannot be determined on this OS.
*/
unsigned long long getCurrentRSS( )
unsigned long long getCurrentRSS(void)
{
#if defined(_WIN32)
/* Windows -------------------------------------------------- */

View File

@ -22,6 +22,7 @@ static toplink *getsubtoplink(char **ss);
static topic *alltopics = NULL;
static fplace *copy_fplace(fplace *place);
static void hlp_topic_free(topic *p_topic);
static int
@ -37,28 +38,34 @@ sortcmp(const void *a, const void *b)
static void
sortlist(toplink **tlp)
{
toplink **vec, *tl;
toplink *tl;
size_t num = 0, i;
for (tl = *tlp; tl; tl = tl->next)
for (tl = *tlp; tl; tl = tl->next) {
num++;
if (!num)
}
if (!num) { /* nothing to sort */
return;
vec = TMALLOC(toplink *, num);
for (tl = *tlp, i = 0; tl; tl = tl->next, i++)
}
toplink ** const vec = TMALLOC(toplink *, num);
for (tl = *tlp, i = 0; tl; tl = tl->next, i++) {
vec[i] = tl;
}
(void) qsort(vec, num, sizeof (toplink *), sortcmp);
*tlp = vec[0];
for (i = 0; i < num - 1; i++)
for (i = 0; i < num - 1; i++) {
vec[i]->next = vec[i + 1];
}
vec[i]->next = NULL;
tfree(vec);
txfree(vec);
}
topic *
hlp_read(fplace *place)
{
int xrc = 0;
char buf[BSIZE_SP];
topic *top = TMALLOC(topic, 1);
toplink *topiclink;
@ -68,22 +75,44 @@ hlp_read(fplace *place)
char *s;
bool mof = FALSE;
if (!place)
return NULL;
if (!place) {
xrc = -1;
goto EXITPOINT;
}
top->place = copy_fplace(place);
/* get the title */
if (!place->fp)
if (!place->fp) {
place->fp = hlp_fopen(place->filename);
if (!place->fp)
return (NULL);
}
if (!place->fp) {
xrc = -1;
goto EXITPOINT;
}
fseek(place->fp, place->fpos, SEEK_SET);
(void) fgets(buf, BSIZE_SP, place->fp); /* skip subject */
(void) fgets(buf, BSIZE_SP, place->fp);
for (s = buf; *s && (*s != '\n'); s++)
/* skip subject */
if (fgets(buf, BSIZE_SP, place->fp) == (char *) NULL) {
fprintf(stderr, "missing subject\n");
xrc = -1;
goto EXITPOINT;
}
if (fgets(buf, BSIZE_SP, place->fp) == (char *) NULL) {
fprintf(stderr, "missing title\n");
xrc = -1;
goto EXITPOINT;
}
for (s = buf; *s && (*s != '\n'); s++) {
;
}
*s = '\0';
if ((int) (s - buf) < 7) {
fprintf(stderr, "invalid title\n");
xrc = -1;
goto EXITPOINT;
}
top->title = copy(&buf[7]); /* don't copy "TITLE: " */
/* get the text */
@ -93,8 +122,7 @@ hlp_read(fplace *place)
break;
if ((*buf == '\0') || /* SJB - bug fix */
!strncmp("SEEALSO: ", buf, 9) ||
!strncmp("SUBTOPIC: ", buf, 10))
{
!strncmp("SUBTOPIC: ", buf, 10)) {
/* no text */
top->text = NULL;
goto endtext;
@ -163,8 +191,15 @@ endtext:
top->readlink = alltopics;
alltopics = top;
return (top);
}
EXITPOINT:
if (xrc != 0) { /* free resources if error */
hlp_topic_free(top);
top = (topic *) NULL;
}
return top;
} /* end of function hlp_read */
/* *ss is of the form filename:subject */
@ -310,11 +345,18 @@ getsubject(fplace *place)
return(NULL);
fseek(place->fp, place->fpos, SEEK_SET);
(void) fgets(buf, BSIZE_SP, place->fp);
if (fgets(buf, BSIZE_SP, place->fp) == (char *) NULL) {
(void) fprintf(stderr, "Missing subject");
return (char *) NULL;
}
for (s = buf; *s && (*s != '\n'); s++)
;
*s = '\0';
return (copy(&buf[9])); /* don't copy "SUBJECT: " */
if ((int) (s - buf) < 9) {
(void) fprintf(stderr, "Invalid subject");
return (char *) NULL;
}
return copy(buf + 9); /* don't copy "SUBJECT: " */
}
@ -324,33 +366,41 @@ void tlfree(toplink *tl)
toplink *nt = NULL;
while (tl) {
tfree(tl->description);
tfree(tl->place->filename);
tfree(tl->place);
txfree(tl->description);
txfree(tl->place->filename);
txfree(tl->place);
/* Don't free the button stuff... */
nt = tl->next;
tfree(tl);
txfree(tl);
tl = nt;
}
}
void
hlp_free(void)
{
topic *top, *nt = NULL;
topic *top, *nt;
for (top = alltopics; top; top = nt) {
nt = top->readlink;
tfree(top->title);
tfree(top->place);
wl_free(top->text);
tlfree(top->subtopics);
tlfree(top->seealso);
tfree(top);
hlp_topic_free(top);
}
alltopics = NULL;
}
} /* end of function hlp_free */
static void hlp_topic_free(topic *p_topic)
{
txfree(p_topic->title);
txfree(p_topic->place);
wl_free(p_topic->text);
tlfree(p_topic->subtopics);
tlfree(p_topic->seealso);
txfree(p_topic);
} /* end of function hlp_topic_free */
static fplace *

View File

@ -250,7 +250,7 @@ int GL_Arc(int x0, int y0, int r, double theta, double delta_theta)
}
int GL_Text(char *text, int x, int y, int angle)
int GL_Text(const char *text, int x, int y, int angle)
{
NG_IGNORE(angle);
@ -291,9 +291,8 @@ int GL_SetLinestyle(int linestyleid)
}
int GL_SetColor(int colorid, GRAPH* graph)
int GL_SetColor(int colorid)
{
NG_IGNORE(graph);
fprintf(plotfile, "SP %d;", colorid);
return 0;

View File

@ -1390,8 +1390,7 @@ com_edit(wordlist *wl)
fprintf(cp_out, "run circuit? ");
fflush(cp_out);
fgets(buf, BSIZE_SP, stdin);
if (buf[0] != 'n') {
if (fgets(buf, BSIZE_SP, stdin) == (char *) NULL || buf[0] != 'n') {
fprintf(cp_out, "running circuit\n");
com_run(NULL);
}

View File

@ -3,23 +3,24 @@ Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
**********/
#include "../misc/ivars.h"
#include "circuits.h"
#include "com_alias.h"
#include "define.h"
#include "display.h"
#include "ftehelp.h"
#include "misccoms.h"
#include "ngspice/ngspice.h"
#include "ngspice/cpdefs.h"
#include "ngspice/ftedefs.h"
#include "ngspice/dvec.h"
#include "ngspice/iferrmsg.h"
#include "ftehelp.h"
#include "ngspice/hlpdefs.h"
#include "misccoms.h"
#include "postcoms.h"
#include "circuits.h"
#include "variable.h"
#include "plotting/graf.h"
#include "display.h"
#include "../misc/ivars.h"
#include "com_alias.h"
#include "define.h"
#include "plotting/plotit.h"
#include "postcoms.h"
#include "runcoms2.h"
#include "variable.h"
#ifdef HAVE_GNUREADLINE
#include <readline/readline.h>
@ -38,7 +39,6 @@ extern void rem_controls(void);
extern IFsimulator SIMinfo;
extern void spice_destroy_devices(void); /* FIXME need a better place */
extern void pl_rempar(void); /* plotit.c */
static void byemesg(void);
static int confirm_quit(void);
@ -136,7 +136,10 @@ com_bug(wordlist *wl)
Bug_Addr);
(void) sprintf(buf, SYSTEM_MAIL, ft_sim->simulator, ft_sim->version, Bug_Addr);
(void) system(buf);
if (system(buf) == -1) {
fprintf(cp_err, "Bug report could not be sent: \"%s\" failed.\n",
buf);
}
fprintf(cp_out, "Bug report sent. Thank you.\n");
}

View File

@ -128,7 +128,7 @@ pscopy(DSTRINGPTR dstr_p, const char *t, const char *stop)
}
ds_clear(dstr_p);
if (ds_cat_mem(dstr_p, t, stop - t) != DS_E_OK) {
if (ds_cat_mem(dstr_p, t, (size_t) (stop - t)) != DS_E_OK) {
controlled_exit(-1);
}

View File

@ -193,7 +193,7 @@ findsubname(dico_t *dico, DSTRINGPTR dstr_p)
pscopy(&name, p, t);
entry = entrynb(dico, ds_get_buf(&name));
if (entry && (entry->tp == NUPA_SUBCKT)) {
(void) ds_set_length(dstr_p, p_end - s);
(void) ds_set_length(dstr_p, (size_t) (p_end - s));
ds_free(&name);
return;
}
@ -247,7 +247,7 @@ transform(dico_t *dico, DSTRINGPTR dstr_p, bool incontrol)
/* split off any "params" tail */
params = strstr(s, "params:");
if (params) {
ds_set_length(dstr_p, params - s);
ds_set_length(dstr_p, (size_t) (params - s));
}
category = 'S';
} else if (prefix(".control", s)) {

View File

@ -146,7 +146,7 @@ static wordlist *bracexpand(const wordlist *w_exp)
char ch_cur;
for ( ; (ch_cur = *p_cur) != '\0'; p_cur++) {
if (ch_cur == cp_ocurl) {
offset_ocurl = p_cur - wl_word;
offset_ocurl = (size_t) (p_cur - wl_word);
break;
}
}
@ -246,7 +246,7 @@ static wordlist_l *brac1(size_t offset_ocurl1, const char *p_str)
}
}
const size_t n_char_append = s - p_start;
const size_t n_char_append = (size_t) (s - p_start);
if (n_char_append > 0) {
wordlist_l *wl;
@ -330,7 +330,7 @@ static wordlist_l *brac2(const char *string,
}
else if (ch_cur == cp_ocurl) { /* another brace level started */
if (nb++ == 0) { /* Inc count. If 1st '{', save offset */
offset_ocurl1 = s - buf_cur;
offset_ocurl1 = (size_t) (s - buf_cur);
}
}
else if ((ch_cur == cp_comma) && (nb == 0)) {
@ -366,7 +366,8 @@ static wordlist_l *brac2(const char *string,
* wordlist being built */
{
wordlist_l *nwl = brac1(
offset_ocurl1 == SIZE_MAX ? s - buf_cur : offset_ocurl1,
offset_ocurl1 == SIZE_MAX ?
(size_t) (s - buf_cur) : offset_ocurl1,
buf_cur);
wlist = wll_append(wlist, nwl);
}
@ -379,7 +380,7 @@ static wordlist_l *brac2(const char *string,
/* When the loop is exited, s is at a brace or comma, which
* is also considered to be processed. Hence +2 not +1. */
*p_n_char_processed = s - buf + 2;
*p_n_char_processed = (size_t) (s - buf + 2);
return wlist;
}
@ -434,7 +435,7 @@ static void tilde_expand_word(wordlist *wl_node)
while ((c = *usr_end) != '\0' && c != DIR_TERM) {
++usr_end;
}
const size_t n_char_usr = usr_end - usr_start;
const size_t n_char_usr = (size_t) (usr_end - usr_start);
const size_t n_byte_usr = n_char_usr + 1;
const char c_orig = c; /* save char to be overwritten by '\0' */
*usr_end = '\0';
@ -447,7 +448,7 @@ static void tilde_expand_word(wordlist *wl_node)
return; /* Strip the ~ and return the rest */
}
merge_home_with_rest(wl_node, (size_t) n_char_home, sz_home,
n_char_usr + 1);
n_byte_usr);
return;
}

View File

@ -456,6 +456,8 @@ prompt(void)
s = "-> ";
while (*s) {
/* NOTE: The FALLTHROUGH comment is used to suppress a GCC warning
* when flag -Wimplicit-fallthrough is present */
switch (*s) {
case '!':
fprintf(cp_out, "%d", cp_event);
@ -463,6 +465,7 @@ prompt(void)
case '\\':
if (s[1])
(void) putc((*++s), cp_out);
/* FALLTHROUGH */
default:
(void) putc((*s), cp_out);
}

View File

@ -31,6 +31,8 @@ quote_gnuplot_string(FILE *stream, char *s)
fputc('"', stream);
for (; *s; s++)
/* NOTE: The FALLTHROUGH comment is used to suppress a GCC warning
* when flag -Wimplicit-fallthrough is present */
switch (*s) {
case '\n':
fputs("\\n", stream);
@ -38,6 +40,7 @@ quote_gnuplot_string(FILE *stream, char *s)
case '"':
case '\\':
fputc('\\', stream);
/* FALLTHROUGH */
default:
fputc(*s, stream);
}

View File

@ -314,7 +314,7 @@ void gr_point(struct dvec *dv,
return;
}
}
SetColor(dv->v_color, currentgraph);
SetColor(dv->v_color);
switch (currentgraph->plottype) {
double *tics;
@ -474,7 +474,7 @@ void drawlegend(GRAPH *graph, int plotno, struct dvec *dv)
const int y = graph->absolute.height - graph->fontheight
- ((plotno + 2) / 2) * (graph->fontheight);
const int i = y + graph->fontheight / 2 + 1;
SetColor(dv->v_color, graph);
SetColor(dv->v_color);
if (graph->plottype == PLOT_POINT) {
char buf[16];
(void) sprintf(buf, "%c : ", dv->v_linestyle);
@ -484,7 +484,7 @@ void drawlegend(GRAPH *graph, int plotno, struct dvec *dv)
SetLinestyle(dv->v_linestyle);
DevDrawLine(x, i, x + graph->viewport.width / 20, i, FALSE);
}
SetColor(1, graph);
SetColor(1);
DevDrawText(dv->v_name, x + graph->viewport.width / 20
+ graph->fontwidth, y, 0);
}
@ -638,7 +638,7 @@ void gr_restoretext(GRAPH *graph)
/* restore text */
for (k = graph->keyed; k; k = k->next) {
SetColor(k->colorindex, graph);
SetColor(k->colorindex);
DevDrawText(k->text, k->x, k->y, 0);
}
}
@ -735,7 +735,7 @@ static int iplot(struct plot *pl, int id)
for (yt = pl->pl_dvecs->v_type, v = pl->pl_dvecs->v_next; v;
v = v->v_next) {
if ((v->v_flags & VF_PLOT) && (v->v_type != yt)) {
if ((v->v_flags & VF_PLOT) && ((int) v->v_type != yt)) {
yt = SV_NOTYPE;
break;
}

View File

@ -74,7 +74,7 @@ gr_fixgrid(GRAPH *graph, double xdelta, double ydelta, int xtype, int ytype)
if (graph->grid.gridtype == GRID_NONE)
graph->grid.gridtype = GRID_LIN;
SetColor(1, graph);
SetColor(1);
SetLinestyle(1);
if ((graph->data.xmin > graph->data.xmax) ||
@ -132,7 +132,7 @@ void
gr_redrawgrid(GRAPH *graph)
{
SetColor(1, graph);
SetColor(1);
SetLinestyle(1);
/* draw labels */
if (graph->grid.xlabel) {
@ -182,9 +182,10 @@ gr_redrawgrid(GRAPH *graph)
#ifdef HAS_WINGUI
/* x axis centered to graphics on Windows */
/* utf-8: figure out the real length of the x label */
wchar_t *wtext;
wtext = TMALLOC(wchar_t, 2 * strlen(graph->grid.xlabel) + 1);
int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.xlabel, -1, wtext, 2 * strlen(graph->grid.xlabel) + 1);
const int n_byte_wide = 2 * (int) strlen(graph->grid.xlabel) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.xlabel, -1,
wtext, n_byte_wide);
if (wlen == 0) {
fprintf(stderr, "UTF-8 to wide char conversion failed with 0x%x\n", GetLastError());
fprintf(stderr, "%s could not be converted\n", graph->grid.xlabel);
@ -206,6 +207,7 @@ gr_redrawgrid(GRAPH *graph)
else
unitshift = 0; /* reset for next plot window */
}
txfree(wtext);
}
#endif
#endif // EXT_ASC
@ -221,26 +223,34 @@ gr_redrawgrid(GRAPH *graph)
(graph->absolute.height * 3) / 4, 0);
} else {
if (eq(dispdev->name, "postscript"))
DevDrawText(graph->grid.ylabel,
if (eq(dispdev->name, "postscript")) {
DevDrawText(graph->grid.ylabel,
graph->fontwidth,
/*vertical text, midpoint in y is aligned midpoint of text string */
(graph->absolute.height - strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90);
/* vertical text, midpoint in y is aligned midpoint
* of text string */
(graph->absolute.height - (int) strlen(
graph->grid.ylabel) * graph->fontwidth) / 2,
90);
}
#ifdef EXT_ASC
else if (eq(dispdev->name, "Windows"))
DevDrawText(graph->grid.ylabel,
graph->fontwidth,
/*vertical text, midpoint in y is aligned midpoint of text string */
(graph->absolute.height - strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90);
/* vertical text, midpoint in y is aligned midpoint
* of text string */
(graph->absolute.height - (int) strlen(
graph->grid.ylabel) * graph->fontwidth) / 2,
90);
#else
#ifdef HAS_WINGUI
/* Windows and UTF-8: check for string length (in pixels),
place vertical text centered in y with respect to grid */
else if (eq(dispdev->name, "Windows")) {
/* utf-8: figure out the real length of the y label */
wchar_t *wtext;
wtext = TMALLOC(wchar_t, 2 * strlen(graph->grid.ylabel) + 1);
int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.ylabel, -1, wtext, 2 * strlen(graph->grid.ylabel) + 1);
const int n_byte_wide = 2 * (int) strlen(graph->grid.ylabel) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.ylabel, -1,
wtext, n_byte_wide);
if (wlen == 0) {
fprintf(stderr, "UTF-8 to wide char conversion failed with 0x%x\n", GetLastError());
fprintf(stderr, "%s could not be converted\n", graph->grid.ylabel);
@ -257,6 +267,7 @@ gr_redrawgrid(GRAPH *graph)
/*vertical text, midpoint in y is aligned midpoint of text string */
(graph->absolute.height - (int)(1.2*sz.cx + tmw.tmOverhang)) / 2, 90);
}
txfree(wtext);
}
#endif
#endif
@ -1477,7 +1488,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d
/* Let's be lazy and just draw everything -- we won't get called too
* much and the circles get clipped anyway...
*/
SetColor(18, graph);
SetColor(18);
cliparc((double) (centx + xoffset + radoff - rad),
(double) (centy + yoffset), rad, 2*angle,
@ -1491,7 +1502,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d
M_PI - 2 * angle, centx, centy, maxrad, 0);
/* Draw the upper and lower circles. */
SetColor(19, graph);
SetColor(19);
aclip = cliparc((double) (centx + xoffset + radoff),
(double) (centy + yoffset + irad), irad,
(double) (M_PI * 1.5 + 2 * iangle),
@ -1500,7 +1511,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d
xlab = (int)(centx + xoffset + radoff + irad * cos(aclip));
ylab = (int)(centy + yoffset + irad * (1 + sin(aclip)));
if ((ylab - gr_ycenter) > graph->fontheight) {
SetColor(1, graph);
SetColor(1);
adddeglabel(graph, pdeg, xlab, ylab,
gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter);
/*
@ -1508,7 +1519,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d
adddeglabel(graph, ndeg, xlab, ylab,
gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter);
*/
SetColor(19, graph);
SetColor(19);
}
}
aclip = cliparc((double) (centx + xoffset + radoff),
@ -1519,14 +1530,14 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d
if ((aclip >= 0 && aclip < 2*M_PI - M_PI/180) && (pdeg < 359)) {
xlab = (int)(centx + xoffset + radoff + irad * cos(aclip));
ylab = (int)(centy + yoffset + irad * (sin(aclip) - 1));
SetColor(1, graph);
SetColor(1);
adddeglabel(graph, ndeg, xlab, ylab,
gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter);
SetColor(19, graph);
SetColor(19);
}
/* Now toss the labels on... */
SetColor(1, graph);
SetColor(1);
x = centx + xoffset + (int)radoff - 2 * (int)rad -
gi_fntwidth * (int) strlen(plab) - 2;

View File

@ -170,7 +170,7 @@ int Plt5_Arc(int xc, int yc, int radius, double theta, double delta_theta)
}
int Plt5_Text(char *text, int x, int y, int angle)
int Plt5_Text(const char *text, int x, int y, int angle)
{
int savedlstyle;
NG_IGNORE(angle);
@ -211,10 +211,9 @@ int Plt5_SetLinestyle(int linestyleid)
/* ARGSUSED */
int Plt5_SetColor(int colorid, GRAPH *graph)
int Plt5_SetColor(int colorid)
{
NG_IGNORE(colorid);
NG_IGNORE(graph);
/* do nothing */
return 0;

View File

@ -27,33 +27,30 @@ static char *xlabel = NULL, *ylabel = NULL, *title = NULL;
#include "ngspice/tclspice.h"
#endif
/* remove the malloced parameters upon ngspice quit */
static struct dvec *vec_self(struct dvec *v);
static struct dvec *vec_scale(struct dvec *v);
static void find_axis_limits(double *lim, bool oneval, bool f_real,
struct dvec *vecs,
struct dvec *(*p_get_axis_dvec)(struct dvec *dvec),
double *lims);
/* Remove the malloced parameters upon ngspice quit. These are set to NULL
* to allow the function to be used at any time and safely called more than
* one time. */
void pl_rempar(void)
{
txfree(xcompress);
txfree(xindices);
txfree(xlim);
txfree(ylim);
txfree(xdelta);
txfree(ydelta);
txfree(xlabel);
txfree(ylabel);
tfree(xcompress);
tfree(xindices);
tfree(xlim);
tfree(ylim);
tfree(xdelta);
tfree(ydelta);
tfree(xlabel);
tfree(ylabel);
}
static struct dvec *vec_self(struct dvec *v);
static struct dvec *vec_scale(struct dvec *v);
static void find_axis_limits(double *lim, bool oneval, bool f_real,
struct dvec *vecs,
struct dvec *(*p_get_axis_dvec)(struct dvec *dvec),
double *lims);
static struct dvec *vec_self(struct dvec *v);
static struct dvec *vec_scale(struct dvec *v);
static void find_axis_limits(double *lim, bool oneval, bool f_real,
struct dvec *vecs,
struct dvec *(*p_get_axis_dvec)(struct dvec *dvec),
double *lims);
/* This routine gets parameters from the command line, which are of
@ -294,7 +291,7 @@ bool plotit(wordlist *wl, const char *hcopy, const char *devname)
struct pnode *pn, *names;
struct dvec *d = NULL, *vecs = NULL, *lv, *lastvs = NULL;
char *xn;
int i, y_type, xt;
int i, xt;
wordlist *wwl;
char *nxlabel = NULL, *nylabel = NULL, *ntitle = NULL;
double tstep, tstart, tstop, ttime;
@ -1080,7 +1077,7 @@ bool plotit(wordlist *wl, const char *hcopy, const char *devname)
}
}
y_type = d ? SV_NOTYPE : vecs->v_type;
const int y_type = (int) (d ? SV_NOTYPE : vecs->v_type);
if (devname && eq(devname, "gnuplot")) {
/* Interface to Gnuplot Plot Program */

View File

@ -2,5 +2,5 @@
#define ngspice_PLOTIT_H
bool plotit(wordlist *wl, const char *hcopy, const char *devname);
void pl_rempar(void);
#endif

View File

@ -237,7 +237,11 @@ initcolors(GRAPH *graph)
"yellow", ""
};
XColor visualcolor, exactcolor, bgcolor;
XColor visualcolor, exactcolor;
/* Silence incorrect compiler warning about possibly not being init */
XColor bgcolor = {0};
char buf[BSIZE_SP], colorstring[BSIZE_SP];
int xmaxcolors = NUMCOLORS; /* note: can we get rid of this? */
@ -273,9 +277,9 @@ initcolors(GRAPH *graph)
t3 = copy(tmpstr);
if (t1 && t2 && t3) {
double c1, c2, c3;
c1 = strtol(t1, NULL, 10) / 255.;
c2 = strtol(t2, NULL, 10) / 255.;
c3 = strtol(t3, NULL, 10) / 255.;
c1 = (double) strtol(t1, NULL, 10) / 255.;
c2 = (double) strtol(t2, NULL, 10) / 255.;
c3 = (double) strtol(t3, NULL, 10) / 255.;
c1 = fmax(0., fmin(c1, 1.));
c2 = fmax(0., fmin(c2, 1.));
c3 = fmax(0., fmin(c3, 1.));
@ -310,7 +314,8 @@ initcolors(GRAPH *graph)
/* select grid color according to background color.
Empirical selection using the color depth of the background */
/* switch the grid and text color depending on background */
int tcolor = (int)bgcolor.red + (int)(1.5 * bgcolor.green) + (int)bgcolor.blue;
int tcolor = (int) bgcolor.red +
(int) (1.5 * bgcolor.green) + (int) bgcolor.blue;
if (tcolor > 92160) {
graph->colorarray[1] = BlackPixel(display, DefaultScreen(display));
strncpy(DEVDEP(graph).txtcolor, "black", 15);
@ -351,7 +356,7 @@ handlekeypressed(Widget w, XtPointer client_data, XEvent *ev, Boolean *continue_
/* write it */
PushGraphContext(graph);
text[nbytes] = '\0';
SetColor(1, graph);
SetColor(1);
DevDrawText(text, keyev->x, graph->absolute.height - keyev->y, 0);
/* save it */
SaveText(graph, text, keyev->x, graph->absolute.height - keyev->y);
@ -652,7 +657,7 @@ X11_Close(void)
int
X11_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
{
if (DEVDEP(currentgraph).isopen)
if (DEVDEP(currentgraph).isopen) {
if (isgrid) {
XDrawLine(display, DEVDEP(currentgraph).window,
DEVDEP(currentgraph).gridgc,
@ -665,6 +670,7 @@ X11_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
x1, currentgraph->absolute.height - y1,
x2, currentgraph->absolute.height - y2);
}
}
return 0;
}
@ -694,25 +700,26 @@ X11_Arc(int x0, int y0, int radius, double theta, double delta_theta)
/* note: x and y are the LOWER left corner of text */
int
X11_Text(char *text, int x, int y, int angle)
X11_Text(const char *text, int x, int y, int angle)
{
/* We specify text position by lower left corner, so have to adjust for
X11's font nonsense. */
int wlen = 0, wheight = 0;
#ifndef HAVE_LIBXFT
if (DEVDEP(currentgraph).isopen)
XDrawString(display, DEVDEP(currentgraph).window,
DEVDEP(currentgraph).gc, x,
currentgraph->absolute.height
- (y + DEVDEP(currentgraph).font->max_bounds.descent),
text, (int) strlen(text));
if (DEVDEP(currentgraph).isopen) {
if (angle != 0) {
fprintf(stderr, " Xft: angles other than 0 are not supported\n");
}
XDrawString(display, DEVDEP(currentgraph).window,
DEVDEP(currentgraph).gc, x,
currentgraph->absolute.height
- (y + DEVDEP(currentgraph).font->max_bounds.descent),
text, (int) strlen(text));
}
/* note: unlike before, we do not save any text here */
/* note: unlike before, we do not save any text here */
#else
/* Draw text */
if(angle == 0) {
if (angle == 0) {
XftDrawStringUtf8(
DEVDEP(currentgraph).draw, &DEVDEP(currentgraph).color, DEVDEP(currentgraph).font0,
x, currentgraph->absolute.height - y, (FcChar8*)text, strlen(text));
@ -838,7 +845,7 @@ X11_SetLinestyle(int linestyleid)
int
X11_SetColor(int colorid, GRAPH *graph)
X11_SetColor(int colorid)
{
currentgraph->currentcolor = colorid;
XSetForeground(display, DEVDEP(currentgraph).gc,

View File

@ -803,13 +803,9 @@ com_cross(wordlist *wl)
vec_remove(newvec);
v = dvec_alloc(copy(newvec),
vecs
? vecs->v_type
: SV_NOTYPE,
comp
? (VF_COMPLEX | VF_PERMANENT)
: (VF_REAL | VF_PERMANENT),
i, NULL);
(int) (vecs ? vecs->v_type : SV_NOTYPE),
comp ? (VF_COMPLEX | VF_PERMANENT) : (VF_REAL | VF_PERMANENT),
i, NULL);
/* Now copy the ind'ths elements into this one. */
for (n = vecs, i = 0; n; n = n->v_link2, i++)

View File

@ -108,7 +108,8 @@ static int maxcolor = 2;
void PS_LinestyleColor(int linestyleid, int colorid);
void PS_SelectColor(int colorid);
void PS_Stroke(void);
size_t utf8_to_latin9(char *const output, const char *const input, const size_t length);
static size_t utf8_to_latin9(char * const output, const char *const input,
const size_t length);
/* Set scale, color and size of the plot */
@ -120,10 +121,15 @@ int PS_Init(void)
if (!cp_getvar("hcopyscale", CP_STRING, psscale, sizeof(psscale))) {
scale = 1.0;
} else {
sscanf(psscale, "%lf", &scale);
if ((scale <= 0) || (scale > 10))
scale = 1.0;
}
else if (sscanf(psscale, "%lf", &scale) != 1) {
(void) fprintf(cp_err, "Error getting scale value\n");
scale = 1.0;
}
else if ((scale <= 0.0) || (scale > 10.0)) {
(void) fprintf(cp_err, "Scale value %lf is out of range\n",
scale);
scale = 1.0;
}
dispdev->numlinestyles = NUMELEMS(linestyle);
/* plot color */
@ -395,12 +401,18 @@ int PS_Arc(int x0, int y0, int r, double theta, double delta_theta)
}
int PS_Text(char *text, int x, int y, int angle)
int PS_Text(const char *text_in, int x, int y, int angle)
{
int savedlstyle, savedcolor;
#ifndef EXT_ASC
utf8_to_latin9(text, text, strlen(text));
char *text;
#ifdef EXT_ASC
text = text_in;
#else
{
const size_t n_char_text = strlen(text_in);
text = TMALLOC(char, n_char_text);
utf8_to_latin9(text, text_in, n_char_text);
}
#endif
/* set linestyle to solid
or may get funny color text on some plotters */
@ -410,12 +422,12 @@ int PS_Text(char *text, int x, int y, int angle)
PS_SetLinestyle(SOLID);
/* set text color to black if background is not white */
if (setbgcolor > 0)
PS_SetColor(0, currentgraph);
PS_SetColor(0);
else
PS_SetColor(1, currentgraph);
PS_SetColor(1);
/* if color is given by set hcopytxpscolor=settxcolor, give it a try */
if (settxcolor >= 0)
PS_SetColor(settxcolor, currentgraph);
PS_SetColor(settxcolor);
/* stroke the path if there's an open one */
PS_Stroke();
/* move to (x, y) */
@ -431,8 +443,13 @@ int PS_Text(char *text, int x, int y, int angle)
/* restore old linestyle */
PS_SetColor(savedcolor, currentgraph);
PS_SetColor(savedcolor);
PS_SetLinestyle(savedlstyle);
#ifndef EXT_ASC
txfree(text);
#endif
return 0;
}
@ -458,9 +475,8 @@ int PS_SetLinestyle(int linestyleid)
}
int PS_SetColor(int colorid, GRAPH *graph)
int PS_SetColor(int colorid)
{
NG_IGNORE(graph);
PS_LinestyleColor(currentgraph->linestyle, colorid);
return 0;
}
@ -600,7 +616,8 @@ static inline unsigned int to_latin9(const unsigned int code)
* Output has to have room for (length+1) chars, including the trailing NUL byte.
from http://stackoverflow.com/questions/11156473/is-there-a-way-to-convert-from-utf8-to-iso-8859-1#11173493
*/
size_t utf8_to_latin9(char *const output, const char *const input, const size_t length)
size_t utf8_to_latin9(char * const output, const char *const input,
const size_t length)
{
unsigned char *out = (unsigned char *)output;
const unsigned char *in = (const unsigned char *)input;

View File

@ -464,7 +464,11 @@ raw_read(char *name) {
}
s = SKIP(buf);
if (!*s) {
(void) fgets(buf, BSIZE_SP, fp);
if (fgets(buf, BSIZE_SP, fp) == (char *) NULL) {
fprintf(cp_err, "Error: unable to read line\n");
plots = NULL;
break;
}
s = buf;
}
if (numdims == 0) {
@ -490,7 +494,10 @@ raw_read(char *name) {
if (!i) {
curpl->pl_scale = v;
} else {
(void) fgets(buf, BSIZE_SP, fp);
if (fgets(buf, BSIZE_SP, fp) == (char *) NULL) {
fprintf(cp_err, "Error: unable to read variable line\n");
break;
}
s = buf;
}
s = nexttok(s); /* The strchr field. */
@ -591,7 +598,10 @@ raw_read(char *name) {
for (i = 0; i < npoints; i++) {
if (is_ascii) {
/* It's an ASCII file. */
(void) fscanf(fp, " %d", &j);
if (fscanf(fp, " %d", &j) != 1) {
fprintf(cp_err, "Error: unable to read point count\n");
break;
}
for (v = curpl->pl_dvecs; v; v = v->v_next) {
if (i < v->v_length) {
if (flags & VF_REAL) {
@ -657,7 +667,7 @@ raw_read(char *name) {
return (NULL);
}
}
}
} /* end of loop */
if (curpl) { /* reverse commands list */
for (wl = curpl->pl_commands, curpl->pl_commands = NULL;

View File

@ -61,13 +61,15 @@ static void fprintmem(FILE *stream, unsigned long long memory);
#if defined(HAVE_WIN32) || defined(HAVE__PROC_MEMINFO)
static int get_procm(struct proc_mem *memall);
static int get_sysmem(struct sys_mem *memall);
struct sys_mem mem_t, mem_t_act;
struct proc_mem mem_ng, mem_ng_act;
#endif
#if defined(HAVE_WIN32) && defined(SHARED_MODULE) && defined(__MINGW32__)
static int get_sysmem(struct sys_mem *memall);
#endif
void
init_rlimits(void)
@ -431,10 +433,13 @@ static int get_procm(struct proc_mem *memall) {
} else
return 0;
#else
/* Use Windows GlobalMemoryStatus or /proc/memory to obtain size of memory - not accurate */
get_sysmem(&mem_t_act); /* size is the difference between free memory at start time and now */
/* Use Windows GlobalMemoryStatus or /proc/memory to obtain size of memory -
* not accurate */
get_sysmem(&mem_t_act); /* size is the difference between free memory at
* start time and now */
if (mem_t.free > mem_t_act.free) /* it can happen that that ngspice is */
memall->size = (mem_t.free - mem_t_act.free); /* to small compared to os memory usage */
memall->size = (mem_t.free - mem_t_act.free); /* too small compared to
* os memory usage */
else
memall->size = 0; /* sure, it is more */
memall->resident = 0;
@ -476,8 +481,8 @@ static int get_procm(struct proc_mem *memall) {
}
static int
get_sysmem(struct sys_mem *memall)
#if defined(HAVE_WIN32) && defined(SHARED_MODULE) && defined(__MINGW32__)
static int get_sysmem(struct sys_mem *memall)
{
#ifdef HAVE_WIN32
#if (_WIN32_WINNT >= 0x0500)
@ -542,6 +547,7 @@ get_sysmem(struct sys_mem *memall)
#endif
return 1;
}
#endif
#else

View File

@ -6,6 +6,8 @@
#ifndef ngspice_RESOURCE_H
#define ngspice_RESOURCE_H
#include "ngspice/wordlist.h"
extern unsigned long long getMemorySize(void);
extern unsigned long long getPeakRSS(void);
extern unsigned long long getCurrentRSS(void);

View File

@ -1386,7 +1386,11 @@ void com_snload(wordlist *wl)
return;
}
fread(&tmpI, sizeof(int), 1, file);
if (fread(&tmpI, sizeof(int), 1, file) != 1) {
(void) fprintf(cp_err, "Unable to read spice version from snapshot.\n");
fclose(file);
return;
}
if (tmpI != sizeof(CKTcircuit)) {
fprintf(cp_err, "loaded num: %d, expected num: %ld\n", tmpI, (long)sizeof(CKTcircuit));
fprintf(cp_err, "Error: snapshot saved with different version of spice\n");
@ -1396,7 +1400,11 @@ void com_snload(wordlist *wl)
my_ckt = TMALLOC(CKTcircuit, 1);
fread(my_ckt, sizeof(CKTcircuit), 1, file);
if (fread(my_ckt, sizeof(CKTcircuit), 1, file) != 1) {
(void) fprintf(cp_err, "Unable to read spice circuit from snapshot.\n");
fclose(file);
return;
}
#define _t(name) ckt->name = my_ckt->name
#define _ta(name, size) \
@ -1484,17 +1492,24 @@ void com_snload(wordlist *wl)
#define _foo(name, type, _size) \
do { \
int __i; \
fread(&__i, sizeof(int), 1, file); \
if (__i) { \
if (name) \
tfree(name); \
name = (type *)tmalloc((size_t) __i); \
fread(name, 1, (size_t) __i, file); \
} else { \
if (fread(&__i, sizeof(int), 1, file) == 1 && __i > 0) { \
if (name) { \
txfree(name); \
} \
name = (type *) tmalloc((size_t) __i); \
if (fread(name, 1, (size_t) __i, file) != (size_t) __i) { \
(void) fprintf(cp_err, \
"Unable to read vector " #name "\n"); \
break; \
} \
} \
else { \
fprintf(cp_err, "size for vector " #name " is 0\n"); \
} \
if ((_size) != -1 && __i != (_size) * (int)sizeof(type)) { \
fprintf(cp_err, "expected %ld, but got %d for "#name"\n", (_size)*(long)sizeof(type), __i); \
if ((_size) != -1 && __i != \
(int) (_size) * (int) sizeof(type)) { \
fprintf(cp_err, "expected %ld, but got %d for "#name"\n", \
(_size)*(long)sizeof(type), __i); \
} \
} while(0)

View File

@ -21,14 +21,12 @@ Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
#include <sys/ioctl.h>
#endif
#if 0
/* Bad interaction with bool type in bool.h because curses also
defines this symbol. */
#ifdef HAVE_TERMCAP
#include <curses.h>
#include <term.h>
#endif
#endif
#ifdef HAVE_TERMCAP_H
#include <termcap.h>
@ -129,7 +127,7 @@ outbufputc(void)
{
if (ourbuf.count != BUFSIZ) {
fputs(staticbuf, cp_out);
memset(staticbuf, 0, (size_t) BUFSIZ - ourbuf.count);
memset(staticbuf, 0, (size_t) (BUFSIZ - ourbuf.count));
ourbuf.count = BUFSIZ;
ourbuf.ptr = staticbuf;
}

View File

@ -75,7 +75,7 @@ static struct plotab plotabs[NUMPLOTTYPES] = {
{ "ac", "ac", FALSE, FALSE },
{ "pz", "pz", FALSE, FALSE },
{ "pz", "p.z.", FALSE, FALSE },
{ "pz", "pole-zero", FALSE},
{ "pz", "pole-zero", FALSE, FALSE},
{ "disto", "disto", FALSE, FALSE },
{ "dist", "dist", FALSE, FALSE },
{ "noise", "noise", FALSE, FALSE },

View File

@ -463,7 +463,8 @@ struct dvec *vec_fromplot(char *word, struct plot *plot) {
DS_CREATE(ds, 100);
const char * const node_start = word + 2;
bool ds_ok = ds_cat_mem(&ds, node_start,
p_last_close_paren - node_start) == DS_E_OK;
(size_t) (p_last_close_paren - node_start)) ==
DS_E_OK;
/* If i(node) or I(node), append #branch */
if (tolower(word[0]) == (int) 'i') {
/* i(node) or I(node) */
@ -809,7 +810,8 @@ struct dvec *vec_copy(struct dvec *v) {
nv->v_numdims = v->v_numdims;
/* Copy defined dimensions */
(void) memcpy(nv->v_dims, v->v_dims, v->v_numdims * sizeof *v->v_dims);
(void) memcpy(nv->v_dims, v->v_dims,
(size_t) v->v_numdims * sizeof *v->v_dims);
nv->v_plot = v->v_plot;
nv->v_next = NULL;
@ -1286,10 +1288,10 @@ vec_mkfamily(struct dvec *v) {
d->v_dims[0] = size;
if (isreal(v)) {
memcpy(d->v_realdata, v->v_realdata + (size_t) size * i,
memcpy(d->v_realdata, v->v_realdata + (size_t) (size * i),
(size_t) size * sizeof(double));
} else {
memcpy(d->v_compdata, v->v_compdata + (size_t) size * i,
memcpy(d->v_compdata, v->v_compdata + (size_t) (size * i),
(size_t) size * sizeof(ngcomplex_t));
}
/* Add one to the counter. */

View File

@ -693,16 +693,17 @@ int WIN_NewViewport(GRAPH *graph)
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
#else
/* UTF-8 support */
wchar_t *wtext, *wtext2;
wtext = TMALLOC(wchar_t, 2 * strlen(graph->plotname) + 1);
wtext2 = TMALLOC(wchar_t, 2 * strlen(WindowName) + 1);
const int n_byte_wide = 2 * (int) strlen(graph->plotname) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
const int n_byte_wide2 = 2 * (int) strlen(WindowName) + 1;
wchar_t * const wtext2 = TMALLOC(wchar_t, n_byte_wide2);
/* translate UTF-8 to UTF-16 */
MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, 2 * strlen(graph->plotname) + 1);
MultiByteToWideChar(CP_UTF8, 0, WindowName, -1, wtext2, 2 * strlen(WindowName) + 1);
MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, n_byte_wide);
MultiByteToWideChar(CP_UTF8, 0, WindowName, -1, wtext2, n_byte_wide2);
window = CreateWindowW(wtext2, wtext, WS_OVERLAPPEDWINDOW,
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
tfree(wtext);
tfree(wtext2);
txfree(wtext);
txfree(wtext2);
#endif
if (!window)
return 1;
@ -733,7 +734,7 @@ int WIN_NewViewport(GRAPH *graph)
wd->PaintFlag = 0;
wd->FirstFlag = 1;
/* modify system menue */
/* modify system menu */
sysmenu = GetSystemMenu(window, FALSE);
AppendMenu(sysmenu, MF_SEPARATOR, 0, NULL);
AppendMenu(sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN);
@ -956,7 +957,7 @@ WIN_Text_old(char *text, int x, int y, int degrees)
#endif
int WIN_Text(char *text, int x, int y, int angle)
int WIN_Text(const char *text, int x, int y, int angle)
{
tpWindowData wd;
HFONT hfont;
@ -1042,11 +1043,12 @@ int WIN_Text(char *text, int x, int y, int angle)
#ifdef EXT_ASC
TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text));
#else
wchar_t *wtext;
wtext = TMALLOC(wchar_t, 2 * strlen(text) + 1);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, 2 * strlen(text) + 1);
TextOutW(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, wtext, 2 * (int)strlen(text) + 1);
tfree(wtext);
const int n_byte_wide = 2 * (int) strlen(text) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide);
TextOutW(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight,
wtext, n_byte_wide);
txfree(wtext);
#endif
DeleteObject(SelectObject(wd->hDC, hfont));
@ -1079,9 +1081,8 @@ int WIN_SetLinestyle(int style)
}
int WIN_SetColor(int color, GRAPH *graph)
int WIN_SetColor(int color)
{
NG_IGNORE(graph);
tpWindowData wd;
if (!currentgraph)

View File

@ -294,13 +294,15 @@ int WPRINT_NewViewport(GRAPH * graph)
TextOut(PrinterDC, PrinterWidth - graph->fontwidth, 1, graph->plotname,
(int)strlen(graph->plotname));
#else
wchar_t* wtext;
wtext = TMALLOC(wchar_t, 2 * strlen(graph->plotname) + 1);
MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, 2 * strlen(graph->plotname) + 1);
TextOutW(PrinterDC, PrinterWidth - graph->fontwidth, 1, wtext, 2 * (int)strlen(graph->plotname) + 1);
tfree(wtext);
const int n_byte_wide = 2 * (int) strlen(graph->plotname) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext,
n_byte_wide);
TextOutW(PrinterDC, PrinterWidth - graph->fontwidth, 1, wtext,
n_byte_wide);
txfree(wtext);
#endif
SetTextAlign( PrinterDC, align);
SetTextAlign(PrinterDC, align);
}
/* fertig */
@ -431,11 +433,12 @@ int WPRINT_Text(char * text, int x, int y, int degrees)
#ifdef EXT_ASC
TextOut(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, text, (int)strlen(text));
#else
wchar_t* wtext;
wtext = TMALLOC(wchar_t, 2 * strlen(text) + 1);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, 2 * strlen(text) + 1);
TextOutW(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, wtext, 2 * (int)strlen(text) + 1);
tfree(wtext);
const int n_byte_wide = 2 * (int) strlen(text) + 1;
wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide);
TextOutW(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight,
wtext, n_byte_wide);
txfree(wtext);
#endif
return (0);
}

View File

@ -7,9 +7,12 @@
#ifndef ngspice_CIDERSUPT_H
#define ngspice_CIDERSUPT_H
#include "ngspice/numglobs.h"
#include "ngspice/material.h"
#include <stdio.h>
#include "ngspice/bool.h"
#include "ngspice/gendev.h"
#include "ngspice/material.h"
#include "ngspice/numglobs.h"
#include "ngspice/profile.h"
/* externals for database.c */
@ -60,21 +63,21 @@ extern void printMaterialInfo(MaterialInfo * );
/* externals for mobil.c */
extern void MOBdefaults(MaterialInfo *, int, int, int, int );
extern void MOBtempDep (MaterialInfo *, double );
extern void MOBconcDep (MaterialInfo *, double, double *, double *);
extern void MOBfieldDep (MaterialInfo *, int, double, double *, double * );
extern void MOBtempDep(MaterialInfo *, double );
extern void MOBconcDep(MaterialInfo *, double, double *, double *);
extern void MOBfieldDep(MaterialInfo *, int, double, double *, double * );
/* externals for recomb.c */
extern void recomb (double, double, double, double, double, double,
extern void recomb(double, double, double, double, double, double,
double, double *, double *, double * );
/* externals for suprem.c */
extern void readAsciiData( char *, int, DOPtable ** );
extern void readSupremData( char *, int, int, DOPtable ** );
extern int readAsciiData(const char *, int, DOPtable **);
extern int readSupremData(const char *, int, int, DOPtable ** );
/* externals for suprmitf.c */
extern void SUPbinRead( char *, float *, float *, int *, int * );
extern void SUPascRead( char *, float *, float *, int *, int * );
extern int SUPbinRead(const char *, float *, float *, int *, int *);
extern int SUPascRead(const char *, float *, float *, int *, int *);

View File

@ -114,8 +114,6 @@ int cm_message_printf(const char *fmt, ...)
int cm_message_printf(const char *fmt, ...);
#endif
#ifndef CM_IGNORE
#define CM_IGNORE(x) (x)
#endif
#define CM_IGNORE(x) (void) (x)
#endif
#endif /* include guard */

View File

@ -69,13 +69,17 @@ typedef struct {
#endif
/* Some defines used mainly in cmath.c. */
#define cph(c) (atan2(imagpart(c), (realpart(c))))
#define cmag(c) (hypot(realpart(c), imagpart(c)))
#define cph(c) (atan2(imagpart(c), (realpart(c))))
#define cmag(c) (hypot(realpart(c), imagpart(c)))
#define radtodeg(c) (cx_degrees ? ((c) * (180 / M_PI)) : (c))
#define degtorad(c) (cx_degrees ? ((c) * (M_PI / 180)) : (c))
#define rcheck(cond, name) if (!(cond)) { \
fprintf(cp_err, "Error: argument out of range for %s\n", name); \
return (NULL); }
#define rcheck(cond, name)\
if (!(cond)) {\
(void) fprintf(cp_err, "Error: argument out of range for %s\n",\
name);\
xrc = -1;\
goto EXITPOINT;\
}
#define cdiv(r1, i1, r2, i2, r3, i3) \

View File

@ -41,7 +41,7 @@ struct comm {
int co_maxargs;
/* The fn that prompts the user. */
void (*co_argfn) (wordlist *wl, struct comm *command);
void (*co_argfn)(const wordlist *wl, const struct comm *command);
/* When these are printed, printf(string, av[0]) .. */
char *co_help;

View File

@ -26,7 +26,6 @@ Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
/* Externs defined in std.c */
extern char *tildexpand(const char *string);
extern void printnum(char *buf, double num);
int printnum_ds(DSTRING *p_ds, double num);
extern int cp_numdgt;

View File

@ -55,15 +55,15 @@ typedef struct SPICEdev {
/* routine to input a paramater to a model */
int (*DEVload)(GENmodel*,CKTcircuit*);
/* routine to load the device into the matrix */
int (*DEVsetup)(SMPmatrix*,GENmodel*,CKTcircuit*,int*);
int (*DEVsetup)(SMPmatrix *, GENmodel *, CKTcircuit *, int *);
/* setup routine to preprocess devices once before soloution begins */
int (*DEVunsetup)(GENmodel*,CKTcircuit*);
/* clean up before running again */
int (*DEVpzSetup)(SMPmatrix*,GENmodel*,CKTcircuit*,int*);
int (*DEVpzSetup)(SMPmatrix *, GENmodel *, CKTcircuit *, int *);
/* setup routine to process devices specially for pz analysis */
int (*DEVtemperature)(GENmodel*,CKTcircuit*);
int (*DEVtemperature)(GENmodel*,CKTcircuit*);
/* subroutine to do temperature dependent setup processing */
int (*DEVtrunc)(GENmodel*,CKTcircuit*,double*);
int (*DEVtrunc)(GENmodel*,CKTcircuit*,double*);
/* subroutine to perform truncation error calc. */
int (*DEVfindBranch)(CKTcircuit*,GENmodel*,IFuid);
/* subroutine to search for device branch eq.s */

View File

@ -10,6 +10,9 @@ Author: 1987 Jeffrey M. Hsu
#ifndef ngspice_FTEDEV_H
#define ngspice_FTEDEV_H
#include "ngspice/bool.h"
#include "ngspice/typedefs.h"
struct graph;
struct request;
struct response;
@ -20,11 +23,11 @@ typedef int disp_fn_Close_t (void);
typedef int disp_fn_Clear_t (void);
typedef int disp_fn_DrawLine_t (int x1, int y1, int x2, int y2, bool isgrid);
typedef int disp_fn_Arc_t (int x0, int y0, int radius, double theta, double delta_theta);
typedef int disp_fn_Text_t (char *text, int x, int y, int angle);
typedef int disp_fn_Text_t (const char *text, int x, int y, int angle);
typedef int disp_fn_DefineColor_t (int colorid, double red, double green, double blue);
typedef int disp_fn_DefineLinestyle_t (int linestyleid, int mask);
typedef int disp_fn_SetLinestyle_t (int linestyleid);
typedef int disp_fn_SetColor_t (int colorid, GRAPH *graf);
typedef int disp_fn_SetColor_t (int colorid);
typedef int disp_fn_Update_t (void);
typedef int disp_fn_Track_t (void);
typedef int disp_fn_MakeMenu_t (void);

View File

@ -156,7 +156,7 @@ extern char *MIFcopy(const char *);
#ifndef CM_IGNORE
#define CM_IGNORE(x) (x)
#define CM_IGNORE(x) (void) (x)
#endif
#endif
#endif /* include guard */

View File

@ -544,14 +544,18 @@ prompt(void)
s = "->";
while (*s) {
char c = (char) (*s++);
char c = (*s++);
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (c) {
case '!':
p += sprintf(p, "%d", where_history() + 1);
break;
case '\\':
case '\\': /* skip an escape char */
if (*s)
c = (char) (*s++);
/* FALLTHROUGH */
default:
*p++ = c;
break;
@ -799,8 +803,11 @@ int main(int argc, char **argv)
{
char log_file[BSIZE_SP];
char soa_log_file[BSIZE_SP];
bool readinit = TRUE; /* read initialization file */
bool istty = TRUE;
/* volatile added to resolve GCC -Wclobbered */
volatile bool readinit = TRUE; /* read initialization file */
volatile bool istty = TRUE;
bool iflag = FALSE; /* flag for interactive mode */
bool qflag = FALSE; /* flag for command completion */
@ -910,7 +917,7 @@ int main(int argc, char **argv)
}
else {
DS_CREATE(ds, 100);
if (ds_cat_mem(&ds, optarg, eq - optarg) == 0) {
if (ds_cat_mem(&ds, optarg, (size_t) (eq - optarg)) == 0) {
cp_vset(ds_get_buf(&ds), CP_STRING, eq + 1);
}
ds_free(&ds);

View File

@ -16,6 +16,8 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
*
*/
#include <errno.h>
#include "ngspice/ngspice.h"
#include "ngspice/memory.h"
#include "ngspice/cpdefs.h"
@ -206,7 +208,7 @@ void *cx_conj(void *data, short int type, int length,
ngcomplex_t * const c_dst = alloc_c(length);
ngcomplex_t *c_dst_cur = c_dst;
ngcomplex_t *c_src_cur = (ngcomplex_t *) data;
ngcomplex_t * const c_src_end = c_src_cur + length;
ngcomplex_t * const c_src_end = c_src_cur + length;
for ( ; c_src_cur < c_src_end; c_src_cur++, c_dst_cur++) {
c_dst_cur->cx_real = c_src_cur->cx_real;
c_dst_cur->cx_imag = -c_src_cur->cx_imag;
@ -215,7 +217,7 @@ void *cx_conj(void *data, short int type, int length,
}
/* Else real, so just copy */
return memcpy(alloc_d(length), data, length * sizeof(double));
return memcpy(alloc_d(length), data, (unsigned int) length * sizeof(double));
} /* end of function cx_conj */
@ -241,20 +243,19 @@ cx_pos(void *data, short int type, int length, int *newlength, short int *newtyp
return ((void *) d);
}
void *
cx_db(void *data, short int type, int length, int *newlength, short int *newtype)
void *cx_db(void *data, short int type, int length,
int *newlength, short int *newtype)
{
int xrc = 0;
double *d = alloc_d(length);
double *dd = (double *) data;
ngcomplex_t *cc = (ngcomplex_t *) data;
double tt;
int i;
*newlength = length;
*newtype = VF_REAL;
if (type == VF_COMPLEX)
if (type == VF_COMPLEX) {
ngcomplex_t *cc = (ngcomplex_t *) data;
int i;
for (i = 0; i < length; i++) {
tt = cmag(cc[i]);
const double tt = cmag(cc[i]);
rcheck(tt > 0, "db");
/*
if (tt == 0.0)
@ -263,29 +264,44 @@ cx_db(void *data, short int type, int length, int *newlength, short int *newtype
*/
d[i] = 20.0 * log10(tt);
}
else
}
else {
double *dd = (double *) data;
int i;
for (i = 0; i < length; i++) {
rcheck(dd[i] > 0, "db");
const double tt = dd[i];
rcheck(tt > 0, "db");
/*
if (dd[i] == 0.0)
d[i] = 20.0 * - log(HUGE);
else
*/
d[i] = 20.0 * log10(dd[i]);
d[i] = 20.0 * log10(tt);
}
return ((void *) d);
}
}
void *
cx_log10(void *data, short int type, int length, int *newlength, short int *newtype)
EXITPOINT:
if (xrc != 0) {
txfree(d);
d = (double *) NULL;
}
return ((void *) d);
} /* end of function cx_db */
void *cx_log10(void *data, short int type, int length,
int *newlength, short int *newtype)
{
*newlength = length;
int xrc = 0;
void *rv;
if (type == VF_COMPLEX) {
ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data;
int i;
c = alloc_c(length);
rv = c = alloc_c(length);
*newtype = VF_COMPLEX;
for (i = 0; i < length; i++) {
double td;
@ -298,42 +314,58 @@ cx_log10(void *data, short int type, int length, int *newlength, short int *newt
if (td == 0.0) {
realpart(c[i]) = - log10(HUGE);
imagpart(c[i]) = 0.0;
} else {
}
else {
realpart(c[i]) = log10(td);
imagpart(c[i]) = atan2(imagpart(cc[i]),
realpart(cc[i]));
imagpart(c[i]) = atan2(imagpart(cc[i]), realpart(cc[i]));
}
}
return ((void *) c);
} else {
}
else {
double *d;
double *dd = (double *) data;
int i;
d = alloc_d(length);
rv = d = alloc_d(length);
*newtype = VF_REAL;
for (i = 0; i < length; i++) {
rcheck(dd[i] >= 0, "log10");
if (dd[i] == 0.0)
if (dd[i] == 0.0) {
d[i] = - log10(HUGE);
else
}
else {
d[i] = log10(dd[i]);
}
}
return ((void *) d);
}
}
void *
cx_log(void *data, short int type, int length, int *newlength, short int *newtype)
{
*newlength = length;
EXITPOINT:
if (xrc != 0) { /* Free resources on error */
txfree(rv);
rv = NULL;
}
return rv;
} /* end of function cx_log10 */
void *cx_log(void *data, short int type, int length,
int *newlength, short int *newtype)
{
int xrc = 0;
void *rv;
if (type == VF_COMPLEX) {
ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data;
int i;
c = alloc_c(length);
rv = c = alloc_c(length);
*newtype = VF_COMPLEX;
int i;
for (i = 0; i < length; i++) {
double td;
@ -342,20 +374,21 @@ cx_log(void *data, short int type, int length, int *newlength, short int *newtyp
if (td == 0.0) {
realpart(c[i]) = - log(HUGE);
imagpart(c[i]) = 0.0;
} else {
}
else {
realpart(c[i]) = log(td);
imagpart(c[i]) = atan2(imagpart(cc[i]),
realpart(cc[i]));
imagpart(c[i]) = atan2(imagpart(cc[i]), realpart(cc[i]));
}
}
return ((void *) c);
} else {
}
else {
double *d;
double *dd = (double *) data;
int i;
d = alloc_d(length);
rv = d = alloc_d(length);
*newtype = VF_REAL;
int i;
for (i = 0; i < length; i++) {
rcheck(dd[i] >= 0, "log");
if (dd[i] == 0.0)
@ -363,9 +396,20 @@ cx_log(void *data, short int type, int length, int *newlength, short int *newtyp
else
d[i] = log(dd[i]);
}
return ((void *) d);
}
}
*newlength = length;
EXITPOINT:
if (xrc != 0) { /* Free resources on error */
txfree(rv);
rv = NULL;
}
return rv;
} /* end of function cx_log */
void *
cx_exp(void *data, short int type, int length, int *newlength, short int *newtype)
@ -614,19 +658,29 @@ cx_cosh(void *data, short int type, int length, int *newlength, short int *newty
}
}
static double *
d_tan(double *dd, int length)
{
double *d;
int i;
d = alloc_d(length);
static double *d_tan(double *dd, int length)
{
int xrc = 0;
double *d = alloc_d(length);
int i;
for (i = 0; i < length; i++) {
rcheck(tan(degtorad(dd[i])) != 0, "tan");
d[i] = tan(degtorad(dd[i]));
}
EXITPOINT:
if (xrc != 0) { /* Free resources on error */
txfree(d);
d = (double *) NULL;
}
return d;
}
} /* end of function d_tan */
static double *
d_tanh(double *dd, int length)
@ -641,64 +695,94 @@ d_tanh(double *dd, int length)
return d;
}
static ngcomplex_t *
c_tan(ngcomplex_t *cc, int length)
/* See https://proofwiki.org/wiki/Tangent_of_Complex_Number (formulation 4) among
* others for the tangent formula:
* sin z = sin(x + iy) = sin x cos(iy) + cos x sin(iy) = sin x cosh y + i cos x sinh y
* cos z = cos(x + iy) = cos x cos(iy) + sin x sin(iy) = cos x cosh y - i sin x sinh y
* tan z = ((sin x cosh y + i cos x sinh y) / (cos x cosh y - i sin x sinh y)) *
(cos x cosh y + isin x sinh y) / (cos x cosh y + i sin x sinh y)
= ...
*
*
* tan(a + bi) = (sin(2a) + i * sinh(2b)) / (cos(2a) + cosh(2b))
*/
static ngcomplex_t *c_tan(ngcomplex_t *cc, int length)
{
ngcomplex_t *c;
ngcomplex_t * const c = alloc_c(length);
int i;
c = alloc_c(length);
for (i = 0; i < length; i++) {
double u, v;
rcheck(cos(degtorad(realpart(cc[i]))) *
cosh(degtorad(imagpart(cc[i]))), "tan");
rcheck(sin(degtorad(realpart(cc[i]))) *
sinh(degtorad(imagpart(cc[i]))), "tan");
u = degtorad(realpart(cc[i]));
v = degtorad(imagpart(cc[i]));
/* The Lattice C compiler won't take multi-line macros, and
* CMS won't take >80 column lines....
*/
#define xx1 sin(u) * cosh(v)
#define xx2 cos(u) * sinh(v)
#define xx3 cos(u) * cosh(v)
#define xx4 -sin(u) * sinh(v)
cdiv(xx1, xx2, xx3, xx4, realpart(c[i]), imagpart(c[i]));
}
return c;
}
/* complex tanh function, uses tanh(z) = -i * tan (i * z) */
static ngcomplex_t *
c_tanh(ngcomplex_t *cc, int length)
{
ngcomplex_t *c, *s, *t;
int i;
c = alloc_c(length);
s = alloc_c(1);
t = alloc_c(1);
for (i = 0; i < length; i++) {
/* multiply by i */
t[0].cx_real = -1. * imagpart(cc[i]);
t[0].cx_imag = realpart(cc[i]);
/* get complex tangent */
s = c_tan(t, 1);
/* if check in c_tan fails */
if (s == NULL) {
tfree(t);
return (NULL);
errno = 0;
ngcomplex_t *p_dst = c + i;
ngcomplex_t *p_src = cc + i;
const double a = p_src->cx_real;
const double b = p_src->cx_imag;
const double u = 2 * degtorad(a);
const double v = 2 * degtorad(b);
const double n_r = sin(u);
const double n_i = sinh(v);
const double d1 = cos(u);
const double d2 = cosh(v);
const double d = d1 + d2;
if (errno != 0 || d == 0.0) {
(void) fprintf(cp_err,
"Invalid argument %lf + %lf i for compex tangent", a, b);
txfree(c);
return (ngcomplex_t *) NULL;
}
/* multiply by -i */
realpart(c[i]) = imagpart(s[0]);
imagpart(c[i]) = -1. * realpart(s[0]);
}
tfree(s);
tfree(t);
p_dst->cx_real = n_r / d;
p_dst->cx_imag = n_i / d;
} /* end of loop over elements in array */
return c;
}
} /* end of function c_tan */
/* complex tanh function, uses tanh(z) = -i * tan(i * z).
* Unfortunately, it did so very inefficiently (a memory allocations per
* value calculated!) and leaked memory badly (all of the aforementioned
* allocations.) These issues were fixed 2020-03-04 */
static ngcomplex_t *c_tanh(ngcomplex_t *cc, int length)
{
ngcomplex_t * const tmp = alloc_c(length); /* i * z */
/* Build the i * z array to allow tan() to be called */
{
int i;
for (i = 0; i < length; ++i) {
ngcomplex_t *p_dst = tmp + i;
ngcomplex_t *p_src = cc + i;
/* multiply by i */
p_dst->cx_real = -p_src->cx_imag;
p_dst->cx_imag = p_src->cx_real;
}
}
/* Calculat tan(i * z), exiting on failure */
ngcomplex_t *const c = c_tan(tmp, length);
if (c == (ngcomplex_t *) NULL) {
txfree(tmp);
return (ngcomplex_t *) NULL;
}
/* Multiply by -i to find final result */
{
int i;
for (i = 0; i < length; ++i) {
ngcomplex_t *p_cur = c + i;
const double cx_real = p_cur->cx_real;
p_cur->cx_real = p_cur->cx_imag;
p_cur->cx_imag = -cx_real;
}
}
return c;
} /* end of function c_tanh */
void *
cx_tan(void *data, short int type, int length, int *newlength, short int *newtype)
@ -770,8 +854,8 @@ cx_sortorder(void *data, short int type, int length, int *newlength, short int *
double *dd = (double *) data;
int i;
amplitude_index_t *array_amplitudes;
array_amplitudes = (amplitude_index_t *) tmalloc(sizeof(amplitude_index_t) * (size_t) length);
amplitude_index_t * const array_amplitudes = (amplitude_index_t *)
tmalloc(sizeof(amplitude_index_t) * (size_t) length);
*newlength = length;
*newtype = VF_REAL;
@ -788,7 +872,7 @@ cx_sortorder(void *data, short int type, int length, int *newlength, short int *
d[i] = array_amplitudes[i].index;
}
tfree(array_amplitudes);
txfree(array_amplitudes);
/* Otherwise it is 0, but tmalloc zeros the stuff already. */
return ((void *) d);

View File

@ -361,11 +361,17 @@ cx_avg(void *data, short int type, int length, int *newlength, short int *newtyp
/* Compute the mean of a vector. */
void *
cx_mean(void *data, short int type, int length, int *newlength, short int *newtype)
void *cx_mean(void *data, short int type, int length,
int *newlength, short int *newtype)
{
if (length == 0) {
(void) fprintf(cp_err, "mean calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = 1;
rcheck(length > 0, "mean");
if (type == VF_REAL) {
double *d;
double *dd = (double *) data;
@ -377,7 +383,8 @@ cx_mean(void *data, short int type, int length, int *newlength, short int *newty
*d += dd[i];
*d /= length;
return ((void *) d);
} else {
}
else {
ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data;
int i;
@ -397,43 +404,59 @@ cx_mean(void *data, short int type, int length, int *newlength, short int *newty
/* Compute the standard deviation of all elements of a vector. */
void *
cx_stddev(void *data, short int type, int length, int *newlength, short int *newtype)
void *cx_stddev(void *data, short int type, int length,
int *newlength, short int *newtype)
{
if (length == 0) {
(void) fprintf(cp_err, "standard deviation calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = 1;
rcheck(length > 1, "stddev");
if (type == VF_REAL) {
double *mean = (double *)cx_mean(data, type, length, newlength, newtype);
double *d, sum = 0.;
double *dd = (double *)data;
int i;
double *p_mean = (double *) cx_mean(data, type, length,
newlength, newtype);
double mean = *p_mean;
double *d, sum = 0.0;
double *dd = (double *) data;
d = alloc_d(1);
*newtype = VF_REAL;
for (i = 0; i < length; i++)
sum += (dd[i] - *mean) * (dd[i] - *mean);
int i;
for (i = 0; i < length; i++) {
const double tmp = dd[i] - mean;
sum += tmp * tmp;
}
*d = sqrt(sum / ((double) length - 1.0));
tfree(mean);
return ((void *)d);
txfree(p_mean);
return (void *) d;
}
else {
ngcomplex_t *cmean = (ngcomplex_t *)cx_mean(data, type, length, newlength, newtype);
double *d, sum = 0., a, b;
ngcomplex_t *cc = (ngcomplex_t *)data;
int i;
ngcomplex_t * const p_cmean = (ngcomplex_t *) cx_mean(data, type, length,
newlength, newtype);
const ngcomplex_t cmean = *p_cmean;
const double rmean = realpart(cmean);
const double imean = imagpart(cmean);
double *d, sum = 0.0;
ngcomplex_t *cc = (ngcomplex_t *) data;
d = alloc_d(1);
*newtype = VF_REAL;
int i;
for (i = 0; i < length; i++) {
a = realpart(cc[i]) - realpart(*cmean);
b = imagpart(cc[i]) - imagpart(*cmean);
const double a = realpart(cc[i]) - rmean;
const double b = imagpart(cc[i]) - imean;
sum += a * a + b * b;
}
*d = sqrt(sum / ((double) length - 1.0));
tfree(cmean);
return ((void *)d);
txfree(p_cmean);
return (void *) d;
}
}
} /* end of function cx_stddev */
void *
@ -635,35 +658,41 @@ cx_times(void *data1, void *data2, short int datatype1, short int datatype2, int
}
void *
cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, int length)
void *cx_mod(void *data1, void *data2, short int datatype1, short int datatype2,
int length)
{
int xrc = 0;
void *rv;
double *dd1 = (double *) data1;
double *dd2 = (double *) data2;
double *d;
ngcomplex_t *cc1 = (ngcomplex_t *) data1;
ngcomplex_t *cc2 = (ngcomplex_t *) data2;
ngcomplex_t *c, c1, c2;
int i, r1, r2, i1, i2, r3, i3;
if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) {
d = alloc_d(length);
double *d;
rv = d = alloc_d(length);
int i;
for (i = 0; i < length; i++) {
r1 = (int)floor(fabs(dd1[i]));
const int r1 = (int) floor(fabs(dd1[i]));
rcheck(r1 > 0, "mod");
r2 = (int)floor(fabs(dd2[i]));
const int r2 = (int)floor(fabs(dd2[i]));
rcheck(r2 > 0, "mod");
r3 = r1 % r2;
const int r3 = r1 % r2;
d[i] = (double) r3;
}
return ((void *) d);
} else {
c = alloc_c(length);
}
else {
ngcomplex_t *c, c1, c2;
ngcomplex_t *cc1 = (ngcomplex_t *) data1;
ngcomplex_t *cc2 = (ngcomplex_t *) data2;
rv = c = alloc_c(length);
int i;
for (i = 0; i < length; i++) {
if (datatype1 == VF_REAL) {
realpart(c1) = dd1[i];
imagpart(c1) = 0.0;
} else {
}
else {
c1 = cc1[i];
}
if (datatype2 == VF_REAL) {
@ -672,34 +701,47 @@ cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, int l
} else {
c2 = cc2[i];
}
r1 = (int)floor(fabs(realpart(c1)));
const int r1 = (int) floor(fabs(realpart(c1)));
rcheck(r1 > 0, "mod");
r2 = (int)floor(fabs(realpart(c2)));
const int r2 = (int) floor(fabs(realpart(c2)));
rcheck(r2 > 0, "mod");
i1 = (int)floor(fabs(imagpart(c1)));
const int i1 = (int) floor(fabs(imagpart(c1)));
rcheck(i1 > 0, "mod");
i2 = (int)floor(fabs(imagpart(c2)));
const int i2 = (int) floor(fabs(imagpart(c2)));
rcheck(i2 > 0, "mod");
r3 = r1 % r2;
i3 = i1 % i2;
const int r3 = r1 % r2;
const int i3 = i1 % i2;
realpart(c[i]) = (double) r3;
imagpart(c[i]) = (double) i3;
}
return ((void *) c);
}
}
EXITPOINT:
if (xrc != 0) { /* Free resources on error */
txfree(rv);
rv = NULL;
}
return rv;
} /* end of function cx_mod */
/* Routoure JM : Compute the max of a vector. */
void *
cx_max(void *data, short int type, int length, int *newlength, short int *newtype)
void *cx_max(void *data, short int type, int length,
int *newlength, short int *newtype)
{
if (length == 0) {
(void) fprintf(cp_err, "maximum calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = 1;
/* test if length >0 et affiche un message d'erreur */
rcheck(length > 0, "mean");
if (type == VF_REAL) {
double largest=0.0;
double largest = 0.0;
double *d;
double *dd = (double *) data;
int i;
@ -707,14 +749,18 @@ cx_max(void *data, short int type, int length, int *newlength, short int *newtyp
d = alloc_d(1);
*newtype = VF_REAL;
largest = dd[0];
for (i = 1; i < length; i++)
if (largest < dd[i])
largest = dd[i];
for (i = 1; i < length; i++) {
const double tmp = dd[i];
if (largest < tmp) {
largest = tmp;
}
}
*d = largest;
return ((void *) d);
} else {
double largest_real=0.0;
double largest_complex=0.0;
return (void *) d;
}
else {
double largest_real = 0.0;
double largest_complex = 0.0;
ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data;
int i;
@ -723,27 +769,37 @@ cx_max(void *data, short int type, int length, int *newlength, short int *newtyp
*newtype = VF_COMPLEX;
largest_real = realpart(*cc);
largest_complex = imagpart(*cc);
for (i = 0; i < length; i++) {
if (largest_real < realpart(cc[i]))
largest_real = realpart(cc[i]);
if (largest_complex < imagpart(cc[i]))
largest_complex = imagpart(cc[i]);
for (i = 1; i < length; i++) {
const double tmpr = realpart(cc[i]);
if (largest_real < tmpr) {
largest_real = tmpr;
}
const double tmpi = imagpart(cc[i]);
if (largest_complex < tmpi) {
largest_complex = tmpi;
}
}
realpart(*c) = largest_real;
imagpart(*c) = largest_complex;
return ((void *) c);
return (void *) c;
}
}
} /* end of function cx_max */
/* Routoure JM : Compute the min of a vector. */
void *
cx_min(void *data, short int type, int length, int *newlength, short int *newtype)
void *cx_min(void *data, short int type, int length,
int *newlength, short int *newtype)
{
if (length == 0) {
(void) fprintf(cp_err, "minimum calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = 1;
/* test if length >0 et affiche un message d'erreur */
rcheck(length > 0, "mean");
if (type == VF_REAL) {
double smallest;
double *d;
@ -753,12 +809,16 @@ cx_min(void *data, short int type, int length, int *newlength, short int *newtyp
d = alloc_d(1);
*newtype = VF_REAL;
smallest = dd[0];
for (i = 1; i < length; i++)
if (smallest > dd[i])
smallest = dd[i];
for (i = 1; i < length; i++) {
const double tmp = dd[i];
if (smallest > tmp) {
smallest = tmp;
}
}
*d = smallest;
return ((void *) d);
} else {
return (void *) d;
}
else {
double smallest_real;
double smallest_complex;
ngcomplex_t *c;
@ -770,26 +830,35 @@ cx_min(void *data, short int type, int length, int *newlength, short int *newtyp
smallest_real = realpart(*cc);
smallest_complex = imagpart(*cc);
for (i = 1; i < length; i++) {
if (smallest_real > realpart(cc[i]))
smallest_real = realpart(cc[i]);
if (smallest_complex > imagpart(cc[i]))
smallest_complex = imagpart(cc[i]);
const double tmpr = realpart(cc[i]);
if (smallest_real > tmpr) {
smallest_real = tmpr;
}
const double tmpi = imagpart(cc[i]);
if (smallest_complex > tmpi) {
smallest_complex = tmpi;
}
}
realpart(*c) = smallest_real;
imagpart(*c) = smallest_complex;
return ((void *) c);
return (void *) c;
}
}
} /* end of function cx_min */
/* Routoure JM : Compute the differential of a vector. */
void *
cx_d(void *data, short int type, int length, int *newlength, short int *newtype)
void *cx_d(void *data, short int type, int length,
int *newlength, short int *newtype)
{
if (length == 0) {
(void) fprintf(cp_err, "differential calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = length;
/* test if length >0 et affiche un message d'erreur */
rcheck(length > 0, "deriv");
if (type == VF_REAL) {
double *d;
double *dd = (double *) data;
@ -799,12 +868,13 @@ cx_d(void *data, short int type, int length, int *newlength, short int *newtype)
*newtype = VF_REAL;
d[0] = dd[1] - dd[0];
d[length-1] = dd[length-1] - dd[length-2];
for (i = 1; i < length - 1; i++)
for (i = 1; i < length - 1; i++) {
d[i] = dd[i+1] - dd[i-1];
}
return ((void *) d);
} else {
return (void *) d;
}
else {
ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data;
int i;
@ -820,11 +890,11 @@ cx_d(void *data, short int type, int length, int *newlength, short int *newtype)
for (i = 1; i < length - 1; i++) {
realpart(c[i]) = realpart(cc[i+1]) - realpart(cc[i-1]);
imagpart(c[i]) = imagpart(cc[i+1]) - imagpart(cc[i-1]);
}
return ((void *) c);
return (void *) c;
}
}
} /* end of function cx_d */
void *

View File

@ -24,50 +24,64 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
static ngcomplex_t *cexp_sp3(ngcomplex_t *c); /* cexp exist's in some newer compiler */
static ngcomplex_t *cln(ngcomplex_t *c);
static ngcomplex_t *ctimes(ngcomplex_t *c1, ngcomplex_t *c2);
static int cln(ngcomplex_t *c, ngcomplex_t *rv);
static void ctimes(ngcomplex_t *c1, ngcomplex_t *c2, ngcomplex_t *rv);
void *
cx_divide(void *data1, void *data2, short int datatype1, short int datatype2, int length)
void *cx_divide(void *data1, void *data2,
short int datatype1, short int datatype2, int length)
{
int xrc = 0;
void *rv;
double *dd1 = (double *) data1;
double *dd2 = (double *) data2;
double *d;
ngcomplex_t *cc1 = (ngcomplex_t *) data1;
ngcomplex_t *cc2 = (ngcomplex_t *) data2;
ngcomplex_t *c, c1, c2;
int i;
if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) {
d = alloc_d(length);
double *d;
rv = d = alloc_d(length);
for (i = 0; i < length; i++) {
rcheck(dd2[i] != 0, "divide");
d[i] = dd1[i] / dd2[i];
}
return ((void *) d);
} else {
c = alloc_c(length);
}
else {
rv = c = alloc_c(length);
for (i = 0; i < length; i++) {
if (datatype1 == VF_REAL) {
realpart(c1) = dd1[i];
imagpart(c1) = 0.0;
} else {
}
else {
c1 = cc1[i];
}
if (datatype2 == VF_REAL) {
realpart(c2) = dd2[i];
imagpart(c2) = 0.0;
} else {
}
else {
c2 = cc2[i];
}
rcheck((realpart(c2) != 0) || (imagpart(c2) != 0), "divide");
#define xx5 realpart(c1)
#define xx6 imagpart(c1)
cdiv(xx5, xx6, realpart(c2), imagpart(c2), realpart(c[i]), imagpart(c[i]));
cdiv(xx5, xx6, realpart(c2), imagpart(c2), realpart(c[i]),
imagpart(c[i]));
}
return ((void *) c);
}
}
EXITPOINT:
if (xrc != 0) { /* Free resources on error */
tfree(rv);
rv = NULL;
}
return rv;
} /* end of function cx_divide */
/* Should just use "j( )" */
/* The comma operator. What this does (unless it is part of the argument
@ -105,58 +119,82 @@ cx_comma(void *data1, void *data2, short int datatype1, short int datatype2, int
return ((void *) c);
}
void *
cx_power(void *data1, void *data2, short int datatype1, short int datatype2, int length)
void *cx_power(void *data1, void *data2,
short int datatype1, short int datatype2, int length)
{
int xrc = 0;
void *rv;
double *dd1 = (double *) data1;
double *dd2 = (double *) data2;
double *d;
ngcomplex_t *cc1 = (ngcomplex_t *) data1;
ngcomplex_t *cc2 = (ngcomplex_t *) data2;
ngcomplex_t *c, c1, c2, *t;
int i;
if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) {
d = alloc_d(length);
double *d;
rv = d = alloc_d(length);
int i;
for (i = 0; i < length; i++) {
rcheck((dd1[i] >= 0) || (floor(dd2[i]) == ceil(dd2[i])), "power");
rcheck((dd1[i] >= 0) || (floor(dd2[i]) == ceil(dd2[i])), "power");
d[i] = pow(dd1[i], dd2[i]);
}
return ((void *) d);
} else {
c = alloc_c(length);
}
else {
ngcomplex_t *cc1 = (ngcomplex_t *) data1;
ngcomplex_t *cc2 = (ngcomplex_t *) data2;
ngcomplex_t *c, c1, c2, *t;
rv = c = alloc_c(length);
int i;
for (i = 0; i < length; i++) {
if (datatype1 == VF_REAL) {
realpart(c1) = dd1[i];
imagpart(c1) = 0.0;
} else {
}
else {
c1 = cc1[i];
}
if (datatype2 == VF_REAL) {
realpart(c2) = dd2[i];
imagpart(c2) = 0.0;
} else {
}
else {
c2 = cc2[i];
}
if ((realpart(c1) == 0.0) && (imagpart(c1) == 0.0)) {
realpart(c[i]) = 0.0;
imagpart(c[i]) = 0.0;
} else { /* if ((imagpart(c1) != 0.0) &&
}
else { /* if ((imagpart(c1) != 0.0) &&
(imagpart(c2) != 0.0)) */
t = cexp_sp3(ctimes(&c2, cln(&c1)));
ngcomplex_t tmp, tmp2;
if (cln(&c1, &tmp) != 0) {
(void) fprintf(cp_err, "power of 0 + i 0 not allowed.\n");
xrc = -1;
goto EXITPOINT;
}
ctimes(&c2, &tmp, &tmp2);
t = cexp_sp3(&tmp2);
c[i] = *t;
/*
} else {
realpart(c[i]) = pow(realpart(c1),
realpart(c2));
imagpart(c[i]) = 0.0;
*/
/*
} else {
realpart(c[i]) = pow(realpart(c1),
realpart(c2));
imagpart(c[i]) = 0.0;
*/
}
}
return ((void *) c);
}
}
EXITPOINT:
if (xrc != 0) { /* Free resources on error */
txfree(rv);
rv = NULL;
}
return rv;
} /* end of function cx_power */
/* These are unnecessary... Only cx_power uses them... */
@ -175,30 +213,35 @@ cexp_sp3(ngcomplex_t *c)
return (&r);
}
static ngcomplex_t *
cln(ngcomplex_t *c)
static int cln(ngcomplex_t *c, ngcomplex_t *rv)
{
static ngcomplex_t r;
double c_r = c->cx_real;
double c_i = c->cx_imag;
rcheck(cmag(*c) != 0, "ln");
realpart(r) = log(cmag(*c));
if (imagpart(*c) != 0.0)
imagpart(r) = atan2(imagpart(*c), realpart(*c));
else
imagpart(r) = 0.0;
return (&r);
}
if (c_r == 0 && c_i == 0) {
(void) fprintf(cp_err, "Complex log of 0 + i0 is undefined.\n");
return -1;
}
static ngcomplex_t *
ctimes(ngcomplex_t *c1, ngcomplex_t *c2)
rv->cx_real = log(cmag(*c));
if (c_i != 0.0) {
rv->cx_imag = atan2(c_i, c_r);
}
else {
rv->cx_imag = 0.0;
}
return 0;
} /* end of functon cln */
static void ctimes(ngcomplex_t *c1, ngcomplex_t *c2, ngcomplex_t *rv)
{
static ngcomplex_t r;
realpart(r) = realpart(*c1) * realpart(*c2) -
rv->cx_real = realpart(*c1) * realpart(*c2) -
imagpart(*c1) * imagpart(*c2);
imagpart(r) = imagpart(*c1) * realpart(*c2) +
rv->cx_imag = imagpart(*c1) * realpart(*c2) +
realpart(*c1) * imagpart(*c2);
return (&r);
return;
}

View File

@ -257,7 +257,7 @@ static inline int product_overflow(size_t a, size_t b, size_t *p_n)
* a * b < a
* a * b < b
*/
if (a == SIZE_MAX && b > 1 || a > 1 && b == SIZE_MAX) {
if ((a == SIZE_MAX && b > 1) || (a > 1 && b == SIZE_MAX)) {
return +1;
}
@ -283,33 +283,5 @@ static void overflow_error(size_t num, size_t size)
} /* end of function overflow_error */
/* strdup must also be serialized since it performs an allocation. Note that
* Microsoft has not had a single-threaded CRT since VS 2005 (Windows XP),
* so, their _strdup can be safely used if desired. */
/* Declared in cmproto.h */
char *tstrdup(const char *str_in)
{
const size_t n_byte_alloc = strlen(str_in); + 1;
char * const str_out = (char *) tmalloc(n_byte_alloc);
/* Program execution would end in tmalloc() if the allocation fails */
return memcpy(str_out, str_in, n_byte_alloc);
} /* end of function tstrdup */
/* Declared in cmproto.h */
char *tstrdup_raw(const char *str_in)
{
const size_t n_byte_alloc = strlen(str_in); + 1;
char * const str_out = (char *) tmalloc_raw(n_byte_alloc);
if (str_out == (char *) NULL) {
return (char *) NULL;
}
return memcpy(str_out, str_in, n_byte_alloc);
} /* end of function tstrdup_raw */
#endif /* #ifndef HAVE_LIBGC */

View File

@ -278,7 +278,7 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg)
/* Else check for buffer large enough and set length if it is */
if ((size_t) rc < n_byte_free) {
p_ds->length += rc;
p_ds->length += (size_t) rc;
return DS_E_OK;
}
@ -286,7 +286,8 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg)
{
/* Double required size to avoid excessive allocations +1 for
* null, which is not included in the count returned by snprintf */
const size_t n_byte_alloc_min = p_ds->length + rc + 1;
const size_t n_byte_alloc_min =
p_ds->length + (size_t) rc + (size_t) 1;
if (ds_reserve_internal(p_ds,
2 * n_byte_alloc_min, n_byte_alloc_min) == DS_E_NO_MEMORY) {
/* vsnprintf may have written bytes to the buffer.
@ -308,7 +309,7 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg)
/* Else update length. No need to check buffer size since it was
* sized to fit the string. */
p_ds->length += rc2;
p_ds->length += (size_t) rc2;
return DS_E_OK;
}
} /* end of function ds_cat_vprintf */

View File

@ -220,9 +220,10 @@ int get_int_n(const char *str, size_t n, int *p_value)
if (!isdigit(ch_cur)) { /* Test for exit due to non-numeric char */
break;
}
/* Compute new value and check for overflow. */
const unsigned int value_new = 10 * value + (ch_cur - '0');
const unsigned int value_new =
10 * value + (unsigned int) (ch_cur - '0');
if (value_new < value) {
return -2;
}
@ -236,7 +237,7 @@ int get_int_n(const char *str, size_t n, int *p_value)
/* Test for overflow.
* If negative, can be 1 greater (-2**n vs 2**n -1) */
if (value - f_neg > (unsigned int) INT_MAX) {
if (value - (unsigned int) f_neg > (unsigned int) INT_MAX) {
return -2;
}
@ -1246,7 +1247,7 @@ static inline const char *next_substr(
for ( ; ; ) {
/* Update hash for next starting point at p_string + 1 */
if ((h_string = (((h_string - (unsigned char) p_string[0] *
msb_factor) << 8) + p_string[n_char_pattern]) %
msb_factor) << 8) + (size_t) p_string[n_char_pattern]) %
KR_MODULUS) > KR_MODULUS) { /* negative value when signed */
h_string += KR_MODULUS;
}

View File

@ -70,7 +70,7 @@ char *tildexpand(const char *string)
string++;
}
const char * const usr_end = string;
const size_t n_char_usr = usr_end - usr_start;
const size_t n_char_usr = (size_t) (usr_end - usr_start);
const size_t n_byte_usr = n_char_usr + 1;
if (n_byte_usr > sizeof buf_fixed) {
buf = TMALLOC(char, n_byte_usr);

View File

@ -27,6 +27,8 @@ CKTdisto (CKTcircuit *ckt, int mode)
int error=0;
int size;
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch(mode) {
case D_SETUP:
@ -63,7 +65,7 @@ CKTdisto (CKTcircuit *ckt, int mode)
case D_RHSF1:
job->Df2given = 0; /* will change if any F2 source is found */
/* FALLTHROUGH */
case D_RHSF2:

View File

@ -34,9 +34,11 @@ SPICEdev ASRCinfo = {
.DEVparam = ASRCparam,
.DEVmodParam = NULL,
.DEVload = ASRCload,
.DEVsetup = ASRCsetup,
.DEVsetup = (int (*)(SMPmatrix *matrix, GENmodel *inModel,
CKTcircuit *ckt, int *states)) ASRCsetup,
.DEVunsetup = ASRCunsetup,
.DEVpzSetup = ASRCsetup,
.DEVpzSetup = (int (*)(SMPmatrix *matrix, GENmodel *inModel,
CKTcircuit *ckt, int *states)) ASRCsetup,
.DEVtemperature = ASRCtemp,
.DEVtrunc = NULL,
.DEVfindBranch = ASRCfindBr,

View File

@ -26,7 +26,7 @@ BJTparam(int param, IFvalue *value, GENinstance *instPtr, IFvalue *select)
NG_IGNORE(select);
switch(param) {
switch (param) {
case BJT_AREA:
here->BJTarea = value->rValue;
here->BJTareaGiven = TRUE;
@ -66,10 +66,13 @@ BJTparam(int param, IFvalue *value, GENinstance *instPtr, IFvalue *select)
here->BJTsenParmNo = value->iValue;
break;
case BJT_IC :
switch(value->v.numValue) {
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 2:
here->BJTicVCE = *(value->v.vec.rVec+1);
here->BJTicVCEGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BJTicVBE = *(value->v.vec.rVec);
here->BJTicVBEGiven = TRUE;

View File

@ -21,7 +21,7 @@ B1param(int param, IFvalue *value, GENinstance *inst,
NG_IGNORE(select);
switch(param) {
switch (param) {
case BSIM1_W:
here->B1w = value->rValue;
here->B1wGiven = TRUE;
@ -74,13 +74,17 @@ B1param(int param, IFvalue *value, GENinstance *inst,
here->B1icVGSGiven = TRUE;
break;
case BSIM1_IC:
switch(value->v.numValue){
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue){
case 3:
here->B1icVBS = *(value->v.vec.rVec+2);
here->B1icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->B1icVGS = *(value->v.vec.rVec+1);
here->B1icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->B1icVDS = *(value->v.vec.rVec);
here->B1icVDSGiven = TRUE;

View File

@ -20,7 +20,7 @@ B2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param) {
switch (param) {
case BSIM2_W:
here->B2w = value->rValue;
here->B2wGiven = TRUE;
@ -73,13 +73,17 @@ B2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->B2icVGSGiven = TRUE;
break;
case BSIM2_IC:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch(value->v.numValue){
case 3:
here->B2icVBS = *(value->v.vec.rVec+2);
here->B2icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->B2icVGS = *(value->v.vec.rVec+1);
here->B2icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->B2icVDS = *(value->v.vec.rVec);
here->B2icVDSGiven = TRUE;

View File

@ -31,8 +31,8 @@ IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param)
{ case BSIM3_W:
switch (param) {
case BSIM3_W:
here->BSIM3w = value->rValue*scale;
here->BSIM3wGiven = TRUE;
break;
@ -104,13 +104,17 @@ IFvalue *select)
here->BSIM3mulu0Given = TRUE;
break;
case BSIM3_IC:
switch(value->v.numValue){
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->BSIM3icVBS = *(value->v.vec.rVec+2);
here->BSIM3icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->BSIM3icVGS = *(value->v.vec.rVec+1);
here->BSIM3icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BSIM3icVDS = *(value->v.vec.rVec);
here->BSIM3icVDSGiven = TRUE;

View File

@ -23,8 +23,10 @@ B3SOIDDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param)
{ case B3SOIDD_W:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch(param) {
case B3SOIDD_W:
here->B3SOIDDw = value->rValue;
here->B3SOIDDwGiven = TRUE;
break;
@ -104,19 +106,23 @@ B3SOIDDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->B3SOIDDbodySquaresGiven = TRUE;
break;
case B3SOIDD_IC:
switch(value->v.numValue){
switch (value->v.numValue) {
case 5:
here->B3SOIDDicVPS = *(value->v.vec.rVec+4);
here->B3SOIDDicVPSGiven = TRUE;
/* FALLTHROUGH */
case 4:
here->B3SOIDDicVES = *(value->v.vec.rVec+3);
here->B3SOIDDicVESGiven = TRUE;
/* FALLTHROUGH */
case 3:
here->B3SOIDDicVBS = *(value->v.vec.rVec+2);
here->B3SOIDDicVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->B3SOIDDicVGS = *(value->v.vec.rVec+1);
here->B3SOIDDicVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->B3SOIDDicVDS = *(value->v.vec.rVec);
here->B3SOIDDicVDSGiven = TRUE;

View File

@ -24,8 +24,8 @@ B3SOIFDparam(int param, IFvalue *value, GENinstance *inst,
NG_IGNORE(select);
switch(param)
{ case B3SOIFD_W:
switch (param) {
case B3SOIFD_W:
here->B3SOIFDw = value->rValue;
here->B3SOIFDwGiven = TRUE;
break;
@ -105,19 +105,25 @@ B3SOIFDparam(int param, IFvalue *value, GENinstance *inst,
here->B3SOIFDbodySquaresGiven = TRUE;
break;
case B3SOIFD_IC:
switch(value->v.numValue){
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 5:
here->B3SOIFDicVPS = *(value->v.vec.rVec+4);
here->B3SOIFDicVPSGiven = TRUE;
/* FALLTHROUGH */
case 4:
here->B3SOIFDicVES = *(value->v.vec.rVec+3);
here->B3SOIFDicVESGiven = TRUE;
/* FALLTHROUGH */
case 3:
here->B3SOIFDicVBS = *(value->v.vec.rVec+2);
here->B3SOIFDicVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->B3SOIFDicVGS = *(value->v.vec.rVec+1);
here->B3SOIFDicVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->B3SOIFDicVDS = *(value->v.vec.rVec);
here->B3SOIFDicVDSGiven = TRUE;

View File

@ -25,8 +25,10 @@ B3SOIPDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param)
{ case B3SOIPD_W:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch(param) {
case B3SOIPD_W:
here->B3SOIPDw = value->rValue;
here->B3SOIPDwGiven = TRUE;
break;
@ -148,19 +150,23 @@ B3SOIPDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
case B3SOIPD_IC:
switch(value->v.numValue){
switch (value->v.numValue) {
case 5:
here->B3SOIPDicVPS = *(value->v.vec.rVec+4);
here->B3SOIPDicVPSGiven = TRUE;
/* FALLTHROUGH */
case 4:
here->B3SOIPDicVES = *(value->v.vec.rVec+3);
here->B3SOIPDicVESGiven = TRUE;
/* FALLTHROUGH */
case 3:
here->B3SOIPDicVBS = *(value->v.vec.rVec+2);
here->B3SOIPDicVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->B3SOIPDicVGS = *(value->v.vec.rVec+1);
here->B3SOIPDicVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->B3SOIPDicVDS = *(value->v.vec.rVec);
here->B3SOIPDicVDSGiven = TRUE;

View File

@ -23,8 +23,8 @@ BSIM3v0param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param)
{ case BSIM3v0_W:
switch (param) {
case BSIM3v0_W:
here->BSIM3v0w = value->rValue*scale;
here->BSIM3v0wGiven = TRUE;
break;
@ -80,13 +80,17 @@ BSIM3v0param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->BSIM3v0nqsModGiven = TRUE;
break;
case BSIM3v0_IC:
switch(value->v.numValue){
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->BSIM3v0icVBS = *(value->v.vec.rVec+2);
here->BSIM3v0icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->BSIM3v0icVGS = *(value->v.vec.rVec+1);
here->BSIM3v0icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BSIM3v0icVDS = *(value->v.vec.rVec);
here->BSIM3v0icVDSGiven = TRUE;

View File

@ -29,8 +29,8 @@ BSIM3v1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param)
{ case BSIM3v1_W:
switch (param) {
case BSIM3v1_W:
here->BSIM3v1w = value->rValue*scale;
here->BSIM3v1wGiven = TRUE;
break;
@ -86,13 +86,17 @@ BSIM3v1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->BSIM3v1nqsModGiven = TRUE;
break;
case BSIM3v1_IC:
switch(value->v.numValue){
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->BSIM3v1icVBS = *(value->v.vec.rVec+2);
here->BSIM3v1icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->BSIM3v1icVGS = *(value->v.vec.rVec+1);
here->BSIM3v1icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BSIM3v1icVDS = *(value->v.vec.rVec);
here->BSIM3v1icVDSGiven = TRUE;

View File

@ -28,8 +28,8 @@ BSIM3v32param (int param, IFvalue *value, GENinstance *inst, IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param)
{ case BSIM3v32_W:
switch (param) {
case BSIM3v32_W:
here->BSIM3v32w = value->rValue*scale;
here->BSIM3v32wGiven = TRUE;
break;
@ -97,13 +97,17 @@ BSIM3v32param (int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->BSIM3v32mulu0Given = TRUE;
break;
case BSIM3v32_IC:
switch(value->v.numValue){
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->BSIM3v32icVBS = *(value->v.vec.rVec+2);
here->BSIM3v32icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->BSIM3v32icVGS = *(value->v.vec.rVec+1);
here->BSIM3v32icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BSIM3v32icVDS = *(value->v.vec.rVec);
here->BSIM3v32icVDSGiven = TRUE;

View File

@ -81,8 +81,8 @@ IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param)
{ case BSIM4_W:
switch (param) {
case BSIM4_W:
here->BSIM4w = value->rValue * scale;
here->BSIM4wGiven = TRUE;
break;
@ -230,13 +230,17 @@ IFvalue *select)
here->BSIM4icVBSGiven = TRUE;
break;
case BSIM4_IC:
switch(value->v.numValue)
{ case 3:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->BSIM4icVBS = *(value->v.vec.rVec+2);
here->BSIM4icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->BSIM4icVGS = *(value->v.vec.rVec+1);
here->BSIM4icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BSIM4icVDS = *(value->v.vec.rVec);
here->BSIM4icVDSGiven = TRUE;

View File

@ -35,8 +35,8 @@ IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param)
{ case BSIM4v5_W:
switch (param) {
case BSIM4v5_W:
here->BSIM4v5w = value->rValue*scale;
here->BSIM4v5wGiven = TRUE;
break;
@ -180,13 +180,17 @@ IFvalue *select)
here->BSIM4v5icVBSGiven = TRUE;
break;
case BSIM4v5_IC:
switch(value->v.numValue)
{ case 3:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->BSIM4v5icVBS = *(value->v.vec.rVec+2);
here->BSIM4v5icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->BSIM4v5icVGS = *(value->v.vec.rVec+1);
here->BSIM4v5icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BSIM4v5icVDS = *(value->v.vec.rVec);
here->BSIM4v5icVDSGiven = TRUE;

View File

@ -37,8 +37,8 @@ IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param)
{ case BSIM4v6_W:
switch (param) {
case BSIM4v6_W:
here->BSIM4v6w = value->rValue*scale;
here->BSIM4v6wGiven = TRUE;
break;
@ -182,13 +182,17 @@ IFvalue *select)
here->BSIM4v6icVBSGiven = TRUE;
break;
case BSIM4v6_IC:
switch(value->v.numValue)
{ case 3:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->BSIM4v6icVBS = *(value->v.vec.rVec+2);
here->BSIM4v6icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->BSIM4v6icVGS = *(value->v.vec.rVec+1);
here->BSIM4v6icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BSIM4v6icVDS = *(value->v.vec.rVec);
here->BSIM4v6icVDSGiven = TRUE;

View File

@ -37,8 +37,8 @@ IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param)
{ case BSIM4v7_W:
switch (param) {
case BSIM4v7_W:
here->BSIM4v7w = value->rValue * scale;
here->BSIM4v7wGiven = TRUE;
break;
@ -186,13 +186,17 @@ IFvalue *select)
here->BSIM4v7icVBSGiven = TRUE;
break;
case BSIM4v7_IC:
switch(value->v.numValue)
{ case 3:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->BSIM4v7icVBS = *(value->v.vec.rVec+2);
here->BSIM4v7icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->BSIM4v7icVGS = *(value->v.vec.rVec+1);
here->BSIM4v7icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->BSIM4v7icVDS = *(value->v.vec.rVec);
here->BSIM4v7icVDSGiven = TRUE;

View File

@ -789,45 +789,44 @@ errordetect:
}
static int
update_delayed_cnv(CPLine *cp, double h)
static int update_delayed_cnv(CPLine *cp, double h)
{
int i, j, k;
double *ratio;
double *ratio1;
double f;
VI_list *vi;
TMS *tms;
int noL;
h *= 0.5e-12;
ratio = cp->ratio;
ratio1 = cp->ratio;
vi = cp->vi_tail;
noL = cp->noL;
for (k = 0; k < noL; k++) /* mode */
if (ratio[k] > 0.0)
if (ratio1[k] > 0.0)
for (i = 0; i < noL; i++) /* current eqn */
for (j = 0; j < noL; j++) {
tms = cp->h3t[i][j][k];
if (tms == NULL)
continue;
f = h * ratio[k] * vi->v_i[j];
f = h * ratio1[k] * vi->v_i[j];
tms->tm[0].cnv_i += f * tms->tm[0].c;
tms->tm[1].cnv_i += f * tms->tm[1].c;
tms->tm[2].cnv_i += f * tms->tm[2].c;
f = h * ratio[k] * vi->v_o[j];
f = h * ratio1[k] * vi->v_o[j];
tms->tm[0].cnv_o += f * tms->tm[0].c;
tms->tm[1].cnv_o += f * tms->tm[1].c;
tms->tm[2].cnv_o += f * tms->tm[2].c;
tms = cp->h2t[i][j][k];
f = h * ratio[k] * vi->i_i[j];
f = h * ratio1[k] * vi->i_i[j];
tms->tm[0].cnv_i += f * tms->tm[0].c;
tms->tm[1].cnv_i += f * tms->tm[1].c;
tms->tm[2].cnv_i += f * tms->tm[2].c;
f = h * ratio[k] * vi->i_o[j];
f = h * ratio1[k] * vi->i_o[j];
tms->tm[0].cnv_o += f * tms->tm[0].c;
tms->tm[1].cnv_o += f * tms->tm[1].c;
tms->tm[2].cnv_o += f * tms->tm[2].c;

View File

@ -1061,14 +1061,14 @@ loop_ZY(int dim, double y)
static void
poly_matrix(
double *A[MAX_DIM][MAX_DIM],
double *A_in[MAX_DIM][MAX_DIM],
int dim, int deg)
{
int i, j;
for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
match(deg, A[i][j], frequency, A[i][j]);
match(deg, A_in[i][j], frequency, A_in[i][j]);
}
/***
@ -1464,10 +1464,9 @@ mult_p(double *p1, double *p2, double *p3, int d1, int d2, int d3)
}
static void
matrix_p_mult(
double *A[MAX_DIM][MAX_DIM],
double *D[MAX_DIM],
static void matrix_p_mult(
double *A_in[MAX_DIM][MAX_DIM],
double *D1[MAX_DIM],
double *B[MAX_DIM][MAX_DIM],
int dim, int deg, int deg_o,
Mult_Out X[MAX_DIM][MAX_DIM])
@ -1480,14 +1479,14 @@ matrix_p_mult(
for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++) {
p = T[i][j] = (double *) calloc((size_t) (deg_o+1), sizeof(double));
mult_p(B[i][j], D[i], p, deg, deg_o, deg_o);
mult_p(B[i][j], D1[i], p, deg, deg_o, deg_o);
}
for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++)
for (k = 0; k < dim; k++) {
p = X[i][j].Poly[k] =
(double *) calloc((size_t) (deg_o+1), sizeof(double));
mult_p(A[i][k], T[k][j], p, deg, deg_o, deg_o);
mult_p(A_in[i][k], T[k][j], p, deg, deg_o, deg_o);
t1 = X[i][j].C_0[k] = p[0];
if (t1 != 0.0) {
p[0] = 1.0;
@ -1523,7 +1522,7 @@ matrix_p_mult(
***/
static double
approx_mode(double *X, double *b, double length)
approx_mode(double *X, double *b, double length_in)
{
double w0, w1, w2, w3, w4, w5;
double a[8];
@ -1545,7 +1544,7 @@ approx_mode(double *X, double *b, double length)
y5 = 60.0 * w5 - 5.0 * y1 * y4 -10.0 * y2 * y3;
y6 = -10.0 * y3 * y3 - 15.0 * y2 * y4 - 6.0 * y1 * y5;
delay = sqrt(w0) * length / Scaling_F;
delay = sqrt(w0) * length_in / Scaling_F;
atten = exp(- delay * y1);
a[1] = y2 / 2.0;
@ -2080,8 +2079,7 @@ diag(int dims)
rotate() rotation of the Jacobi's method
****************************************************************/
static int
rotate(int dim, int p, int q)
static int rotate(int dim_in, int p, int q)
{
int j;
double co, si;
@ -2095,12 +2093,12 @@ rotate(int dim, int p, int q)
co = sqrt((ve + ABS(mu)) / (2.0 * ve));
si = SGN(mu) * ld / (2.0 * ve * co);
for (j = p+1; j < dim; j++)
for (j = p+1; j < dim_in; j++)
T[j] = ZY[p][j];
for (j = 0; j < p; j++)
T[j] = ZY[j][p];
for (j = p+1; j < dim; j++) {
for (j = p+1; j < dim_in; j++) {
if (j == q)
continue;
if (j > q)
@ -2108,7 +2106,7 @@ rotate(int dim, int p, int q)
else
ZY[p][j] = T[j] * co - ZY[j][q] * si;
}
for (j = q+1; j < dim; j++) {
for (j = q+1; j < dim_in; j++) {
if (j == p)
continue;
ZY[q][j] = T[j] * si + ZY[q][j] * co;
@ -2133,12 +2131,12 @@ rotate(int dim, int p, int q)
{
double R[MAX_DIM];
for (j = 0; j < dim; j++) {
for (j = 0; j < dim_in; j++) {
T[j] = Sv[j][p];
R[j] = Sv[j][q];
}
for (j = 0; j < dim; j++) {
for (j = 0; j < dim_in; j++) {
Sv[j][p] = T[j] * co - R[j] * si;
Sv[j][q] = T[j] * si + R[j] * co;
}

View File

@ -479,15 +479,11 @@ int load_opus(const char *name)
#endif
/* Give the code model access to facilities provided by ngspice. Note
* that older versions of code models will not access the functions
* added by newer versions of ngspice since it is unaware of them and
* newer versions of code models will not use newer (undefined)
* functions from ngspice because any of its models that use them
* will not be recognized and used by ngspice. */
/* Give the code model access to facilities provided by ngspice. */
if ((fetch = dlsym(lib,"CMgetCoreItfPtr")) != (funptr_t) NULL) {
const struct coreInfo_t ** const core =
(*(const struct coreInfo_t ** const (*)(void)) fetch)();
(const struct coreInfo_t **const)
(*(struct coreInfo_t ** (*)(void)) fetch)();
*core = &coreInfo;
}
else {

View File

@ -18,7 +18,7 @@ HFETAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param) {
switch (param) {
case HFETA_LENGTH:
here->HFETAlength = value->rValue;
here->HFETAlengthGiven = TRUE;
@ -43,10 +43,13 @@ HFETAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->HFETAoff = value->iValue;
break;
case HFETA_IC:
switch(value->v.numValue) {
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 2:
here->HFETAicVGS = *(value->v.vec.rVec+1);
here->HFETAicVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->HFETAicVDS = *(value->v.vec.rVec);
here->HFETAicVDSGiven = TRUE;

View File

@ -16,8 +16,8 @@ int HFET2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
HFET2instance *here = (HFET2instance*)inst;
NG_IGNORE(select);
switch(param) {
switch (param) {
case HFET2_LENGTH:
L = value->rValue;
here->HFET2lengthGiven = TRUE;
@ -34,10 +34,13 @@ int HFET2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->HFET2off = value->iValue;
break;
case HFET2_IC:
switch(value->v.numValue) {
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 2:
here->HFET2icVGS = *(value->v.vec.rVec+1);
here->HFET2icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->HFET2icVDS = *(value->v.vec.rVec);
here->HFET2icVDSGiven = TRUE;

View File

@ -133,13 +133,17 @@ int HSM2param(
here->HSM2_icVGS_Given = TRUE;
break;
case HSM2_IC:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->HSM2_icVBS = *(value->v.vec.rVec + 2);
here->HSM2_icVBS_Given = TRUE;
/* FALLTHROUGH */
case 2:
here->HSM2_icVGS = *(value->v.vec.rVec + 1);
here->HSM2_icVGS_Given = TRUE;
/* FALLTHROUGH */
case 1:
here->HSM2_icVDS = *(value->v.vec.rVec);
here->HSM2_icVDS_Given = TRUE;

View File

@ -102,9 +102,11 @@ int HSMHVparam(
case 3:
here->HSMHV_icVBS = *(value->v.vec.rVec + 2);
here->HSMHV_icVBS_Given = TRUE;
/* FALLTHROUGH */
case 2:
here->HSMHV_icVGS = *(value->v.vec.rVec + 1);
here->HSMHV_icVGS_Given = TRUE;
/* FALLTHROUGH */
case 1:
here->HSMHV_icVDS = *(value->v.vec.rVec);
here->HSMHV_icVDS_Given = TRUE;

View File

@ -140,13 +140,17 @@ int HSMHV2param(
here->HSMHV2_icVGS_Given = TRUE;
break;
case HSMHV2_IC:
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->HSMHV2_icVBS = *(value->v.vec.rVec + 2);
here->HSMHV2_icVBS_Given = TRUE;
/* FALLTHROUGH */
case 2:
here->HSMHV2_icVGS = *(value->v.vec.rVec + 1);
here->HSMHV2_icVGS_Given = TRUE;
/* FALLTHROUGH */
case 1:
here->HSMHV2_icVDS = *(value->v.vec.rVec);
here->HSMHV2_icVDS_Given = TRUE;

View File

@ -38,7 +38,7 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param) {
switch (param) {
case ISRC_DC:
here->ISRCdcValue = value->rValue;
@ -63,13 +63,17 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
break;
case ISRC_AC:
switch(value->v.numValue) {
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 2:
here->ISRCacPhase = *(value->v.vec.rVec+1);
here->ISRCacPGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->ISRCacMag = *(value->v.vec.rVec);
here->ISRCacMGiven = TRUE;
/* FALLTHROUGH */
case 0:
here->ISRCacGiven = TRUE;
break;

View File

@ -21,7 +21,7 @@ JFETparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param) {
switch (param) {
case JFET_TEMP:
here->JFETtemp = value->rValue+CONSTCtoK;
here->JFETtempGiven = TRUE;
@ -50,10 +50,13 @@ JFETparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->JFEToff = (value->iValue != 0);
break;
case JFET_IC:
switch(value->v.numValue) {
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 2:
here->JFETicVGS = *(value->v.vec.rVec+1);
here->JFETicVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->JFETicVDS = *(value->v.vec.rVec);
here->JFETicVDSGiven = TRUE;

View File

@ -25,7 +25,7 @@ JFET2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param) {
switch (param) {
case JFET2_TEMP:
here->JFET2temp = value->rValue+CONSTCtoK;
here->JFET2tempGiven = TRUE;
@ -54,10 +54,13 @@ JFET2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->JFET2off = (value->iValue != 0);
break;
case JFET2_IC:
switch(value->v.numValue) {
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 2:
here->JFET2icVGS = *(value->v.vec.rVec+1);
here->JFET2icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->JFET2icVDS = *(value->v.vec.rVec);
here->JFET2icVDSGiven = TRUE;

View File

@ -90,6 +90,8 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt)
break;
}
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (model->LTRAspecialCase) {
case LTRA_MOD_RLC:
/*
@ -122,6 +124,7 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt)
model->LTRAtd, model->LTRAalpha, model->LTRAbeta,
ckt->CKTtime, ckt->CKTtimePoints, ckt->CKTtimeIndex,
model->LTRAchopReltol, &(model->LTRAauxIndex));
/* FALLTHROUGH */
case LTRA_MOD_LC:
@ -308,6 +311,7 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt)
*(here->LTRAibr2Pos2Ptr) += dummy1;
*(here->LTRAibr2Neg2Ptr) -= dummy1;
/* end loading for convolution parts' first terms */
/* FALLTHROUGH */
case LTRA_MOD_LC:
/*
@ -591,6 +595,8 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt)
return (E_BADPARM);
}
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (model->LTRAspecialCase) {
case LTRA_MOD_RLC:
@ -701,6 +707,7 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt)
/* end convolution of h3dash with v2 and v1 */
/* FALLTHROUGH */
case LTRA_MOD_LC:
/* begin lossless-like parts */

View File

@ -39,10 +39,13 @@ LTRAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
switch (value->v.numValue) {
case 4:
here->LTRAinitCur2 = *(value->v.vec.rVec + 3);
/* FALLTHROUGH */
case 3:
here->LTRAinitVolt2 = *(value->v.vec.rVec + 2);
/* FALLTHROUGH */
case 2:
here->LTRAinitCur1 = *(value->v.vec.rVec + 1);
/* FALLTHROUGH */
case 1:
here->LTRAinitVolt1 = *(value->v.vec.rVec);
break;

View File

@ -20,7 +20,7 @@ MESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param) {
switch (param) {
case MES_AREA:
here->MESarea = value->rValue;
here->MESareaGiven = TRUE;
@ -41,10 +41,13 @@ MESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->MESoff = value->iValue;
break;
case MES_IC:
switch(value->v.numValue) {
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 2:
here->MESicVGS = *(value->v.vec.rVec+1);
here->MESicVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->MESicVDS = *(value->v.vec.rVec);
here->MESicVDSGiven = TRUE;

View File

@ -19,7 +19,7 @@ MESAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select);
switch(param) {
switch (param) {
case MESA_LENGTH:
here->MESAlength = value->rValue;
here->MESAlengthGiven = TRUE;
@ -45,10 +45,13 @@ MESAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->MESAoff = value->iValue;
break;
case MESA_IC:
switch(value->v.numValue) {
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 2:
here->MESAicVGS = *(value->v.vec.rVec+1);
here->MESAicVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->MESAicVDS = *(value->v.vec.rVec);
here->MESAicVDSGiven = TRUE;

View File

@ -28,7 +28,7 @@ MOS1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param) {
switch (param) {
case MOS1_TEMP:
here->MOS1temp = value->rValue+CONSTCtoK;
here->MOS1tempGiven = TRUE;
@ -89,13 +89,17 @@ MOS1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->MOS1icVGSGiven = TRUE;
break;
case MOS1_IC:
switch(value->v.numValue){
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->MOS1icVBS = *(value->v.vec.rVec+2);
here->MOS1icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->MOS1icVGS = *(value->v.vec.rVec+1);
here->MOS1icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->MOS1icVDS = *(value->v.vec.rVec);
here->MOS1icVDSGiven = TRUE;

View File

@ -193,8 +193,8 @@ MOS2dSetup(GENmodel *inModel, CKTcircuit *ckt)
* this routine evaluates the drain current, its derivatives and * the charges associated with the gate, channel and bulk * for mosfets *
*/
double arg;
double sarg;
double arg1;
double sarg1;
double a4[4],b4[4],x4[8],poly4[8];
double beta1;
double sphi = 0.0; /* square root of phi */
@ -358,22 +358,22 @@ d_p.d3_pqr = 0.0;
d_phiMinVbs.d1_q = - d_phiMinVbs.d1_q;
if (lvbs <= 0.0) {
sarg = sqrt(phiMinVbs);
sarg1 = sqrt(phiMinVbs);
SqrtDeriv(&d_sarg, &d_phiMinVbs);
dsrgdb = -0.5/sarg;
dsrgdb = -0.5/sarg1;
InvDeriv(&d_dsrgdb,&d_sarg);
TimesDeriv(&d_dsrgdb,&d_dsrgdb,-0.5);
} else {
sphi = sqrt(here->MOS2tPhi); /*const*/
sphi3 = here->MOS2tPhi*sphi; /*const*/
sarg = sphi/(1.0+0.5*lvbs/here->MOS2tPhi);
sarg1 = sphi/(1.0+0.5*lvbs/here->MOS2tPhi);
EqualDeriv(&d_sarg,&d_q); d_sarg.value = lvbs;
TimesDeriv(&d_sarg,&d_sarg,0.5/here->MOS2tPhi);
d_sarg.value += 1.0;
InvDeriv(&d_sarg,&d_sarg);
TimesDeriv(&d_sarg,&d_sarg,sphi);
dsrgdb = -0.5*sarg*sarg/sphi3;
dsrgdb = -0.5*sarg1*sarg1/sphi3;
MultDeriv(&d_dsrgdb,&d_sarg,&d_sarg);
TimesDeriv(&d_dsrgdb,&d_dsrgdb,-0.5/sphi3);
/* tmp = sarg/sphi3; */
@ -422,7 +422,7 @@ d_p.d3_pqr = 0.0;
if ((model->MOS2gamma > 0.0) ||
(model->MOS2substrateDoping > 0.0)) {
xwd = model->MOS2xd*barg;
xws = model->MOS2xd*sarg;
xws = model->MOS2xd*sarg1;
TimesDeriv(&d_xwd,&d_barg,model->MOS2xd);
TimesDeriv(&d_xws,&d_sarg,model->MOS2xd);
@ -484,7 +484,7 @@ d_p.d3_pqr = 0.0;
dgddvb = 0.0;
EqualDeriv(&d_dgddvb,&d_zero);
}
von = vbin+gamasd*sarg;
von = vbin+gamasd*sarg1;
MultDeriv(&d_von,&d_gamasd,&d_sarg);
PlusDeriv(&d_von,&d_von,&d_vbin);
/*
@ -497,7 +497,7 @@ d_p.d3_pqr = 0.0;
/* XXX constant per model */
cfs = CHARGE*model->MOS2fastSurfaceStateDensity*
1e4 /*(cm**2/m**2)*/;
cdonco = -(gamasd*dsrgdb + dgddvb*sarg) + factor;
cdonco = -(gamasd*dsrgdb + dgddvb*sarg1) + factor;
MultDeriv(&d_dummy,&d_dgddvb,&d_sarg);
MultDeriv(&d_cdonco,&d_gamasd,&d_dsrgdb);
PlusDeriv(&d_cdonco,&d_cdonco,&d_dummy);
@ -533,7 +533,7 @@ d_p.d3_pqr = 0.0;
/*
* compute some more useful quantities */
sarg3 = sarg*sarg*sarg;
sarg3 = sarg1*sarg1*sarg1;
CubeDeriv(&d_sarg3,&d_sarg);
/* XXX constant per model */
sbiarg = sqrt(here->MOS2tBulkPot); /*const*/
@ -599,7 +599,7 @@ line500:
vdsat = 0.0;
EqualDeriv(&d_vdsat,&d_zero);
} else {
arg = sqrt(1.0+4.0*argv/gammd2);
arg1 = sqrt(1.0+4.0*argv/gammd2);
DivDeriv(&d_arg,&d_argv,&d_gammd2);
TimesDeriv(&d_arg,&d_arg,4.0);d_arg.value += 1.0;
SqrtDeriv(&d_arg,&d_arg);
@ -883,14 +883,14 @@ line500:
MultDeriv(&d_sargv,&d_argv,&d_argv);
d_sargv.value += 1.0;
SqrtDeriv(&d_sargv,&d_sargv);
arg = sqrt(argv+sargv);
arg1 = sqrt(argv+sargv);
PlusDeriv(&d_arg,&d_sargv,&d_argv);
SqrtDeriv(&d_arg,&d_arg);
xlfact = model->MOS2xd/(EffectiveLength*lvds);
EqualDeriv(&d_xlfact,&d_r); d_xlfact.value = lvds;
InvDeriv(&d_xlfact,&d_xlfact);
TimesDeriv(&d_xlfact,&d_xlfact,model->MOS2xd/EffectiveLength);
xlamda = xlfact*arg;
xlamda = xlfact*arg1;
MultDeriv(&d_xlamda,&d_xlfact,&d_arg);
} else {
argv = (vgsx-vbin)/eta-vdsat;
@ -990,7 +990,7 @@ line610:
goto line1050;
}
here->MOS2gds = beta1*(von-vbin-gammad*sarg)*exp(argg*
here->MOS2gds = beta1*(von-vbin-gammad*sarg1)*exp(argg*
(lvgs-von));
MultDeriv(&d_dummy,&d_gammad,&d_sarg);
PlusDeriv(&d_dummy,&d_dummy,&d_vbin);
@ -1011,7 +1011,7 @@ line610:
}
here->MOS2gds = beta1*(lvgs-vbin-gammad*sarg);
here->MOS2gds = beta1*(lvgs-vbin-gammad*sarg1);
MultDeriv(&d_mos2gds,&d_gammad,&d_sarg);
PlusDeriv(&d_mos2gds,&d_mos2gds,&d_vbin);
TimesDeriv(&d_mos2gds,&d_mos2gds,-1.0);

View File

@ -431,8 +431,8 @@ next1: if(vbs <= -3*vt) {
*
*/
double arg;
double sarg;
double arg1;
double sarg1;
double a4[4],b4[4],x4[8],poly4[8];
double beta1;
double dsrgdb;
@ -569,15 +569,15 @@ next1: if(vbs <= -3*vt) {
*/
if (lvbs <= 0.0) {
sarg = sqrt(phiMinVbs);
dsrgdb = -0.5/sarg;
sarg1 = sqrt(phiMinVbs);
dsrgdb = -0.5/sarg1;
d2sdb2 = 0.5*dsrgdb/phiMinVbs;
} else {
sphi = sqrt(here->MOS2tPhi);
sphi3 = here->MOS2tPhi*sphi;
sarg = sphi/(1.0+0.5*lvbs/here->MOS2tPhi);
tmp = sarg/sphi3;
dsrgdb = -0.5*sarg*tmp;
sarg1 = sphi/(1.0+0.5*lvbs/here->MOS2tPhi);
tmp = sarg1/sphi3;
dsrgdb = -0.5*sarg1*tmp;
d2sdb2 = -dsrgdb*tmp;
}
if ((lvbs-lvds) <= 0) {
@ -606,7 +606,7 @@ next1: if(vbs <= -3*vt) {
if ((model->MOS2gamma > 0.0) ||
(model->MOS2substrateDoping > 0.0)) {
xwd = model->MOS2xd*barg;
xws = model->MOS2xd*sarg;
xws = model->MOS2xd*sarg1;
/*
* short-channel effect with vds .ne. 0.0
@ -655,14 +655,14 @@ next1: if(vbs <= -3*vt) {
dgdvds = 0.0;
dgddb2 = 0.0;
}
von = vbin+gamasd*sarg;
von = vbin+gamasd*sarg1;
vth = von;
vdsat = 0.0;
if (model->MOS2fastSurfaceStateDensity != 0.0 && OxideCap != 0.0) {
/* XXX constant per model */
cfs = CHARGE*model->MOS2fastSurfaceStateDensity*
1e4 /*(cm**2/m**2)*/;
cdonco = -(gamasd*dsrgdb+dgddvb*sarg)+factor;
cdonco = -(gamasd*dsrgdb+dgddvb*sarg1)+factor;
xn = 1.0+cfs/OxideCap*here->MOS2m*
here->MOS2w*EffectiveLength+cdonco;
@ -686,20 +686,20 @@ next1: if(vbs <= -3*vt) {
* compute some more useful quantities
*/
sarg3 = sarg*sarg*sarg;
sarg3 = sarg1*sarg1*sarg1;
/* XXX constant per model */
sbiarg = sqrt(here->MOS2tBulkPot);
gammad = gamasd;
dgdvbs = dgddvb;
body = barg*barg*barg-sarg3;
gdbdv = 2.0*gammad*(barg*barg*dbrgdb-sarg*sarg*dsrgdb);
dodvbs = -factor+dgdvbs*sarg+gammad*dsrgdb;
gdbdv = 2.0*gammad*(barg*barg*dbrgdb-sarg1*sarg1*dsrgdb);
dodvbs = -factor+dgdvbs*sarg1+gammad*dsrgdb;
if (model->MOS2fastSurfaceStateDensity == 0.0) goto line400;
if (OxideCap == 0.0) goto line410;
dxndvb = 2.0*dgdvbs*dsrgdb+gammad*d2sdb2+dgddb2*sarg;
dxndvb = 2.0*dgdvbs*dsrgdb+gammad*d2sdb2+dgddb2*sarg1;
dodvbs = dodvbs+vt*dxndvb;
dxndvd = dgdvds*dsrgdb;
dodvds = dgdvds*sarg+vt*dxndvd;
dodvds = dgdvds*sarg1+vt*dxndvd;
/*
* evaluate effective mobility and its derivatives
*/
@ -740,12 +740,12 @@ line500:
dsdvgs = 0.0;
dsdvbs = 0.0;
} else {
arg = sqrt(1.0+4.0*argv/gammd2);
vdsat = (vgsx-vbin)/eta+gammd2*(1.0-arg)/2.0;
arg1 = sqrt(1.0+4.0*argv/gammd2);
vdsat = (vgsx-vbin)/eta+gammd2*(1.0-arg1)/2.0;
vdsat = MAX(vdsat,0.0);
dsdvgs = (1.0-1.0/arg)/eta;
dsdvbs = (gammad*(1.0-arg)+2.0*argv/(gammad*arg))/
eta*dgdvbs+1.0/arg+factor*dsdvgs;
dsdvgs = (1.0-1.0/arg1)/eta;
dsdvbs = (gammad*(1.0-arg1)+2.0*argv/(gammad*arg1))/
eta*dgdvbs+1.0/arg1+factor*dsdvgs;
}
} else {
vdsat = (vgsx-vbin)/eta;
@ -838,15 +838,15 @@ line500:
dbsrdb = -0.5*bsarg*bsarg/sphi3;
}
bodys = bsarg*bsarg*bsarg-sarg3;
gdbdvs = 2.0*gammad*(bsarg*bsarg*dbsrdb-sarg*sarg*dsrgdb);
gdbdvs = 2.0*gammad*(bsarg*bsarg*dbsrdb-sarg1*sarg1*dsrgdb);
if (model->MOS2maxDriftVel <= 0) {
if (model->MOS2substrateDoping == 0.0) goto line610;
if (xlamda > 0.0) goto line610;
argv = (lvds-vdsat)/4.0;
sargv = sqrt(1.0+argv*argv);
arg = sqrt(argv+sargv);
arg1 = sqrt(argv+sargv);
xlfact = model->MOS2xd/(EffectiveLength*lvds);
xlamda = xlfact*arg;
xlamda = xlfact*arg1;
dldsat = lvds*xlamda/(8.0*sargv);
} else {
argv = (vgsx-vbin)/eta-vdsat;
@ -915,13 +915,13 @@ line610:
goto line1050;
}
here->MOS2gds = beta1*(von-vbin-gammad*sarg)*exp(argg*
here->MOS2gds = beta1*(von-vbin-gammad*sarg1)*exp(argg*
(lvgs-von));
goto line1050;
}
here->MOS2gds = beta1*(lvgs-vbin-gammad*sarg);
here->MOS2gds = beta1*(lvgs-vbin-gammad*sarg1);
goto line1050;
}
@ -971,25 +971,25 @@ line900:
* linear region
*/
cdrain = beta1*((lvgs-vbin-eta*lvds/2.0)*lvds-gammad*body/1.5);
arg = cdrain*(dudvgs/ufact-dldvgs/clfact);
here->MOS2gm = arg+beta1*lvds;
arg = cdrain*(dudvds/ufact-dldvds/clfact);
here->MOS2gds = arg+beta1*(lvgs-vbin-eta*
arg1 = cdrain*(dudvgs/ufact-dldvgs/clfact);
here->MOS2gm = arg1+beta1*lvds;
arg1 = cdrain*(dudvds/ufact-dldvds/clfact);
here->MOS2gds = arg1+beta1*(lvgs-vbin-eta*
lvds-gammad*barg-dgdvds*body/1.5);
arg = cdrain*(dudvbs/ufact-dldvbs/clfact);
here->MOS2gmbs = arg-beta1*(gdbdv+dgdvbs*body/1.5-factor*lvds);
arg1 = cdrain*(dudvbs/ufact-dldvbs/clfact);
here->MOS2gmbs = arg1-beta1*(gdbdv+dgdvbs*body/1.5-factor*lvds);
} else {
/*
* saturation region
*/
cdrain = beta1*((lvgs-vbin-eta*
vdsat/2.0)*vdsat-gammad*bodys/1.5);
arg = cdrain*(dudvgs/ufact-dldvgs/clfact);
here->MOS2gm = arg+beta1*vdsat+beta1*(lvgs-
arg1 = cdrain*(dudvgs/ufact-dldvgs/clfact);
here->MOS2gm = arg1+beta1*vdsat+beta1*(lvgs-
vbin-eta*vdsat-gammad*bsarg)*dsdvgs;
here->MOS2gds = -cdrain*dldvds/clfact-beta1*dgdvds*bodys/1.5;
arg = cdrain*(dudvbs/ufact-dldvbs/clfact);
here->MOS2gmbs = arg-beta1*(gdbdvs+dgdvbs*bodys/1.5-factor*
arg1 = cdrain*(dudvbs/ufact-dldvbs/clfact);
here->MOS2gmbs = arg1-beta1*(gdbdvs+dgdvbs*bodys/1.5-factor*
vdsat)+beta1* (lvgs-vbin-eta*vdsat-gammad*bsarg)*dsdvbs;
}
/*

View File

@ -29,7 +29,7 @@ MOS2param(int param, IFvalue *value, GENinstance *inst,
if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1;
switch(param) {
switch (param) {
case MOS2_TEMP:
here->MOS2temp = value->rValue+CONSTCtoK;
here->MOS2tempGiven = TRUE;
@ -90,13 +90,17 @@ MOS2param(int param, IFvalue *value, GENinstance *inst,
here->MOS2icVGSGiven = TRUE;
break;
case MOS2_IC:
switch(value->v.numValue){
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3:
here->MOS2icVBS = *(value->v.vec.rVec+2);
here->MOS2icVBSGiven = TRUE;
/* FALLTHROUGH */
case 2:
here->MOS2icVGS = *(value->v.vec.rVec+1);
here->MOS2icVGSGiven = TRUE;
/* FALLTHROUGH */
case 1:
here->MOS2icVDS = *(value->v.vec.rVec);
here->MOS2icVDSGiven = TRUE;

Some files were not shown because too many files have changed in this diff Show More