Merge with pre-master

This commit is contained in:
Jim Monte 2020-03-08 01:54:40 -05:00
commit 721bc05a43
126 changed files with 1807 additions and 1167 deletions

View File

@ -1333,4 +1333,9 @@ else
AC_SUBST([CMPP], ['$(top_builddir)/src/xspice/cmpp/cmpp$(EXEEXT)']) AC_SUBST([CMPP], ['$(top_builddir)/src/xspice/cmpp/cmpp$(EXEEXT)'])
fi 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 AC_OUTPUT

View File

@ -4,18 +4,19 @@ Author: 1991 David A. Gates, U. C. Berkeley CAD Group
Modifed: 2001 Paolo Nenzi Modifed: 2001 Paolo Nenzi
**********/ **********/
#include "ngspice/ngspice.h" #include "ngspice/carddefs.h"
#include "ngspice/cidersupt.h"
#include "ngspice/cktdefs.h" #include "ngspice/cktdefs.h"
#include "ngspice/numenum.h" #include "ngspice/ciderinp.h"
#include "ngspice/cpextern.h"
#include "ngspice/dopdefs.h" #include "ngspice/dopdefs.h"
#include "ngspice/meshext.h" #include "ngspice/meshext.h"
#include "ngspice/ngspice.h"
#include "ngspice/numenum.h"
#include "ngspice/profile.h" #include "ngspice/profile.h"
#include "ngspice/gendev.h" #include "ngspice/gendev.h"
#include "ngspice/sperror.h" #include "ngspice/sperror.h"
#include "ngspice/suffix.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; break;
case DOP_SUPREM3: case DOP_SUPREM3:
newProfile->type = LOOKUP; 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; newProfile->IMPID = ++impurityId;
break; break;
case DOP_SUPASCII: case DOP_SUPASCII:
newProfile->type = LOOKUP; 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; newProfile->IMPID = ++impurityId;
break; break;
case DOP_ASCII: case DOP_ASCII:
newProfile->type = LOOKUP; 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; newProfile->IMPID = ++impurityId;
break; break;
default: default:

View File

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

View File

@ -77,6 +77,7 @@ ONEdopingValue(DOPprofile *pProfile, DOPtable *pTable, double x)
} else { } else {
value = pProfile->PEAK_CONC * exp(-argP); value = pProfile->PEAK_CONC * exp(-argP);
} }
break;
case EXP: case EXP:
argP = ABS(argP); argP = ABS(argP);
if (argP > 80.0) { 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 */ /* 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/ngspice.h"
#include "ngspice/profile.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; int index;
double x, y; double x, y;
int numPoints; int numPoints;
DOPtable *tmpTable; DOPtable *tmpTable = (DOPtable *) NULL;
double **profileData; double **profileData = (double **) NULL;
double sign; double sign;
/* Open Input File */ /* Open Input File */
if ((fpAscii = fopen( fileName, "r" )) == NULL) { if ((fpAscii = fopen( fileName, "r" )) == NULL) {
perror( fileName ); (void) fprintf(cp_err, "unable to open SUPREM file \"%s\": %s\n",
exit(-1); fileName, strerror(errno));
xrc = -1;
goto EXITPOINT;
} }
/* Get sign of concentrations */ /* Get sign of concentrations */
@ -35,31 +45,43 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable )
} }
/* read the number of points */ /* 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) */ /* allocate 2-D array to read in data of x-coordinate and N(x) */
XCALLOC( profileData, double *, 2 ); profileData = alloc_profile_data((size_t) numPoints + 1);
for( index = 0; index <= 1; index++ ) {
XCALLOC( profileData[ index ], double, 1 + numPoints );
}
/* the number of points is stored as profileData[0][0] */ /* the number of points is stored as profileData[0][0] */
profileData[0][0] = numPoints; profileData[0][0] = numPoints;
for( index = 1; index <= numPoints; index++ ) { for (index = 1; index <= numPoints; index++ ) {
fscanf( fpAscii, "%lf %lf ", &x, &y ); if (fscanf(fpAscii, "%lf %lf ", &x, &y) != 2) {
profileData[ 0 ][ index ] = x; (void) fprintf(cp_err, "unable to read point %d"
profileData[ 1 ][ index ] = sign * ABS(y); "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 */ /* Now create a new lookup table */
XCALLOC( tmpTable, DOPtable, 1 ); XCALLOC(tmpTable, DOPtable, 1);
if ( *ppTable == NULL ) { if (*ppTable == NULL) {
/* First Entry */ /* First Entry */
tmpTable->impId = 1; tmpTable->impId = 1;
tmpTable->dopData = profileData; tmpTable->dopData = profileData;
tmpTable->next = NULL; tmpTable->next = NULL;
*ppTable = tmpTable; *ppTable = tmpTable;
} else { }
else {
tmpTable->impId = (*ppTable)->impId + 1; tmpTable->impId = (*ppTable)->impId + 1;
tmpTable->dopData = profileData; tmpTable->dopData = profileData;
tmpTable->next = *ppTable; tmpTable->next = *ppTable;
@ -72,9 +94,21 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable )
printf("\n %e %e", profileData[ 0 ][ index ], profileData[ 1 ][ index ]); printf("\n %e %e", profileData[ 0 ][ index ], profileData[ 1 ][ index ]);
} }
*/ */
fclose(fpAscii); EXITPOINT:
return; 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 */ /* interface routine based on notes provided by Steve Hansen of Stanford */
@ -108,40 +142,45 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable )
*/ */
void int readSupremData(const char *fileName, int fileType, int impType,
readSupremData(char *fileName, int fileType, int impType, DOPtable **ppTable) DOPtable **ppTable)
{ {
int xrc = 0;
#define MAX_GRID 500 #define MAX_GRID 500
float x[ MAX_GRID ], conc[ MAX_GRID ]; float x[ MAX_GRID ], conc[ MAX_GRID ];
int index; int index;
DOPtable *tmpTable; DOPtable *tmpTable = (DOPtable *) NULL;
double **profileData; double **profileData = (double **) NULL;
int numNodes; int numNodes;
/* read the Suprem data file */ /* read the Suprem data file */
if ( fileType == 0 ) { /* BINARY 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 { else {
SUPascRead( fileName, x, conc, &impType, &numNodes ); SUPascRead( fileName, x, conc, &impType, &numNodes );
} }
/* allocate 2-D array to read in data of x-coordinate and N(x) */ /* allocate 2-D array to read in data of x-coordinate and N(x) */
XCALLOC( profileData, double *, 2 ); profileData = alloc_profile_data((size_t) numNodes + 1);
for( index = 0; index <= 1; index++ ) {
XCALLOC( profileData[ index ], double, 1 + numNodes );
}
/* the number of points is stored as profileData[0][0] */ /* the number of points is stored as profileData[0][0] */
profileData[0][0] = numNodes; profileData[0][0] = numNodes;
for( index = 1; index <= numNodes; index++ ) { for( index = 1; index <= numNodes; index++ ) {
profileData[ 0 ][ index ] = x[ index ]; profileData[ 0 ][ index ] = x[ index ];
profileData[ 1 ][ index ] = conc[ index ]; profileData[ 1 ][ index ] = conc[ index ];
} }
/* Now create a new lookup table */ /* Now create a new lookup table */
XCALLOC( tmpTable, DOPtable, 1 ); XCALLOC(tmpTable, DOPtable, 1);
if ( *ppTable == NULL ) { if ( *ppTable == NULL ) {
/* First Entry */ /* First Entry */
tmpTable->impId = 1; 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 ]); 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 */ /* 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 * 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/cidersupt.h"
#include "ngspice/cpextern.h"
#include "ngspice/ngspice.h"
#define MAXMAT 10 #define MAXMAT 10
#define MAXIMP 4 #define MAXIMP 4
#define MAXLAYER 10 #define MAXLAYER 10
#define MAXGRID 500 #define MAXGRID 500
#define GFREAD( fp, ptr, type, num ) if (num && (fread( ptr,\ #define GFREAD( fp, ptr, type, num )\
sizeof(type), (unsigned)num, fp ) != (unsigned)num)) {\ if (num && (fread( ptr, sizeof(type), (size_t) num,\
return;\ fp ) != (size_t) num)) {\
} xrc = -1;\
goto EXITPOINT;\
}
#define DEBUG if (0) #define DEBUG if (0)
void int SUPbinRead(const char *inFile, float *x, float *conc, int *impId,
SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod) int *numNod)
{ {
int xrc = 0;
int idata, recordMark; int idata, recordMark;
int ldata; int ldata;
int i, j; int i, j;
@ -37,18 +43,20 @@ SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod)
float xStart; float xStart;
float layerTh[10]; float layerTh[10];
float con[500]; float con[500];
FILE *fpSuprem; FILE *fpSuprem = (FILE *) NULL;
/* Clear Concentration Array */ /* Clear Concentration Array */
for ( i=0; i < MAXGRID; i++ ) { for ( i=0; i < MAXGRID; i++ ) {
conc[i] = 0.0; conc[i] = 0.0;
} }
/* Open Input File */ /* Open Input File */
if ((fpSuprem = fopen( inFile, "r" )) == NULL) { if ((fpSuprem = fopen( inFile, "r" )) == NULL) {
perror(inFile); (void) fprintf(cp_err, "Unable to read file \"%s\": %s.\n",
return; inFile, strerror(errno));
} xrc = -1;
goto EXITPOINT;
}
/* /*
* The first record contains the number of layers (I4), the number of * 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 ); DEBUG fprintf(stderr," %d\n", ldata );
GFREAD( fpSuprem, &recordMark, int, 1 ); 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 */ /* shift silicon layer to beginning of array */
for ( j=numLay; --j >= 0; ) for (j = numLay; --j >= 0; ) {
if (matTyp[ j ] == 1) if (matTyp[j] == 1) {
break; 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; siIndex = j;
@ -223,15 +241,26 @@ SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod)
/* Store number of valid nodes using pointer */ /* Store number of valid nodes using pointer */
*numNod = numGrid; *numNod = numGrid;
return;
}
void EXITPOINT:
SUPascRead(char *inFile, float *x, float *conc, int *impId, int *numNod) 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; int i, j;
float rdata;
char cdata[21]; char cdata[21];
int numLay, numImp, numGrid; int numLay, numImp, numGrid;
int impTyp[4], matTyp[10], topNod[10], siIndex, offset; 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; conc[i] = 0.0;
} }
/* Open Input File */ /* Open Input File */
if ((fpSuprem = fopen( inFile, "r" )) == NULL) { if ((fpSuprem = fopen( inFile, "r" )) == NULL) {
perror(inFile); (void) fprintf(cp_err, "Unable to open file \"%s\": %s.\n",
return; inFile, strerror(errno));
} xrc = -1;
goto EXITPOINT;
}
/* /*
* The first line contains the number of layers (I4), the number of * The first line contains the number of layers (I4), the number of
* impurities (I4), and the number of nodes (I4) present in the structure. * 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); 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 second set of lines contains, for each layer, the material name
* the material type (I4), the layer thickness (R4), and the pointer to * (A20), the material type (I4), the layer thickness (R4), and the
* the top node of the layer (I4), and an unknown int and unknown float. * pointer to the top node of the layer (I4), and an unknown int and
* The material type code: * unknown float.
* 1 - Si *
* 2 - SiO2 * The material type code:
* 3 - Poly * 1 - Si
* 4 - Si3N4 * 2 - SiO2
* 5 - Alum * 3 - Poly
*/ * 4 - Si3N4
for ( i=0; i < numLay; i++ ) { * 5 - Alum
fscanf( fpSuprem, "%s\n %d %e %d %d %e\n", */
cdata, &matTyp[i], &layerTh[i], &topNod[i], &idata, &rdata ); for (i = 0; i < numLay; ++i) {
DEBUG fprintf(stderr,"set 2: %s: %d %f %d\n", int idata;
cdata, matTyp[i], layerTh[i], topNod[i] ); 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;
}
/* DEBUG fprintf(stderr,"set 2: %s: %d %f %d\n",
* The third set of lines contains, for each impurity, the name of the cdata, matTyp[i], layerTh[i], topNod[i]);
* impurity (A20) and the type of impurity (I4). } /* end of loop over layers */
*/
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] );
}
/* /*
* The fourth set of lines contains, for each layer by each impurity, the * The third set of lines contains, for each impurity, the name of the
* integrated dopant (R4), and the interior concentration of the * impurity (A20) and the type of impurity (I4).
* polysilicon grains (R4). */
*/ for (i = 0; i < numImp; ++i) {
for ( j=0; j < numLay; j++ ) { if (fscanf( fpSuprem, "%s\n %d\n", cdata, &impTyp[i]) != 2) {
for ( i=0; i < numImp; i++ ) { (void) fprintf(cp_err, "Unable to read impurity %d "
fscanf( fpSuprem, "%e", &rdata ); "from file \"%s\".\n",
fscanf( fpSuprem, "%e", &rdata ); 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 fifth set of lines contains, for each node in the structure,
* the distance to the next deepest node (R4), the distance from the * the distance to the next deepest node (R4), the distance from the
* surface (R4), and, for each impurity type, the impurity's * surface (R4), and, for each impurity type, the impurity's
* chemical concentration (R4) and the impurity's active concentration (R4). * chemical concentration (R4) and the impurity's active concentration (R4).
*/ */
for ( i=1; i <= numGrid; i++ ) { for (i = 1; i <= numGrid; ++i) {
fscanf( fpSuprem, "%e %e", &rdata, &x[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++ ) { for (j = 0; j < numImp; j++) {
/* chemical concentration - not required */ float junk;
fscanf( fpSuprem, "%e", &con[i] ); /* chemical concentration - not required */
if (fscanf(fpSuprem, "%e", &junk) != 1) {
/* store active concentration */ (void) fprintf(cp_err, "Unable to chemical concentration "
fscanf( fpSuprem, "%e", &con[i] ); "%d of layer %d "
"from file \"%s\".\n",
j + 1, i + 1, inFile);
xrc = -1;
goto EXITPOINT;
}
/* orient sign properly */ /* store active concentration */
if (impTyp[j] == *impId) { if (fscanf(fpSuprem, "%e", &con[i]) != 1) {
/*...Boron...*/ (void) fprintf(cp_err, "Unable to active concentration "
if (impTyp[j] == 1) { "%d of layer %d "
conc[i] = - con[i]; "from file \"%s\".\n",
} else { j + 1, i + 1, inFile);
/*...All Other Impurities: P, As, Sb ...*/ xrc = -1;
conc[i] = con[i]; 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;
} }
} fpSuprem = (FILE *) NULL;
DEBUG fprintf( stderr, "set 5: %e %e\n", x[1], conc[1] );
/* /* shift silicon layer to beginning of array */
* The last line in the file contains some random stuff that might be for (j = numLay; --j >= 0; ) {
* useful to some people, the temperature in degrees Kelvin of the last if (matTyp[j] == 1) {
* diffusion step (R4), the phosphorus implant dose (R4), the arsenic break;
* implant flag (L4). However, we can just ignore that stuff. }
*/ }
fclose( fpSuprem );
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 BOOLEAN TWOdeviceConverged(TWOdevice *);
extern void TWOresetJacobian(TWOdevice *); extern void TWOresetJacobian(TWOdevice *);
extern void TWOstoreNeutralGuess(TWOdevice *); extern void TWOstoreNeutralGuess(TWOdevice *);
extern void TWOequilSolve(TWOdevice *); extern int TWOequilSolve(TWOdevice *);
extern void TWObiasSolve(TWOdevice *, int, BOOLEAN, TWOtranInfo *); extern void TWObiasSolve(TWOdevice *, int, BOOLEAN, TWOtranInfo *);
extern void TWOstoreEquilibGuess(TWOdevice *); extern void TWOstoreEquilibGuess(TWOdevice *);
extern void TWOstoreInitialGuess(TWOdevice *); extern void TWOstoreInitialGuess(TWOdevice *);

View File

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

View File

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

View File

@ -10,7 +10,7 @@ char *prompt(FILE *fp);
wordlist *process(wordlist *wlist); wordlist *process(wordlist *wlist);
void arg_print(const wordlist *wl, const struct comm *command); void arg_print(const wordlist *wl, const struct comm *command);
void arg_plot(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_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);
void arg_display(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 #ifndef ngspice_COM_ALIAS_H
#define ngspice_COM_ALIAS_H #define ngspice_COM_ALIAS_H
#include "ngspice/wordlist.h"
void com_alias(wordlist *wl); void com_alias(wordlist *wl);
void com_unalias(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))) if (!cp_getvar("lprplot5", CP_STRING, format, sizeof(format)))
strcpy(format, SYSTEM_PLOT5LPR); strcpy(format, SYSTEM_PLOT5LPR);
(void) sprintf(buf, format, device, fname); (void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); if (system(buf) == -1) {
(void) system(buf); fprintf(cp_out, "Printing %s on the %s printer failed.\n",
printed = 1; fname, device);
}
else {
fprintf(cp_out, "Printing %s on the %s printer OK.\n",
fname, device);
printed = 1;
}
} }
#endif #endif
#ifdef SYSTEM_PSLPR #ifdef SYSTEM_PSLPR
@ -199,9 +205,15 @@ void com_hardcopy(wordlist *wl)
if (!cp_getvar("lprps", CP_STRING, format, sizeof(format))) if (!cp_getvar("lprps", CP_STRING, format, sizeof(format)))
strcpy(format, SYSTEM_PSLPR); strcpy(format, SYSTEM_PSLPR);
(void) sprintf(buf, format, device, fname); (void) sprintf(buf, format, device, fname);
fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); if (system(buf) == -1) {
(void) system(buf); fprintf(cp_out, "Printing %s on the %s printer failed.\n",
printed = 1; fname, device);
}
else {
fprintf(cp_out, "Printing %s on the %s printer OK.\n",
fname, device);
printed = 1;
}
} }
#endif #endif
} }

View File

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

View File

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

View File

@ -265,7 +265,14 @@ static void set_static_system_info(void)
system_info.osName = TMALLOC(char, size + 1); system_info.osName = TMALLOC(char, size + 1);
rewind(file); 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); fclose(file);
system_info.osName[size] = '\0'; system_info.osName[size] = '\0';
@ -287,7 +294,12 @@ static void set_static_system_info(void)
/* get complete string */ /* get complete string */
inStr = TMALLOC(char, size+1); inStr = TMALLOC(char, size+1);
rewind(file); 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'; inStr[size] = '\0';
{ {
@ -377,7 +389,7 @@ static void set_static_system_info(void)
* } * }
*/ */
tfree(inStr); txfree(inStr);
fclose(file); fclose(file);
} /* end of case that file was opened OK */ } /* 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 ')' */ size_t n = strlen(p_start) - 1; /* copy all but final ')' */
ds_case_t case_type = make_i_name_lower ? ds_case_t case_type = make_i_name_lower ?
ds_case_lower : ds_case_as_is; ds_case_lower : ds_case_as_is;
bool f_ok = ds_cat_mem_case(dbuf_p, p_start, (int) n, bool f_ok = ds_cat_mem_case(dbuf_p, p_start, n, case_type) == DS_E_OK;
case_type) == DS_E_OK;
f_ok &= ds_cat_mem(dbuf_p, sz_branch, f_ok &= ds_cat_mem(dbuf_p, sz_branch,
sizeof sz_branch / sizeof *sz_branch - 1) == DS_E_OK; sizeof sz_branch / sizeof *sz_branch - 1) == DS_E_OK;
if (!f_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); int rc = get_bracketed_dim(p, data + n_dim);
if (rc <= 0) { /* error or normal exit */ if (rc <= 0) { /* error or normal exit */
*p_n_dim = n_dim; *p_n_dim = (int) n_dim;
return !!rc; return !!rc;
} }
p += rc; /* step after the dimension that was processed */ 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; ++p;
break; break;
case ']': /* ] ended scan */ case ']': /* ] ended scan */
*p_n_dim = n_dim; *p_n_dim = (int) n_dim;
return (int) (p - p0) + 1; return (int) (p - p0) + 1;
case '\0': /* end of string ended scan */ case '\0': /* end of string ended scan */
*p_n_dim = n_dim; *p_n_dim = (int) n_dim;
return 0; return 0;
default: /* invalid char */ default: /* invalid char */
return -1; return -1;
@ -347,7 +347,7 @@ static int get_dim(const char *p, int *p_val)
const char *p0 = p; const char *p0 = p;
for ( ; ; ++p) { for ( ; ; ++p) {
const char c_cur = *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; unsigned int val_new;
if (digit_cur > 9) { /* not a digit */ if (digit_cur > 9) { /* not a digit */
if ((*p_val = (int) val) < 0) { /* overflow */ 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 void DevDrawText(const char *text, int x, int y, int angle)
DevDrawText(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 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 DevClear(void);
void DevDrawLine(int x1, int y1, int x2, int y2, bool isgrid); 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 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 DefineColor(int colorid, double red, double green, double blue);
void DefineLinestyle(int linestyleid, int mask); void DefineLinestyle(int linestyleid, int mask);
void SetLinestyle(int linestyleid); void SetLinestyle(int linestyleid);
void SetColor(int colorid, GRAPH* graph); void SetColor(int colorid);
void DevUpdate(void); void DevUpdate(void);
void DatatoScreen(GRAPH *graph, double x, double y, int *screenx, int *screeny); void DatatoScreen(GRAPH *graph, double x, double y, int *screenx, int *screeny);
void Input(REQUEST *request, RESPONSE *response); void Input(REQUEST *request, RESPONSE *response);

View File

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

View File

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

View File

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

View File

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

View File

@ -1390,8 +1390,7 @@ com_edit(wordlist *wl)
fprintf(cp_out, "run circuit? "); fprintf(cp_out, "run circuit? ");
fflush(cp_out); fflush(cp_out);
fgets(buf, BSIZE_SP, stdin); if (fgets(buf, BSIZE_SP, stdin) == (char *) NULL || buf[0] != 'n') {
if (buf[0] != 'n') {
fprintf(cp_out, "running circuit\n"); fprintf(cp_out, "running circuit\n");
com_run(NULL); 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 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/ngspice.h"
#include "ngspice/cpdefs.h" #include "ngspice/cpdefs.h"
#include "ngspice/ftedefs.h" #include "ngspice/ftedefs.h"
#include "ngspice/dvec.h" #include "ngspice/dvec.h"
#include "ngspice/iferrmsg.h" #include "ngspice/iferrmsg.h"
#include "ftehelp.h"
#include "ngspice/hlpdefs.h" #include "ngspice/hlpdefs.h"
#include "misccoms.h"
#include "postcoms.h"
#include "circuits.h"
#include "variable.h"
#include "plotting/graf.h" #include "plotting/graf.h"
#include "display.h" #include "plotting/plotit.h"
#include "../misc/ivars.h" #include "postcoms.h"
#include "com_alias.h"
#include "define.h"
#include "runcoms2.h" #include "runcoms2.h"
#include "variable.h"
#ifdef HAVE_GNUREADLINE #ifdef HAVE_GNUREADLINE
#include <readline/readline.h> #include <readline/readline.h>
@ -38,7 +39,6 @@ extern void rem_controls(void);
extern IFsimulator SIMinfo; extern IFsimulator SIMinfo;
extern void spice_destroy_devices(void); /* FIXME need a better place */ extern void spice_destroy_devices(void); /* FIXME need a better place */
extern void pl_rempar(void); /* plotit.c */
static void byemesg(void); static void byemesg(void);
static int confirm_quit(void); static int confirm_quit(void);
@ -136,7 +136,10 @@ com_bug(wordlist *wl)
Bug_Addr); Bug_Addr);
(void) sprintf(buf, SYSTEM_MAIL, ft_sim->simulator, ft_sim->version, 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"); 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); 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); controlled_exit(-1);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -317,7 +317,7 @@ void gr_point(struct dvec *dv,
return; return;
} }
} }
SetColor(dv->v_color, currentgraph); SetColor(dv->v_color);
switch (currentgraph->plottype) { switch (currentgraph->plottype) {
double *tics; double *tics;
@ -477,7 +477,7 @@ void drawlegend(GRAPH *graph, int plotno, struct dvec *dv)
const int y = graph->absolute.height - graph->fontheight const int y = graph->absolute.height - graph->fontheight
- ((plotno + 2) / 2) * (graph->fontheight); - ((plotno + 2) / 2) * (graph->fontheight);
const int i = y + graph->fontheight / 2 + 1; const int i = y + graph->fontheight / 2 + 1;
SetColor(dv->v_color, graph); SetColor(dv->v_color);
if (graph->plottype == PLOT_POINT) { if (graph->plottype == PLOT_POINT) {
char buf[16]; char buf[16];
(void) sprintf(buf, "%c : ", dv->v_linestyle); (void) sprintf(buf, "%c : ", dv->v_linestyle);
@ -487,7 +487,7 @@ void drawlegend(GRAPH *graph, int plotno, struct dvec *dv)
SetLinestyle(dv->v_linestyle); SetLinestyle(dv->v_linestyle);
DevDrawLine(x, i, x + graph->viewport.width / 20, i, FALSE); DevDrawLine(x, i, x + graph->viewport.width / 20, i, FALSE);
} }
SetColor(1, graph); SetColor(1);
DevDrawText(dv->v_name, x + graph->viewport.width / 20 DevDrawText(dv->v_name, x + graph->viewport.width / 20
+ graph->fontwidth, y, 0); + graph->fontwidth, y, 0);
} }
@ -641,7 +641,7 @@ void gr_restoretext(GRAPH *graph)
/* restore text */ /* restore text */
for (k = graph->keyed; k; k = k->next) { for (k = graph->keyed; k; k = k->next) {
SetColor(k->colorindex, graph); SetColor(k->colorindex);
DevDrawText(k->text, k->x, k->y, 0); DevDrawText(k->text, k->x, k->y, 0);
} }
} }
@ -738,7 +738,7 @@ static int iplot(struct plot *pl, int id)
for (yt = pl->pl_dvecs->v_type, v = pl->pl_dvecs->v_next; v; for (yt = pl->pl_dvecs->v_type, v = pl->pl_dvecs->v_next; v;
v = v->v_next) { 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; yt = SV_NOTYPE;
break; 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) if (graph->grid.gridtype == GRID_NONE)
graph->grid.gridtype = GRID_LIN; graph->grid.gridtype = GRID_LIN;
SetColor(1, graph); SetColor(1);
SetLinestyle(1); SetLinestyle(1);
if ((graph->data.xmin > graph->data.xmax) || if ((graph->data.xmin > graph->data.xmax) ||
@ -132,7 +132,7 @@ void
gr_redrawgrid(GRAPH *graph) gr_redrawgrid(GRAPH *graph)
{ {
SetColor(1, graph); SetColor(1);
SetLinestyle(1); SetLinestyle(1);
/* draw labels */ /* draw labels */
if (graph->grid.xlabel) { if (graph->grid.xlabel) {
@ -182,9 +182,10 @@ gr_redrawgrid(GRAPH *graph)
#ifdef HAS_WINGUI #ifdef HAS_WINGUI
/* x axis centered to graphics on Windows */ /* x axis centered to graphics on Windows */
/* utf-8: figure out the real length of the x label */ /* utf-8: figure out the real length of the x label */
wchar_t *wtext; const int n_byte_wide = 2 * (int) strlen(graph->grid.xlabel) + 1;
wtext = TMALLOC(wchar_t, 2 * 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, 2 * strlen(graph->grid.xlabel) + 1); int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.xlabel, -1,
wtext, n_byte_wide);
if (wlen == 0) { if (wlen == 0) {
fprintf(stderr, "UTF-8 to wide char conversion failed with 0x%x\n", GetLastError()); 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); fprintf(stderr, "%s could not be converted\n", graph->grid.xlabel);
@ -206,6 +207,7 @@ gr_redrawgrid(GRAPH *graph)
else else
unitshift = 0; /* reset for next plot window */ unitshift = 0; /* reset for next plot window */
} }
txfree(wtext);
} }
#endif #endif
#endif // EXT_ASC #endif // EXT_ASC
@ -221,26 +223,34 @@ gr_redrawgrid(GRAPH *graph)
(graph->absolute.height * 3) / 4, 0); (graph->absolute.height * 3) / 4, 0);
} else { } else {
if (eq(dispdev->name, "postscript")) if (eq(dispdev->name, "postscript")) {
DevDrawText(graph->grid.ylabel, DevDrawText(graph->grid.ylabel,
graph->fontwidth, graph->fontwidth,
/*vertical text, midpoint in y is aligned midpoint of text string */ /* vertical text, midpoint in y is aligned midpoint
(graph->absolute.height - strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90); * of text string */
(graph->absolute.height - (int) strlen(
graph->grid.ylabel) * graph->fontwidth) / 2,
90);
}
#ifdef EXT_ASC #ifdef EXT_ASC
else if (eq(dispdev->name, "Windows")) else if (eq(dispdev->name, "Windows"))
DevDrawText(graph->grid.ylabel, DevDrawText(graph->grid.ylabel,
graph->fontwidth, graph->fontwidth,
/*vertical text, midpoint in y is aligned midpoint of text string */ /* vertical text, midpoint in y is aligned midpoint
(graph->absolute.height - strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90); * of text string */
(graph->absolute.height - (int) strlen(
graph->grid.ylabel) * graph->fontwidth) / 2,
90);
#else #else
#ifdef HAS_WINGUI #ifdef HAS_WINGUI
/* Windows and UTF-8: check for string length (in pixels), /* Windows and UTF-8: check for string length (in pixels),
place vertical text centered in y with respect to grid */ place vertical text centered in y with respect to grid */
else if (eq(dispdev->name, "Windows")) { else if (eq(dispdev->name, "Windows")) {
/* utf-8: figure out the real length of the y label */ /* utf-8: figure out the real length of the y label */
wchar_t *wtext; const int n_byte_wide = 2 * (int) strlen(graph->grid.ylabel) + 1;
wtext = TMALLOC(wchar_t, 2 * 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, 2 * strlen(graph->grid.ylabel) + 1); int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.ylabel, -1,
wtext, n_byte_wide);
if (wlen == 0) { if (wlen == 0) {
fprintf(stderr, "UTF-8 to wide char conversion failed with 0x%x\n", GetLastError()); 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); 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 */ /*vertical text, midpoint in y is aligned midpoint of text string */
(graph->absolute.height - (int)(1.2*sz.cx + tmw.tmOverhang)) / 2, 90); (graph->absolute.height - (int)(1.2*sz.cx + tmw.tmOverhang)) / 2, 90);
} }
txfree(wtext);
} }
#endif #endif
#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 /* Let's be lazy and just draw everything -- we won't get called too
* much and the circles get clipped anyway... * much and the circles get clipped anyway...
*/ */
SetColor(18, graph); SetColor(18);
cliparc((double) (centx + xoffset + radoff - rad), cliparc((double) (centx + xoffset + radoff - rad),
(double) (centy + yoffset), rad, 2*angle, (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); M_PI - 2 * angle, centx, centy, maxrad, 0);
/* Draw the upper and lower circles. */ /* Draw the upper and lower circles. */
SetColor(19, graph); SetColor(19);
aclip = cliparc((double) (centx + xoffset + radoff), aclip = cliparc((double) (centx + xoffset + radoff),
(double) (centy + yoffset + irad), irad, (double) (centy + yoffset + irad), irad,
(double) (M_PI * 1.5 + 2 * iangle), (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)); xlab = (int)(centx + xoffset + radoff + irad * cos(aclip));
ylab = (int)(centy + yoffset + irad * (1 + sin(aclip))); ylab = (int)(centy + yoffset + irad * (1 + sin(aclip)));
if ((ylab - gr_ycenter) > graph->fontheight) { if ((ylab - gr_ycenter) > graph->fontheight) {
SetColor(1, graph); SetColor(1);
adddeglabel(graph, pdeg, xlab, ylab, adddeglabel(graph, pdeg, xlab, ylab,
gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter); 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, adddeglabel(graph, ndeg, xlab, ylab,
gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter); gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter);
*/ */
SetColor(19, graph); SetColor(19);
} }
} }
aclip = cliparc((double) (centx + xoffset + radoff), 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)) { if ((aclip >= 0 && aclip < 2*M_PI - M_PI/180) && (pdeg < 359)) {
xlab = (int)(centx + xoffset + radoff + irad * cos(aclip)); xlab = (int)(centx + xoffset + radoff + irad * cos(aclip));
ylab = (int)(centy + yoffset + irad * (sin(aclip) - 1)); ylab = (int)(centy + yoffset + irad * (sin(aclip) - 1));
SetColor(1, graph); SetColor(1);
adddeglabel(graph, ndeg, xlab, ylab, adddeglabel(graph, ndeg, xlab, ylab,
gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter); gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter);
SetColor(19, graph); SetColor(19);
} }
/* Now toss the labels on... */ /* Now toss the labels on... */
SetColor(1, graph); SetColor(1);
x = centx + xoffset + (int)radoff - 2 * (int)rad - x = centx + xoffset + (int)radoff - 2 * (int)rad -
gi_fntwidth * (int) strlen(plab) - 2; 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; int savedlstyle;
NG_IGNORE(angle); NG_IGNORE(angle);
@ -211,10 +211,9 @@ int Plt5_SetLinestyle(int linestyleid)
/* ARGSUSED */ /* ARGSUSED */
int Plt5_SetColor(int colorid, GRAPH *graph) int Plt5_SetColor(int colorid)
{ {
NG_IGNORE(colorid); NG_IGNORE(colorid);
NG_IGNORE(graph);
/* do nothing */ /* do nothing */
return 0; return 0;

View File

@ -27,33 +27,30 @@ static char *xlabel = NULL, *ylabel = NULL, *title = NULL;
#include "ngspice/tclspice.h" #include "ngspice/tclspice.h"
#endif #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) void pl_rempar(void)
{ {
txfree(xcompress); tfree(xcompress);
txfree(xindices); tfree(xindices);
txfree(xlim); tfree(xlim);
txfree(ylim); tfree(ylim);
txfree(xdelta); tfree(xdelta);
txfree(ydelta); tfree(ydelta);
txfree(xlabel); tfree(xlabel);
txfree(ylabel); 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 /* 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 pnode *pn, *names;
struct dvec *d = NULL, *vecs = NULL, *lv, *lastvs = NULL; struct dvec *d = NULL, *vecs = NULL, *lv, *lastvs = NULL;
char *xn; char *xn;
int i, y_type, xt; int i, xt;
wordlist *wwl; wordlist *wwl;
char *nxlabel = NULL, *nylabel = NULL, *ntitle = NULL; char *nxlabel = NULL, *nylabel = NULL, *ntitle = NULL;
double tstep, tstart, tstop, ttime; 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")) { if (devname && eq(devname, "gnuplot")) {
/* Interface to Gnuplot Plot Program */ /* Interface to Gnuplot Plot Program */

View File

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

View File

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

View File

@ -803,13 +803,9 @@ com_cross(wordlist *wl)
vec_remove(newvec); vec_remove(newvec);
v = dvec_alloc(copy(newvec), v = dvec_alloc(copy(newvec),
vecs (int) (vecs ? vecs->v_type : SV_NOTYPE),
? vecs->v_type comp ? (VF_COMPLEX | VF_PERMANENT) : (VF_REAL | VF_PERMANENT),
: SV_NOTYPE, i, NULL);
comp
? (VF_COMPLEX | VF_PERMANENT)
: (VF_REAL | VF_PERMANENT),
i, NULL);
/* Now copy the ind'ths elements into this one. */ /* Now copy the ind'ths elements into this one. */
for (n = vecs, i = 0; n; n = n->v_link2, i++) 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_LinestyleColor(int linestyleid, int colorid);
void PS_SelectColor(int colorid); void PS_SelectColor(int colorid);
void PS_Stroke(void); 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 */ /* 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))) { if (!cp_getvar("hcopyscale", CP_STRING, psscale, sizeof(psscale))) {
scale = 1.0; scale = 1.0;
} else { }
sscanf(psscale, "%lf", &scale); else if (sscanf(psscale, "%lf", &scale) != 1) {
if ((scale <= 0) || (scale > 10)) (void) fprintf(cp_err, "Error getting scale value\n");
scale = 1.0; 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); dispdev->numlinestyles = NUMELEMS(linestyle);
/* plot color */ /* 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; int savedlstyle, savedcolor;
char *text;
#ifndef EXT_ASC #ifdef EXT_ASC
utf8_to_latin9(text, text, strlen(text)); 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 #endif
/* set linestyle to solid /* set linestyle to solid
or may get funny color text on some plotters */ 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); PS_SetLinestyle(SOLID);
/* set text color to black if background is not white */ /* set text color to black if background is not white */
if (setbgcolor > 0) if (setbgcolor > 0)
PS_SetColor(0, currentgraph); PS_SetColor(0);
else else
PS_SetColor(1, currentgraph); PS_SetColor(1);
/* if color is given by set hcopytxpscolor=settxcolor, give it a try */ /* if color is given by set hcopytxpscolor=settxcolor, give it a try */
if (settxcolor >= 0) if (settxcolor >= 0)
PS_SetColor(settxcolor, currentgraph); PS_SetColor(settxcolor);
/* stroke the path if there's an open one */ /* stroke the path if there's an open one */
PS_Stroke(); PS_Stroke();
/* move to (x, y) */ /* move to (x, y) */
@ -431,8 +443,13 @@ int PS_Text(char *text, int x, int y, int angle)
/* restore old linestyle */ /* restore old linestyle */
PS_SetColor(savedcolor, currentgraph); PS_SetColor(savedcolor);
PS_SetLinestyle(savedlstyle); PS_SetLinestyle(savedlstyle);
#ifndef EXT_ASC
txfree(text);
#endif
return 0; 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); PS_LinestyleColor(currentgraph->linestyle, colorid);
return 0; 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. * 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 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; unsigned char *out = (unsigned char *)output;
const unsigned char *in = (const unsigned char *)input; const unsigned char *in = (const unsigned char *)input;

View File

@ -464,7 +464,11 @@ raw_read(char *name) {
} }
s = SKIP(buf); s = SKIP(buf);
if (!*s) { 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; s = buf;
} }
if (numdims == 0) { if (numdims == 0) {
@ -490,7 +494,10 @@ raw_read(char *name) {
if (!i) { if (!i) {
curpl->pl_scale = v; curpl->pl_scale = v;
} else { } 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 = buf;
} }
s = nexttok(s); /* The strchr field. */ s = nexttok(s); /* The strchr field. */
@ -591,7 +598,10 @@ raw_read(char *name) {
for (i = 0; i < npoints; i++) { for (i = 0; i < npoints; i++) {
if (is_ascii) { if (is_ascii) {
/* It's an ASCII file. */ /* 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) { for (v = curpl->pl_dvecs; v; v = v->v_next) {
if (i < v->v_length) { if (i < v->v_length) {
if (flags & VF_REAL) { if (flags & VF_REAL) {
@ -657,7 +667,7 @@ raw_read(char *name) {
return (NULL); return (NULL);
} }
} }
} } /* end of loop */
if (curpl) { /* reverse commands list */ if (curpl) { /* reverse commands list */
for (wl = curpl->pl_commands, curpl->pl_commands = NULL; 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) #if defined(HAVE_WIN32) || defined(HAVE__PROC_MEMINFO)
static int get_procm(struct proc_mem *memall); 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 sys_mem mem_t, mem_t_act;
struct proc_mem mem_ng, mem_ng_act; struct proc_mem mem_ng, mem_ng_act;
#endif #endif
#if defined(HAVE_WIN32) && defined(SHARED_MODULE) && defined(__MINGW32__)
static int get_sysmem(struct sys_mem *memall);
#endif
void void
init_rlimits(void) init_rlimits(void)
@ -431,10 +433,13 @@ static int get_procm(struct proc_mem *memall) {
} else } else
return 0; return 0;
#else #else
/* Use Windows GlobalMemoryStatus or /proc/memory to obtain size of memory - not accurate */ /* Use Windows GlobalMemoryStatus or /proc/memory to obtain size of memory -
get_sysmem(&mem_t_act); /* size is the difference between free memory at start time and now */ * 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 */ 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 else
memall->size = 0; /* sure, it is more */ memall->size = 0; /* sure, it is more */
memall->resident = 0; memall->resident = 0;
@ -476,8 +481,8 @@ static int get_procm(struct proc_mem *memall) {
} }
static int #if defined(HAVE_WIN32) && defined(SHARED_MODULE) && defined(__MINGW32__)
get_sysmem(struct sys_mem *memall) static int get_sysmem(struct sys_mem *memall)
{ {
#ifdef HAVE_WIN32 #ifdef HAVE_WIN32
#if (_WIN32_WINNT >= 0x0500) #if (_WIN32_WINNT >= 0x0500)
@ -542,6 +547,7 @@ get_sysmem(struct sys_mem *memall)
#endif #endif
return 1; return 1;
} }
#endif
#else #else

View File

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

View File

@ -1386,7 +1386,11 @@ void com_snload(wordlist *wl)
return; 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)) { if (tmpI != sizeof(CKTcircuit)) {
fprintf(cp_err, "loaded num: %d, expected num: %ld\n", tmpI, (long)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"); 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); 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 _t(name) ckt->name = my_ckt->name
#define _ta(name, size) \ #define _ta(name, size) \
@ -1484,17 +1492,24 @@ void com_snload(wordlist *wl)
#define _foo(name, type, _size) \ #define _foo(name, type, _size) \
do { \ do { \
int __i; \ int __i; \
fread(&__i, sizeof(int), 1, file); \ if (fread(&__i, sizeof(int), 1, file) == 1 && __i > 0) { \
if (__i) { \ if (name) { \
if (name) \ txfree(name); \
tfree(name); \ } \
name = (type *)tmalloc((size_t) __i); \ name = (type *) tmalloc((size_t) __i); \
fread(name, 1, (size_t) __i, file); \ if (fread(name, 1, (size_t) __i, file) != (size_t) __i) { \
} else { \ (void) fprintf(cp_err, \
"Unable to read vector " #name "\n"); \
break; \
} \
} \
else { \
fprintf(cp_err, "size for vector " #name " is 0\n"); \ fprintf(cp_err, "size for vector " #name " is 0\n"); \
} \ } \
if ((_size) != -1 && __i != (_size) * (int)sizeof(type)) { \ if ((_size) != -1 && __i != \
fprintf(cp_err, "expected %ld, but got %d for "#name"\n", (_size)*(long)sizeof(type), __i); \ (int) (_size) * (int) sizeof(type)) { \
fprintf(cp_err, "expected %ld, but got %d for "#name"\n", \
(_size)*(long)sizeof(type), __i); \
} \ } \
} while(0) } while(0)

View File

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

View File

@ -75,7 +75,7 @@ static struct plotab plotabs[NUMPLOTTYPES] = {
{ "ac", "ac", FALSE, FALSE }, { "ac", "ac", FALSE, FALSE },
{ "pz", "pz", FALSE, FALSE }, { "pz", "pz", FALSE, FALSE },
{ "pz", "p.z.", FALSE, FALSE }, { "pz", "p.z.", FALSE, FALSE },
{ "pz", "pole-zero", FALSE}, { "pz", "pole-zero", FALSE, FALSE},
{ "disto", "disto", FALSE, FALSE }, { "disto", "disto", FALSE, FALSE },
{ "dist", "dist", FALSE, FALSE }, { "dist", "dist", FALSE, FALSE },
{ "noise", "noise", 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); DS_CREATE(ds, 100);
const char * const node_start = word + 2; const char * const node_start = word + 2;
bool ds_ok = ds_cat_mem(&ds, node_start, 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 i(node) or I(node), append #branch */
if (tolower(word[0]) == (int) 'i') { if (tolower(word[0]) == (int) 'i') {
/* i(node) or I(node) */ /* i(node) or I(node) */
@ -809,7 +810,8 @@ struct dvec *vec_copy(struct dvec *v) {
nv->v_numdims = v->v_numdims; nv->v_numdims = v->v_numdims;
/* Copy defined dimensions */ /* 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_plot = v->v_plot;
nv->v_next = NULL; nv->v_next = NULL;
@ -1286,10 +1288,10 @@ vec_mkfamily(struct dvec *v) {
d->v_dims[0] = size; d->v_dims[0] = size;
if (isreal(v)) { 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)); (size_t) size * sizeof(double));
} else { } 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)); (size_t) size * sizeof(ngcomplex_t));
} }
/* Add one to the counter. */ /* Add one to the counter. */

View File

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

View File

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

View File

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

View File

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

View File

@ -41,7 +41,7 @@ struct comm {
int co_maxargs; int co_maxargs;
/* The fn that prompts the user. */ /* 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]) .. */ /* When these are printed, printf(string, av[0]) .. */
char *co_help; char *co_help;

View File

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

View File

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

View File

@ -10,6 +10,9 @@ Author: 1987 Jeffrey M. Hsu
#ifndef ngspice_FTEDEV_H #ifndef ngspice_FTEDEV_H
#define ngspice_FTEDEV_H #define ngspice_FTEDEV_H
#include "ngspice/bool.h"
#include "ngspice/typedefs.h"
struct graph; struct graph;
struct request; struct request;
struct response; struct response;
@ -20,11 +23,11 @@ typedef int disp_fn_Close_t (void);
typedef int disp_fn_Clear_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_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_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_DefineColor_t (int colorid, double red, double green, double blue);
typedef int disp_fn_DefineLinestyle_t (int linestyleid, int mask); typedef int disp_fn_DefineLinestyle_t (int linestyleid, int mask);
typedef int disp_fn_SetLinestyle_t (int linestyleid); 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_Update_t (void);
typedef int disp_fn_Track_t (void); typedef int disp_fn_Track_t (void);
typedef int disp_fn_MakeMenu_t (void); typedef int disp_fn_MakeMenu_t (void);

View File

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

View File

@ -544,14 +544,18 @@ prompt(void)
s = "->"; s = "->";
while (*s) { while (*s) {
char c = (char) (*s++); char c = (*s++);
/* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (c) { switch (c) {
case '!': case '!':
p += sprintf(p, "%d", where_history() + 1); p += sprintf(p, "%d", where_history() + 1);
break; break;
case '\\': case '\\': /* skip an escape char */
if (*s) if (*s)
c = (char) (*s++); c = (char) (*s++);
/* FALLTHROUGH */
default: default:
*p++ = c; *p++ = c;
break; break;
@ -799,8 +803,11 @@ int main(int argc, char **argv)
{ {
char log_file[BSIZE_SP]; char log_file[BSIZE_SP];
char soa_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 iflag = FALSE; /* flag for interactive mode */
bool qflag = FALSE; /* flag for command completion */ bool qflag = FALSE; /* flag for command completion */
@ -910,7 +917,7 @@ int main(int argc, char **argv)
} }
else { else {
DS_CREATE(ds, 100); 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); cp_vset(ds_get_buf(&ds), CP_STRING, eq + 1);
} }
ds_free(&ds); 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/ngspice.h"
#include "ngspice/memory.h" #include "ngspice/memory.h"
#include "ngspice/cpdefs.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 * const c_dst = alloc_c(length);
ngcomplex_t *c_dst_cur = c_dst; ngcomplex_t *c_dst_cur = c_dst;
ngcomplex_t *c_src_cur = (ngcomplex_t *) data; 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++) { 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_real = c_src_cur->cx_real;
c_dst_cur->cx_imag = -c_src_cur->cx_imag; 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 */ /* 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 */ } /* 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); return ((void *) d);
} }
void * void *cx_db(void *data, short int type, int length,
cx_db(void *data, short int type, int length, int *newlength, short int *newtype) int *newlength, short int *newtype)
{ {
int xrc = 0;
double *d = alloc_d(length); double *d = alloc_d(length);
double *dd = (double *) data;
ngcomplex_t *cc = (ngcomplex_t *) data;
double tt;
int i;
*newlength = length; *newlength = length;
*newtype = VF_REAL; *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++) { for (i = 0; i < length; i++) {
tt = cmag(cc[i]); const double tt = cmag(cc[i]);
rcheck(tt > 0, "db"); rcheck(tt > 0, "db");
/* /*
if (tt == 0.0) 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); d[i] = 20.0 * log10(tt);
} }
else }
else {
double *dd = (double *) data;
int i;
for (i = 0; i < length; 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) if (dd[i] == 0.0)
d[i] = 20.0 * - log(HUGE); d[i] = 20.0 * - log(HUGE);
else else
*/ */
d[i] = 20.0 * log10(dd[i]); d[i] = 20.0 * log10(tt);
} }
return ((void *) d); }
}
void * EXITPOINT:
cx_log10(void *data, short int type, int length, int *newlength, short int *newtype) 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) { if (type == VF_COMPLEX) {
ngcomplex_t *c; ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data; ngcomplex_t *cc = (ngcomplex_t *) data;
int i; int i;
c = alloc_c(length); rv = c = alloc_c(length);
*newtype = VF_COMPLEX; *newtype = VF_COMPLEX;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
double td; double td;
@ -298,42 +314,58 @@ cx_log10(void *data, short int type, int length, int *newlength, short int *newt
if (td == 0.0) { if (td == 0.0) {
realpart(c[i]) = - log10(HUGE); realpart(c[i]) = - log10(HUGE);
imagpart(c[i]) = 0.0; imagpart(c[i]) = 0.0;
} else { }
else {
realpart(c[i]) = log10(td); realpart(c[i]) = log10(td);
imagpart(c[i]) = atan2(imagpart(cc[i]), imagpart(c[i]) = atan2(imagpart(cc[i]), realpart(cc[i]));
realpart(cc[i]));
} }
} }
return ((void *) c); }
} else { else {
double *d; double *d;
double *dd = (double *) data; double *dd = (double *) data;
int i; int i;
d = alloc_d(length); rv = d = alloc_d(length);
*newtype = VF_REAL; *newtype = VF_REAL;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
rcheck(dd[i] >= 0, "log10"); rcheck(dd[i] >= 0, "log10");
if (dd[i] == 0.0) if (dd[i] == 0.0) {
d[i] = - log10(HUGE); d[i] = - log10(HUGE);
else }
else {
d[i] = log10(dd[i]); 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; *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) { if (type == VF_COMPLEX) {
ngcomplex_t *c; ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data; ngcomplex_t *cc = (ngcomplex_t *) data;
int i;
c = alloc_c(length); rv = c = alloc_c(length);
*newtype = VF_COMPLEX; *newtype = VF_COMPLEX;
int i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
double td; double td;
@ -342,20 +374,21 @@ cx_log(void *data, short int type, int length, int *newlength, short int *newtyp
if (td == 0.0) { if (td == 0.0) {
realpart(c[i]) = - log(HUGE); realpart(c[i]) = - log(HUGE);
imagpart(c[i]) = 0.0; imagpart(c[i]) = 0.0;
} else { }
else {
realpart(c[i]) = log(td); realpart(c[i]) = log(td);
imagpart(c[i]) = atan2(imagpart(cc[i]), imagpart(c[i]) = atan2(imagpart(cc[i]), realpart(cc[i]));
realpart(cc[i]));
} }
} }
return ((void *) c); }
} else { else {
double *d; double *d;
double *dd = (double *) data; double *dd = (double *) data;
int i;
d = alloc_d(length); rv = d = alloc_d(length);
*newtype = VF_REAL; *newtype = VF_REAL;
int i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
rcheck(dd[i] >= 0, "log"); rcheck(dd[i] >= 0, "log");
if (dd[i] == 0.0) if (dd[i] == 0.0)
@ -363,9 +396,20 @@ cx_log(void *data, short int type, int length, int *newlength, short int *newtyp
else else
d[i] = log(dd[i]); 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 * void *
cx_exp(void *data, short int type, int length, int *newlength, short int *newtype) 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++) { for (i = 0; i < length; i++) {
rcheck(tan(degtorad(dd[i])) != 0, "tan"); rcheck(tan(degtorad(dd[i])) != 0, "tan");
d[i] = tan(degtorad(dd[i])); d[i] = tan(degtorad(dd[i]));
} }
EXITPOINT:
if (xrc != 0) { /* Free resources on error */
txfree(d);
d = (double *) NULL;
}
return d; return d;
} } /* end of function d_tan */
static double * static double *
d_tanh(double *dd, int length) d_tanh(double *dd, int length)
@ -641,64 +695,94 @@ d_tanh(double *dd, int length)
return d; return d;
} }
static ngcomplex_t * /* See https://proofwiki.org/wiki/Tangent_of_Complex_Number (formulation 4) among
c_tan(ngcomplex_t *cc, int length) * 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; int i;
c = alloc_c(length);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
double u, v; errno = 0;
ngcomplex_t *p_dst = c + i;
rcheck(cos(degtorad(realpart(cc[i]))) * ngcomplex_t *p_src = cc + i;
cosh(degtorad(imagpart(cc[i]))), "tan"); const double a = p_src->cx_real;
rcheck(sin(degtorad(realpart(cc[i]))) * const double b = p_src->cx_imag;
sinh(degtorad(imagpart(cc[i]))), "tan"); const double u = 2 * degtorad(a);
u = degtorad(realpart(cc[i])); const double v = 2 * degtorad(b);
v = degtorad(imagpart(cc[i])); const double n_r = sin(u);
/* The Lattice C compiler won't take multi-line macros, and const double n_i = sinh(v);
* CMS won't take >80 column lines.... const double d1 = cos(u);
*/ const double d2 = cosh(v);
#define xx1 sin(u) * cosh(v) const double d = d1 + d2;
#define xx2 cos(u) * sinh(v) if (errno != 0 || d == 0.0) {
#define xx3 cos(u) * cosh(v) (void) fprintf(cp_err,
#define xx4 -sin(u) * sinh(v) "Invalid argument %lf + %lf i for compex tangent", a, b);
cdiv(xx1, xx2, xx3, xx4, realpart(c[i]), imagpart(c[i])); txfree(c);
} return (ngcomplex_t *) NULL;
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);
} }
/* multiply by -i */ p_dst->cx_real = n_r / d;
realpart(c[i]) = imagpart(s[0]); p_dst->cx_imag = n_i / d;
imagpart(c[i]) = -1. * realpart(s[0]); } /* end of loop over elements in array */
}
tfree(s);
tfree(t);
return c; 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 * void *
cx_tan(void *data, short int type, int length, int *newlength, short int *newtype) 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; double *dd = (double *) data;
int i; int i;
amplitude_index_t *array_amplitudes; amplitude_index_t * const array_amplitudes = (amplitude_index_t *)
array_amplitudes = (amplitude_index_t *) tmalloc(sizeof(amplitude_index_t) * (size_t) length); tmalloc(sizeof(amplitude_index_t) * (size_t) length);
*newlength = length; *newlength = length;
*newtype = VF_REAL; *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; d[i] = array_amplitudes[i].index;
} }
tfree(array_amplitudes); txfree(array_amplitudes);
/* Otherwise it is 0, but tmalloc zeros the stuff already. */ /* Otherwise it is 0, but tmalloc zeros the stuff already. */
return ((void *) d); 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. */ /* Compute the mean of a vector. */
void * void *cx_mean(void *data, short int type, int length,
cx_mean(void *data, short int type, int length, int *newlength, short int *newtype) int *newlength, short int *newtype)
{ {
if (length == 0) {
(void) fprintf(cp_err, "mean calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = 1; *newlength = 1;
rcheck(length > 0, "mean");
if (type == VF_REAL) { if (type == VF_REAL) {
double *d; double *d;
double *dd = (double *) data; 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 += dd[i];
*d /= length; *d /= length;
return ((void *) d); return ((void *) d);
} else { }
else {
ngcomplex_t *c; ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data; ngcomplex_t *cc = (ngcomplex_t *) data;
int i; 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. */ /* Compute the standard deviation of all elements of a vector. */
void * void *cx_stddev(void *data, short int type, int length,
cx_stddev(void *data, short int type, int length, int *newlength, short int *newtype) 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; *newlength = 1;
rcheck(length > 1, "stddev");
if (type == VF_REAL) { if (type == VF_REAL) {
double *mean = (double *)cx_mean(data, type, length, newlength, newtype); double *p_mean = (double *) cx_mean(data, type, length,
double *d, sum = 0.; newlength, newtype);
double *dd = (double *)data; double mean = *p_mean;
int i; double *d, sum = 0.0;
double *dd = (double *) data;
d = alloc_d(1); d = alloc_d(1);
*newtype = VF_REAL; *newtype = VF_REAL;
for (i = 0; i < length; i++) int i;
sum += (dd[i] - *mean) * (dd[i] - *mean); for (i = 0; i < length; i++) {
const double tmp = dd[i] - mean;
sum += tmp * tmp;
}
*d = sqrt(sum / ((double) length - 1.0)); *d = sqrt(sum / ((double) length - 1.0));
tfree(mean); txfree(p_mean);
return ((void *)d); return (void *) d;
} }
else { else {
ngcomplex_t *cmean = (ngcomplex_t *)cx_mean(data, type, length, newlength, newtype); ngcomplex_t * const p_cmean = (ngcomplex_t *) cx_mean(data, type, length,
double *d, sum = 0., a, b; newlength, newtype);
ngcomplex_t *cc = (ngcomplex_t *)data; const ngcomplex_t cmean = *p_cmean;
int i; 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); d = alloc_d(1);
*newtype = VF_REAL; *newtype = VF_REAL;
int i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
a = realpart(cc[i]) - realpart(*cmean); const double a = realpart(cc[i]) - rmean;
b = imagpart(cc[i]) - imagpart(*cmean); const double b = imagpart(cc[i]) - imean;
sum += a * a + b * b; sum += a * a + b * b;
} }
*d = sqrt(sum / ((double) length - 1.0)); *d = sqrt(sum / ((double) length - 1.0));
tfree(cmean); txfree(p_cmean);
return ((void *)d); return (void *) d;
} }
} } /* end of function cx_stddev */
void * void *
@ -635,35 +658,41 @@ cx_times(void *data1, void *data2, short int datatype1, short int datatype2, int
} }
void * void *cx_mod(void *data1, void *data2, short int datatype1, short int datatype2,
cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, int length) int length)
{ {
int xrc = 0;
void *rv;
double *dd1 = (double *) data1; double *dd1 = (double *) data1;
double *dd2 = (double *) data2; 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)) { 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++) { for (i = 0; i < length; i++) {
r1 = (int)floor(fabs(dd1[i])); const int r1 = (int) floor(fabs(dd1[i]));
rcheck(r1 > 0, "mod"); rcheck(r1 > 0, "mod");
r2 = (int)floor(fabs(dd2[i])); const int r2 = (int)floor(fabs(dd2[i]));
rcheck(r2 > 0, "mod"); rcheck(r2 > 0, "mod");
r3 = r1 % r2; const int r3 = r1 % r2;
d[i] = (double) r3; d[i] = (double) r3;
} }
return ((void *) d); }
} else { else {
c = alloc_c(length); 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++) { for (i = 0; i < length; i++) {
if (datatype1 == VF_REAL) { if (datatype1 == VF_REAL) {
realpart(c1) = dd1[i]; realpart(c1) = dd1[i];
imagpart(c1) = 0.0; imagpart(c1) = 0.0;
} else { }
else {
c1 = cc1[i]; c1 = cc1[i];
} }
if (datatype2 == VF_REAL) { if (datatype2 == VF_REAL) {
@ -672,34 +701,47 @@ cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, int l
} else { } else {
c2 = cc2[i]; c2 = cc2[i];
} }
r1 = (int)floor(fabs(realpart(c1))); const int r1 = (int) floor(fabs(realpart(c1)));
rcheck(r1 > 0, "mod"); rcheck(r1 > 0, "mod");
r2 = (int)floor(fabs(realpart(c2))); const int r2 = (int) floor(fabs(realpart(c2)));
rcheck(r2 > 0, "mod"); rcheck(r2 > 0, "mod");
i1 = (int)floor(fabs(imagpart(c1))); const int i1 = (int) floor(fabs(imagpart(c1)));
rcheck(i1 > 0, "mod"); rcheck(i1 > 0, "mod");
i2 = (int)floor(fabs(imagpart(c2))); const int i2 = (int) floor(fabs(imagpart(c2)));
rcheck(i2 > 0, "mod"); rcheck(i2 > 0, "mod");
r3 = r1 % r2; const int r3 = r1 % r2;
i3 = i1 % i2; const int i3 = i1 % i2;
realpart(c[i]) = (double) r3; realpart(c[i]) = (double) r3;
imagpart(c[i]) = (double) i3; 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. */ /* Routoure JM : Compute the max of a vector. */
void * void *cx_max(void *data, short int type, int length,
cx_max(void *data, short int type, int length, int *newlength, short int *newtype) int *newlength, short int *newtype)
{ {
if (length == 0) {
(void) fprintf(cp_err, "maximum calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = 1; *newlength = 1;
/* test if length >0 et affiche un message d'erreur */
rcheck(length > 0, "mean");
if (type == VF_REAL) { if (type == VF_REAL) {
double largest=0.0; double largest = 0.0;
double *d; double *d;
double *dd = (double *) data; double *dd = (double *) data;
int i; int i;
@ -707,14 +749,18 @@ cx_max(void *data, short int type, int length, int *newlength, short int *newtyp
d = alloc_d(1); d = alloc_d(1);
*newtype = VF_REAL; *newtype = VF_REAL;
largest = dd[0]; largest = dd[0];
for (i = 1; i < length; i++) for (i = 1; i < length; i++) {
if (largest < dd[i]) const double tmp = dd[i];
largest = dd[i]; if (largest < tmp) {
largest = tmp;
}
}
*d = largest; *d = largest;
return ((void *) d); return (void *) d;
} else { }
double largest_real=0.0; else {
double largest_complex=0.0; double largest_real = 0.0;
double largest_complex = 0.0;
ngcomplex_t *c; ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data; ngcomplex_t *cc = (ngcomplex_t *) data;
int i; int i;
@ -723,27 +769,37 @@ cx_max(void *data, short int type, int length, int *newlength, short int *newtyp
*newtype = VF_COMPLEX; *newtype = VF_COMPLEX;
largest_real = realpart(*cc); largest_real = realpart(*cc);
largest_complex = imagpart(*cc); largest_complex = imagpart(*cc);
for (i = 0; i < length; i++) { for (i = 1; i < length; i++) {
if (largest_real < realpart(cc[i])) const double tmpr = realpart(cc[i]);
largest_real = realpart(cc[i]); if (largest_real < tmpr) {
if (largest_complex < imagpart(cc[i])) largest_real = tmpr;
largest_complex = imagpart(cc[i]); }
const double tmpi = imagpart(cc[i]);
if (largest_complex < tmpi) {
largest_complex = tmpi;
}
} }
realpart(*c) = largest_real; realpart(*c) = largest_real;
imagpart(*c) = largest_complex; imagpart(*c) = largest_complex;
return ((void *) c); return (void *) c;
} }
} } /* end of function cx_max */
/* Routoure JM : Compute the min of a vector. */ /* Routoure JM : Compute the min of a vector. */
void * void *cx_min(void *data, short int type, int length,
cx_min(void *data, short int type, int length, int *newlength, short int *newtype) int *newlength, short int *newtype)
{ {
if (length == 0) {
(void) fprintf(cp_err, "minimum calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = 1; *newlength = 1;
/* test if length >0 et affiche un message d'erreur */
rcheck(length > 0, "mean");
if (type == VF_REAL) { if (type == VF_REAL) {
double smallest; double smallest;
double *d; double *d;
@ -753,12 +809,16 @@ cx_min(void *data, short int type, int length, int *newlength, short int *newtyp
d = alloc_d(1); d = alloc_d(1);
*newtype = VF_REAL; *newtype = VF_REAL;
smallest = dd[0]; smallest = dd[0];
for (i = 1; i < length; i++) for (i = 1; i < length; i++) {
if (smallest > dd[i]) const double tmp = dd[i];
smallest = dd[i]; if (smallest > tmp) {
smallest = tmp;
}
}
*d = smallest; *d = smallest;
return ((void *) d); return (void *) d;
} else { }
else {
double smallest_real; double smallest_real;
double smallest_complex; double smallest_complex;
ngcomplex_t *c; 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_real = realpart(*cc);
smallest_complex = imagpart(*cc); smallest_complex = imagpart(*cc);
for (i = 1; i < length; i++) { for (i = 1; i < length; i++) {
if (smallest_real > realpart(cc[i])) const double tmpr = realpart(cc[i]);
smallest_real = realpart(cc[i]); if (smallest_real > tmpr) {
if (smallest_complex > imagpart(cc[i])) smallest_real = tmpr;
smallest_complex = imagpart(cc[i]); }
const double tmpi = imagpart(cc[i]);
if (smallest_complex > tmpi) {
smallest_complex = tmpi;
}
} }
realpart(*c) = smallest_real; realpart(*c) = smallest_real;
imagpart(*c) = smallest_complex; imagpart(*c) = smallest_complex;
return ((void *) c); return (void *) c;
} }
} } /* end of function cx_min */
/* Routoure JM : Compute the differential of a vector. */ /* Routoure JM : Compute the differential of a vector. */
void * void *cx_d(void *data, short int type, int length,
cx_d(void *data, short int type, int length, int *newlength, short int *newtype) int *newlength, short int *newtype)
{ {
if (length == 0) {
(void) fprintf(cp_err, "differential calculation requires "
"at least one element.\n");
return NULL;
}
*newlength = length; *newlength = length;
/* test if length >0 et affiche un message d'erreur */
rcheck(length > 0, "deriv");
if (type == VF_REAL) { if (type == VF_REAL) {
double *d; double *d;
double *dd = (double *) data; 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; *newtype = VF_REAL;
d[0] = dd[1] - dd[0]; d[0] = dd[1] - dd[0];
d[length-1] = dd[length-1] - dd[length-2]; 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]; d[i] = dd[i+1] - dd[i-1];
}
return ((void *) d); return (void *) d;
} else { }
else {
ngcomplex_t *c; ngcomplex_t *c;
ngcomplex_t *cc = (ngcomplex_t *) data; ngcomplex_t *cc = (ngcomplex_t *) data;
int i; 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++) { for (i = 1; i < length - 1; i++) {
realpart(c[i]) = realpart(cc[i+1]) - realpart(cc[i-1]); realpart(c[i]) = realpart(cc[i+1]) - realpart(cc[i-1]);
imagpart(c[i]) = imagpart(cc[i+1]) - imagpart(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 * 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 *cexp_sp3(ngcomplex_t *c); /* cexp exist's in some newer compiler */
static ngcomplex_t *cln(ngcomplex_t *c); static int cln(ngcomplex_t *c, ngcomplex_t *rv);
static ngcomplex_t *ctimes(ngcomplex_t *c1, ngcomplex_t *c2); static void ctimes(ngcomplex_t *c1, ngcomplex_t *c2, ngcomplex_t *rv);
void * void *cx_divide(void *data1, void *data2,
cx_divide(void *data1, void *data2, short int datatype1, short int datatype2, int length) short int datatype1, short int datatype2, int length)
{ {
int xrc = 0;
void *rv;
double *dd1 = (double *) data1; double *dd1 = (double *) data1;
double *dd2 = (double *) data2; double *dd2 = (double *) data2;
double *d;
ngcomplex_t *cc1 = (ngcomplex_t *) data1; ngcomplex_t *cc1 = (ngcomplex_t *) data1;
ngcomplex_t *cc2 = (ngcomplex_t *) data2; ngcomplex_t *cc2 = (ngcomplex_t *) data2;
ngcomplex_t *c, c1, c2; ngcomplex_t *c, c1, c2;
int i; int i;
if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) { if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) {
d = alloc_d(length); double *d;
rv = d = alloc_d(length);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
rcheck(dd2[i] != 0, "divide"); rcheck(dd2[i] != 0, "divide");
d[i] = dd1[i] / dd2[i]; d[i] = dd1[i] / dd2[i];
} }
return ((void *) d); }
} else { else {
c = alloc_c(length); rv = c = alloc_c(length);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (datatype1 == VF_REAL) { if (datatype1 == VF_REAL) {
realpart(c1) = dd1[i]; realpart(c1) = dd1[i];
imagpart(c1) = 0.0; imagpart(c1) = 0.0;
} else { }
else {
c1 = cc1[i]; c1 = cc1[i];
} }
if (datatype2 == VF_REAL) { if (datatype2 == VF_REAL) {
realpart(c2) = dd2[i]; realpart(c2) = dd2[i];
imagpart(c2) = 0.0; imagpart(c2) = 0.0;
} else { }
else {
c2 = cc2[i]; c2 = cc2[i];
} }
rcheck((realpart(c2) != 0) || (imagpart(c2) != 0), "divide"); rcheck((realpart(c2) != 0) || (imagpart(c2) != 0), "divide");
#define xx5 realpart(c1) #define xx5 realpart(c1)
#define xx6 imagpart(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( )" */ /* Should just use "j( )" */
/* The comma operator. What this does (unless it is part of the argument /* 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); return ((void *) c);
} }
void * void *cx_power(void *data1, void *data2,
cx_power(void *data1, void *data2, short int datatype1, short int datatype2, int length) short int datatype1, short int datatype2, int length)
{ {
int xrc = 0;
void *rv;
double *dd1 = (double *) data1; double *dd1 = (double *) data1;
double *dd2 = (double *) data2; 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)) { 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++) { 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]); d[i] = pow(dd1[i], dd2[i]);
} }
return ((void *) d); }
} else { else {
c = alloc_c(length); 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++) { for (i = 0; i < length; i++) {
if (datatype1 == VF_REAL) { if (datatype1 == VF_REAL) {
realpart(c1) = dd1[i]; realpart(c1) = dd1[i];
imagpart(c1) = 0.0; imagpart(c1) = 0.0;
} else { }
else {
c1 = cc1[i]; c1 = cc1[i];
} }
if (datatype2 == VF_REAL) { if (datatype2 == VF_REAL) {
realpart(c2) = dd2[i]; realpart(c2) = dd2[i];
imagpart(c2) = 0.0; imagpart(c2) = 0.0;
} else { }
else {
c2 = cc2[i]; c2 = cc2[i];
} }
if ((realpart(c1) == 0.0) && (imagpart(c1) == 0.0)) { if ((realpart(c1) == 0.0) && (imagpart(c1) == 0.0)) {
realpart(c[i]) = 0.0; realpart(c[i]) = 0.0;
imagpart(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)) */ (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; c[i] = *t;
/* /*
} else { } else {
realpart(c[i]) = pow(realpart(c1), realpart(c[i]) = pow(realpart(c1),
realpart(c2)); realpart(c2));
imagpart(c[i]) = 0.0; 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... */ /* These are unnecessary... Only cx_power uses them... */
@ -175,30 +213,35 @@ cexp_sp3(ngcomplex_t *c)
return (&r); return (&r);
} }
static ngcomplex_t * static int cln(ngcomplex_t *c, ngcomplex_t *rv)
cln(ngcomplex_t *c)
{ {
static ngcomplex_t r; double c_r = c->cx_real;
double c_i = c->cx_imag;
rcheck(cmag(*c) != 0, "ln"); if (c_r == 0 && c_i == 0) {
realpart(r) = log(cmag(*c)); (void) fprintf(cp_err, "Complex log of 0 + i0 is undefined.\n");
if (imagpart(*c) != 0.0) return -1;
imagpart(r) = atan2(imagpart(*c), realpart(*c)); }
else
imagpart(r) = 0.0;
return (&r);
}
static ngcomplex_t * rv->cx_real = log(cmag(*c));
ctimes(ngcomplex_t *c1, ngcomplex_t *c2) 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; rv->cx_real = realpart(*c1) * realpart(*c2) -
realpart(r) = realpart(*c1) * realpart(*c2) -
imagpart(*c1) * imagpart(*c2); imagpart(*c1) * imagpart(*c2);
imagpart(r) = imagpart(*c1) * realpart(*c2) + rv->cx_imag = imagpart(*c1) * realpart(*c2) +
realpart(*c1) * imagpart(*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 < a
* a * b < b * 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; return +1;
} }
@ -283,33 +283,5 @@ static void overflow_error(size_t num, size_t size)
} /* end of function overflow_error */ } /* 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 */ #endif /* #ifndef HAVE_LIBGC */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,8 +24,8 @@ B3SOIFDparam(int param, IFvalue *value, GENinstance *inst,
NG_IGNORE(select); NG_IGNORE(select);
switch(param) switch (param) {
{ case B3SOIFD_W: case B3SOIFD_W:
here->B3SOIFDw = value->rValue; here->B3SOIFDw = value->rValue;
here->B3SOIFDwGiven = TRUE; here->B3SOIFDwGiven = TRUE;
break; break;
@ -105,7 +105,9 @@ B3SOIFDparam(int param, IFvalue *value, GENinstance *inst,
here->B3SOIFDbodySquaresGiven = TRUE; here->B3SOIFDbodySquaresGiven = TRUE;
break; break;
case B3SOIFD_IC: case B3SOIFD_IC:
switch(value->v.numValue){ /* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 5: case 5:
here->B3SOIFDicVPS = *(value->v.vec.rVec+4); here->B3SOIFDicVPS = *(value->v.vec.rVec+4);
here->B3SOIFDicVPSGiven = TRUE; here->B3SOIFDicVPSGiven = TRUE;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -789,45 +789,44 @@ errordetect:
} }
static int static int update_delayed_cnv(CPLine *cp, double h)
update_delayed_cnv(CPLine *cp, double h)
{ {
int i, j, k; int i, j, k;
double *ratio; double *ratio1;
double f; double f;
VI_list *vi; VI_list *vi;
TMS *tms; TMS *tms;
int noL; int noL;
h *= 0.5e-12; h *= 0.5e-12;
ratio = cp->ratio; ratio1 = cp->ratio;
vi = cp->vi_tail; vi = cp->vi_tail;
noL = cp->noL; noL = cp->noL;
for (k = 0; k < noL; k++) /* mode */ 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 (i = 0; i < noL; i++) /* current eqn */
for (j = 0; j < noL; j++) { for (j = 0; j < noL; j++) {
tms = cp->h3t[i][j][k]; tms = cp->h3t[i][j][k];
if (tms == NULL) if (tms == NULL)
continue; 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[0].cnv_i += f * tms->tm[0].c;
tms->tm[1].cnv_i += f * tms->tm[1].c; tms->tm[1].cnv_i += f * tms->tm[1].c;
tms->tm[2].cnv_i += f * tms->tm[2].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[0].cnv_o += f * tms->tm[0].c;
tms->tm[1].cnv_o += f * tms->tm[1].c; tms->tm[1].cnv_o += f * tms->tm[1].c;
tms->tm[2].cnv_o += f * tms->tm[2].c; tms->tm[2].cnv_o += f * tms->tm[2].c;
tms = cp->h2t[i][j][k]; 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[0].cnv_i += f * tms->tm[0].c;
tms->tm[1].cnv_i += f * tms->tm[1].c; tms->tm[1].cnv_i += f * tms->tm[1].c;
tms->tm[2].cnv_i += f * tms->tm[2].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[0].cnv_o += f * tms->tm[0].c;
tms->tm[1].cnv_o += f * tms->tm[1].c; tms->tm[1].cnv_o += f * tms->tm[1].c;
tms->tm[2].cnv_o += f * tms->tm[2].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 static void
poly_matrix( poly_matrix(
double *A[MAX_DIM][MAX_DIM], double *A_in[MAX_DIM][MAX_DIM],
int dim, int deg) int dim, int deg)
{ {
int i, j; int i, j;
for (i = 0; i < dim; i++) for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++) 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 static void matrix_p_mult(
matrix_p_mult( double *A_in[MAX_DIM][MAX_DIM],
double *A[MAX_DIM][MAX_DIM], double *D1[MAX_DIM],
double *D[MAX_DIM],
double *B[MAX_DIM][MAX_DIM], double *B[MAX_DIM][MAX_DIM],
int dim, int deg, int deg_o, int dim, int deg, int deg_o,
Mult_Out X[MAX_DIM][MAX_DIM]) Mult_Out X[MAX_DIM][MAX_DIM])
@ -1480,14 +1479,14 @@ matrix_p_mult(
for (i = 0; i < dim; i++) for (i = 0; i < dim; i++)
for (j = 0; j < dim; j++) { for (j = 0; j < dim; j++) {
p = T[i][j] = (double *) calloc((size_t) (deg_o+1), sizeof(double)); 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 (i = 0; i < dim; i++)
for (j = 0; j < dim; j++) for (j = 0; j < dim; j++)
for (k = 0; k < dim; k++) { for (k = 0; k < dim; k++) {
p = X[i][j].Poly[k] = p = X[i][j].Poly[k] =
(double *) calloc((size_t) (deg_o+1), sizeof(double)); (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]; t1 = X[i][j].C_0[k] = p[0];
if (t1 != 0.0) { if (t1 != 0.0) {
p[0] = 1.0; p[0] = 1.0;
@ -1523,7 +1522,7 @@ matrix_p_mult(
***/ ***/
static double 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 w0, w1, w2, w3, w4, w5;
double a[8]; 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; 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; 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); atten = exp(- delay * y1);
a[1] = y2 / 2.0; a[1] = y2 / 2.0;
@ -2080,8 +2079,7 @@ diag(int dims)
rotate() rotation of the Jacobi's method rotate() rotation of the Jacobi's method
****************************************************************/ ****************************************************************/
static int static int rotate(int dim_in, int p, int q)
rotate(int dim, int p, int q)
{ {
int j; int j;
double co, si; double co, si;
@ -2095,12 +2093,12 @@ rotate(int dim, int p, int q)
co = sqrt((ve + ABS(mu)) / (2.0 * ve)); co = sqrt((ve + ABS(mu)) / (2.0 * ve));
si = SGN(mu) * ld / (2.0 * ve * co); 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]; T[j] = ZY[p][j];
for (j = 0; j < p; j++) for (j = 0; j < p; j++)
T[j] = ZY[j][p]; T[j] = ZY[j][p];
for (j = p+1; j < dim; j++) { for (j = p+1; j < dim_in; j++) {
if (j == q) if (j == q)
continue; continue;
if (j > q) if (j > q)
@ -2108,7 +2106,7 @@ rotate(int dim, int p, int q)
else else
ZY[p][j] = T[j] * co - ZY[j][q] * si; 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) if (j == p)
continue; continue;
ZY[q][j] = T[j] * si + ZY[q][j] * co; 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]; double R[MAX_DIM];
for (j = 0; j < dim; j++) { for (j = 0; j < dim_in; j++) {
T[j] = Sv[j][p]; T[j] = Sv[j][p];
R[j] = Sv[j][q]; 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][p] = T[j] * co - R[j] * si;
Sv[j][q] = T[j] * si + R[j] * co; Sv[j][q] = T[j] * si + R[j] * co;
} }

View File

@ -479,15 +479,11 @@ int load_opus(const char *name)
#endif #endif
/* Give the code model access to facilities provided by ngspice. Note /* Give the code model access to facilities provided by ngspice. */
* 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. */
if ((fetch = dlsym(lib,"CMgetCoreItfPtr")) != (funptr_t) NULL) { if ((fetch = dlsym(lib,"CMgetCoreItfPtr")) != (funptr_t) NULL) {
const struct coreInfo_t ** const core = 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; *core = &coreInfo;
} }
else { else {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ MOS1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0)) if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1; scale = 1;
switch(param) { switch (param) {
case MOS1_TEMP: case MOS1_TEMP:
here->MOS1temp = value->rValue+CONSTCtoK; here->MOS1temp = value->rValue+CONSTCtoK;
here->MOS1tempGiven = TRUE; here->MOS1tempGiven = TRUE;
@ -89,7 +89,9 @@ MOS1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->MOS1icVGSGiven = TRUE; here->MOS1icVGSGiven = TRUE;
break; break;
case MOS1_IC: case MOS1_IC:
switch(value->v.numValue){ /* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3: case 3:
here->MOS1icVBS = *(value->v.vec.rVec+2); here->MOS1icVBS = *(value->v.vec.rVec+2);
here->MOS1icVBSGiven = TRUE; here->MOS1icVBSGiven = 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 * * this routine evaluates the drain current, its derivatives and * the charges associated with the gate, channel and bulk * for mosfets *
*/ */
double arg; double arg1;
double sarg; double sarg1;
double a4[4],b4[4],x4[8],poly4[8]; double a4[4],b4[4],x4[8],poly4[8];
double beta1; double beta1;
double sphi = 0.0; /* square root of phi */ 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; d_phiMinVbs.d1_q = - d_phiMinVbs.d1_q;
if (lvbs <= 0.0) { if (lvbs <= 0.0) {
sarg = sqrt(phiMinVbs); sarg1 = sqrt(phiMinVbs);
SqrtDeriv(&d_sarg, &d_phiMinVbs); SqrtDeriv(&d_sarg, &d_phiMinVbs);
dsrgdb = -0.5/sarg; dsrgdb = -0.5/sarg1;
InvDeriv(&d_dsrgdb,&d_sarg); InvDeriv(&d_dsrgdb,&d_sarg);
TimesDeriv(&d_dsrgdb,&d_dsrgdb,-0.5); TimesDeriv(&d_dsrgdb,&d_dsrgdb,-0.5);
} else { } else {
sphi = sqrt(here->MOS2tPhi); /*const*/ sphi = sqrt(here->MOS2tPhi); /*const*/
sphi3 = here->MOS2tPhi*sphi; /*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; EqualDeriv(&d_sarg,&d_q); d_sarg.value = lvbs;
TimesDeriv(&d_sarg,&d_sarg,0.5/here->MOS2tPhi); TimesDeriv(&d_sarg,&d_sarg,0.5/here->MOS2tPhi);
d_sarg.value += 1.0; d_sarg.value += 1.0;
InvDeriv(&d_sarg,&d_sarg); InvDeriv(&d_sarg,&d_sarg);
TimesDeriv(&d_sarg,&d_sarg,sphi); 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); MultDeriv(&d_dsrgdb,&d_sarg,&d_sarg);
TimesDeriv(&d_dsrgdb,&d_dsrgdb,-0.5/sphi3); TimesDeriv(&d_dsrgdb,&d_dsrgdb,-0.5/sphi3);
/* tmp = sarg/sphi3; */ /* tmp = sarg/sphi3; */
@ -422,7 +422,7 @@ d_p.d3_pqr = 0.0;
if ((model->MOS2gamma > 0.0) || if ((model->MOS2gamma > 0.0) ||
(model->MOS2substrateDoping > 0.0)) { (model->MOS2substrateDoping > 0.0)) {
xwd = model->MOS2xd*barg; xwd = model->MOS2xd*barg;
xws = model->MOS2xd*sarg; xws = model->MOS2xd*sarg1;
TimesDeriv(&d_xwd,&d_barg,model->MOS2xd); TimesDeriv(&d_xwd,&d_barg,model->MOS2xd);
TimesDeriv(&d_xws,&d_sarg,model->MOS2xd); TimesDeriv(&d_xws,&d_sarg,model->MOS2xd);
@ -484,7 +484,7 @@ d_p.d3_pqr = 0.0;
dgddvb = 0.0; dgddvb = 0.0;
EqualDeriv(&d_dgddvb,&d_zero); EqualDeriv(&d_dgddvb,&d_zero);
} }
von = vbin+gamasd*sarg; von = vbin+gamasd*sarg1;
MultDeriv(&d_von,&d_gamasd,&d_sarg); MultDeriv(&d_von,&d_gamasd,&d_sarg);
PlusDeriv(&d_von,&d_von,&d_vbin); PlusDeriv(&d_von,&d_von,&d_vbin);
/* /*
@ -497,7 +497,7 @@ d_p.d3_pqr = 0.0;
/* XXX constant per model */ /* XXX constant per model */
cfs = CHARGE*model->MOS2fastSurfaceStateDensity* cfs = CHARGE*model->MOS2fastSurfaceStateDensity*
1e4 /*(cm**2/m**2)*/; 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_dummy,&d_dgddvb,&d_sarg);
MultDeriv(&d_cdonco,&d_gamasd,&d_dsrgdb); MultDeriv(&d_cdonco,&d_gamasd,&d_dsrgdb);
PlusDeriv(&d_cdonco,&d_cdonco,&d_dummy); PlusDeriv(&d_cdonco,&d_cdonco,&d_dummy);
@ -533,7 +533,7 @@ d_p.d3_pqr = 0.0;
/* /*
* compute some more useful quantities */ * compute some more useful quantities */
sarg3 = sarg*sarg*sarg; sarg3 = sarg1*sarg1*sarg1;
CubeDeriv(&d_sarg3,&d_sarg); CubeDeriv(&d_sarg3,&d_sarg);
/* XXX constant per model */ /* XXX constant per model */
sbiarg = sqrt(here->MOS2tBulkPot); /*const*/ sbiarg = sqrt(here->MOS2tBulkPot); /*const*/
@ -599,7 +599,7 @@ line500:
vdsat = 0.0; vdsat = 0.0;
EqualDeriv(&d_vdsat,&d_zero); EqualDeriv(&d_vdsat,&d_zero);
} else { } else {
arg = sqrt(1.0+4.0*argv/gammd2); arg1 = sqrt(1.0+4.0*argv/gammd2);
DivDeriv(&d_arg,&d_argv,&d_gammd2); DivDeriv(&d_arg,&d_argv,&d_gammd2);
TimesDeriv(&d_arg,&d_arg,4.0);d_arg.value += 1.0; TimesDeriv(&d_arg,&d_arg,4.0);d_arg.value += 1.0;
SqrtDeriv(&d_arg,&d_arg); SqrtDeriv(&d_arg,&d_arg);
@ -883,14 +883,14 @@ line500:
MultDeriv(&d_sargv,&d_argv,&d_argv); MultDeriv(&d_sargv,&d_argv,&d_argv);
d_sargv.value += 1.0; d_sargv.value += 1.0;
SqrtDeriv(&d_sargv,&d_sargv); SqrtDeriv(&d_sargv,&d_sargv);
arg = sqrt(argv+sargv); arg1 = sqrt(argv+sargv);
PlusDeriv(&d_arg,&d_sargv,&d_argv); PlusDeriv(&d_arg,&d_sargv,&d_argv);
SqrtDeriv(&d_arg,&d_arg); SqrtDeriv(&d_arg,&d_arg);
xlfact = model->MOS2xd/(EffectiveLength*lvds); xlfact = model->MOS2xd/(EffectiveLength*lvds);
EqualDeriv(&d_xlfact,&d_r); d_xlfact.value = lvds; EqualDeriv(&d_xlfact,&d_r); d_xlfact.value = lvds;
InvDeriv(&d_xlfact,&d_xlfact); InvDeriv(&d_xlfact,&d_xlfact);
TimesDeriv(&d_xlfact,&d_xlfact,model->MOS2xd/EffectiveLength); TimesDeriv(&d_xlfact,&d_xlfact,model->MOS2xd/EffectiveLength);
xlamda = xlfact*arg; xlamda = xlfact*arg1;
MultDeriv(&d_xlamda,&d_xlfact,&d_arg); MultDeriv(&d_xlamda,&d_xlfact,&d_arg);
} else { } else {
argv = (vgsx-vbin)/eta-vdsat; argv = (vgsx-vbin)/eta-vdsat;
@ -990,7 +990,7 @@ line610:
goto line1050; goto line1050;
} }
here->MOS2gds = beta1*(von-vbin-gammad*sarg)*exp(argg* here->MOS2gds = beta1*(von-vbin-gammad*sarg1)*exp(argg*
(lvgs-von)); (lvgs-von));
MultDeriv(&d_dummy,&d_gammad,&d_sarg); MultDeriv(&d_dummy,&d_gammad,&d_sarg);
PlusDeriv(&d_dummy,&d_dummy,&d_vbin); 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); MultDeriv(&d_mos2gds,&d_gammad,&d_sarg);
PlusDeriv(&d_mos2gds,&d_mos2gds,&d_vbin); PlusDeriv(&d_mos2gds,&d_mos2gds,&d_vbin);
TimesDeriv(&d_mos2gds,&d_mos2gds,-1.0); TimesDeriv(&d_mos2gds,&d_mos2gds,-1.0);

View File

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

View File

@ -28,8 +28,7 @@ MOS3param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
if (!cp_getvar("scale", CP_REAL, &scale, 0)) if (!cp_getvar("scale", CP_REAL, &scale, 0))
scale = 1; scale = 1;
switch(param) { switch (param) {
case MOS3_M: case MOS3_M:
here->MOS3m = value->rValue; here->MOS3m = value->rValue;
here->MOS3mGiven = TRUE; here->MOS3mGiven = TRUE;
@ -90,7 +89,9 @@ MOS3param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->MOS3dtempGiven = TRUE; here->MOS3dtempGiven = TRUE;
break; break;
case MOS3_IC: case MOS3_IC:
switch(value->v.numValue){ /* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3: case 3:
here->MOS3icVBS = *(value->v.vec.rVec+2); here->MOS3icVBS = *(value->v.vec.rVec+2);
here->MOS3icVBSGiven = TRUE; here->MOS3icVBSGiven = TRUE;

View File

@ -464,8 +464,8 @@ next1: if(vbs <= -3*vt) {
/* the following 14 variables are local to this code block until /* the following 14 variables are local to this code block until
* it is obvious that they can be made global * it is obvious that they can be made global
*/ */
double arg; double arg1;
double sarg; double sarg1;
double vgon; double vgon;
double vdshere, vbsvbd; double vdshere, vbsvbd;
double idsat, lambda, vonbm = 0.0; double idsat, lambda, vonbm = 0.0;
@ -473,14 +473,14 @@ next1: if(vbs <= -3*vt) {
vbsvbd = (here->MOS6mode==1?vbs:vbd); vbsvbd = (here->MOS6mode==1?vbs:vbd);
if (vbsvbd <= 0 ) { if (vbsvbd <= 0 ) {
sarg = sqrt(here->MOS6tPhi - vbsvbd); sarg1 = sqrt(here->MOS6tPhi - vbsvbd);
} else { } else {
sarg = sqrt(here->MOS6tPhi); sarg1 = sqrt(here->MOS6tPhi);
sarg = sarg - vbsvbd / (sarg+sarg); sarg1 = sarg1 - vbsvbd / (sarg1+sarg1);
sarg = MAX(0,sarg); sarg1 = MAX(0,sarg1);
} }
vdshere = vds * here->MOS6mode; vdshere = vds * here->MOS6mode;
von=(here->MOS6tVbi*model->MOS6type)+model->MOS6gamma*sarg von=(here->MOS6tVbi*model->MOS6type)+model->MOS6gamma*sarg1
- model->MOS6gamma1 * vbsvbd - model->MOS6gamma1 * vbsvbd
- model->MOS6sigma * vdshere; - model->MOS6sigma * vdshere;
vgon = (here->MOS6mode==1?vgs:vgd) - von; vgon = (here->MOS6mode==1?vgs:vgd) - von;
@ -496,20 +496,20 @@ next1: if(vbs <= -3*vt) {
here->MOS6gmbs=0; here->MOS6gmbs=0;
} else { } else {
if (sarg <= 0) { if (sarg1 <= 0) {
arg=0; arg1=0;
} else { } else {
if ((here->MOS6mode==1?vbs:vbd) <= 0 ) { if ((here->MOS6mode==1?vbs:vbd) <= 0 ) {
vonbm = model->MOS6gamma1 vonbm = model->MOS6gamma1
+ model->MOS6gamma / (sarg + sarg); + model->MOS6gamma / (sarg1 + sarg1);
} else { } else {
vonbm = model->MOS6gamma1 vonbm = model->MOS6gamma1
+ model->MOS6gamma / 2 / sqrt(here->MOS6tPhi); + model->MOS6gamma / 2 / sqrt(here->MOS6tPhi);
} }
} }
sarg = log(vgon); sarg1 = log(vgon);
vdsat = model->MOS6kv * exp(sarg * model->MOS6nv); vdsat = model->MOS6kv * exp(sarg1 * model->MOS6nv);
idsat = betac * exp(sarg * model->MOS6nc); idsat = betac * exp(sarg1 * model->MOS6nc);
lambda = model->MOS6lamda0 - model->MOS6lamda1 * vbsvbd; lambda = model->MOS6lamda0 - model->MOS6lamda1 * vbsvbd;
/* /*
* saturation region * saturation region

View File

@ -21,7 +21,7 @@ MOS6param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
NG_IGNORE(select); NG_IGNORE(select);
switch(param) { switch (param) {
case MOS6_TEMP: case MOS6_TEMP:
here->MOS6temp = value->rValue+CONSTCtoK; here->MOS6temp = value->rValue+CONSTCtoK;
here->MOS6tempGiven = TRUE; here->MOS6tempGiven = TRUE;
@ -82,7 +82,9 @@ MOS6param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
here->MOS6icVGSGiven = TRUE; here->MOS6icVGSGiven = TRUE;
break; break;
case MOS6_IC: case MOS6_IC:
switch(value->v.numValue){ /* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3: case 3:
here->MOS6icVBS = *(value->v.vec.rVec+2); here->MOS6icVBS = *(value->v.vec.rVec+2);
here->MOS6icVBSGiven = TRUE; here->MOS6icVBSGiven = TRUE;

View File

@ -23,8 +23,7 @@ MOS9param(int param, IFvalue *value, GENinstance *inst,
NG_IGNORE(select); NG_IGNORE(select);
switch(param) { switch (param) {
case MOS9_M: case MOS9_M:
here->MOS9m = value->rValue; here->MOS9m = value->rValue;
here->MOS9mGiven = TRUE; here->MOS9mGiven = TRUE;
@ -85,7 +84,9 @@ MOS9param(int param, IFvalue *value, GENinstance *inst,
here->MOS9dtempGiven = TRUE; here->MOS9dtempGiven = TRUE;
break; break;
case MOS9_IC: case MOS9_IC:
switch(value->v.numValue){ /* FALLTHROUGH added to suppress GCC warning due to
* -Wimplicit-fallthrough flag */
switch (value->v.numValue) {
case 3: case 3:
here->MOS9icVBS = *(value->v.vec.rVec+2); here->MOS9icVBS = *(value->v.vec.rVec+2);
here->MOS9icVBSGiven = TRUE; here->MOS9icVBSGiven = TRUE;

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