⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spoutput.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 2 页
字号:
    FREE(PrintOrdToIntRowMap);    return;}/* *  OUTPUT MATRIX TO FILE * *  Writes matrix to file in format suitable to be read back in by the *  matrix test program. * *  >>> Returns: *  One is returned if routine was successful, otherwise zero is returned. *  The calling function can query errno (the system global error variable) *  as to the reason why this routine failed. * *  >>> Arguments: *  Matrix  <input>  (char *) *      Pointer to matrix. *  File  <input>  (char *) *      Name of file into which matrix is to be written. *  Label  <input>  (char *) *      String that is transferred to file and is used as a label. *  Reordered  <input> (int) *      Specifies whether matrix should be output in reordered form, *      or in original order. *  Data  <input> (int) *      Indicates that the element values should be output along with *      the indices for each element.  This parameter must be TRUE if *      matrix is to be read by the sparse test program. *  Header  <input> (int) *      Indicates that header is desired.  This parameter must be TRUE if *      matrix is to be read by the sparse test program. * *  >>> Local variables: *  Col  (int) *      The original column number of the element being output. *  pElement  (ElementPtr) *      Pointer to an element in the matrix. *  pMatrixFile  (FILE *) *      File pointer to the matrix file. *  Row  (int) *      The original row number of the element being output. *  Size  (int) *      The size of the matrix. */intspFileMatrix(void *eMatrix, char *File, char *Label, int Reordered,	     int Data, int Header){    MatrixPtr  Matrix = (MatrixPtr)eMatrix;    int  I, Size;    ElementPtr  pElement;    int  Row, Col, Err;    FILE  *pMatrixFile;    /* Begin `spFileMatrix'. */    assert( IS_SPARSE( Matrix ) );    /* Open file matrix file in write mode. */    if ((pMatrixFile = fopen(File, "w")) == NULL)        return 0;    /* Output header. */    Size = Matrix->Size;    if (Header)    {	if (Matrix->Factored && Data)        {	    Err = fprintf(pMatrixFile,			  "Warning : The following matrix is "			  "factored in to LU form.\n");	    if (Err < 0)		return 0;        }        if (fprintf(pMatrixFile, "%s\n", Label) < 0)	    return 0;        Err = fprintf( pMatrixFile, "%d\t%s\n", Size,		       (Matrix->Complex ? "complex" : "real"));        if (Err < 0)	    return 0;    }    /* Output matrix. */    if (!Data)    {	for (I = 1; I <= Size; I++)        {	    pElement = Matrix->FirstInCol[I];            while (pElement != NULL)            {		if (Reordered)                {		    Row = pElement->Row;                    Col = I;                }                else                {		    Row = Matrix->IntToExtRowMap[pElement->Row];                    Col = Matrix->IntToExtColMap[I];                }                pElement = pElement->NextInCol;                if (fprintf(pMatrixFile, "%d\t%d\n", Row, Col) < 0) return 0;            }        }	/* Output terminator, a line of zeros. */        if (Header)            if (fprintf(pMatrixFile, "0\t0\n") < 0) return 0;    }    if (Data && Matrix->Complex)    {	for (I = 1; I <= Size; I++)        {	    pElement = Matrix->FirstInCol[I];            while (pElement != NULL)            {		if (Reordered)                {		    Row = pElement->Row;                    Col = I;                }                else                {		    Row = Matrix->IntToExtRowMap[pElement->Row];                    Col = Matrix->IntToExtColMap[I];                }                Err = fprintf		    (   pMatrixFile,"%d\t%d\t%-.15g\t%-.15g\n",			Row, Col, (double)pElement->Real, (double)pElement->Imag			);                if (Err < 0) return 0;                pElement = pElement->NextInCol;            }        }	/* Output terminator, a line of zeros. */        if (Header)            if (fprintf(pMatrixFile,"0\t0\t0.0\t0.0\n") < 0) return 0;    }    if (Data && !Matrix->Complex)    {	for (I = 1; I <= Size; I++)        {	    pElement = Matrix->FirstInCol[I];            while (pElement != NULL)            {		Row = Matrix->IntToExtRowMap[pElement->Row];                Col = Matrix->IntToExtColMap[I];                Err = fprintf		    (   pMatrixFile,"%d\t%d\t%-.15g\n",			Row, Col, (double)pElement->Real			);                if (Err < 0) return 0;                pElement = pElement->NextInCol;            }        }	/* Output terminator, a line of zeros. */        if (Header)            if (fprintf(pMatrixFile,"0\t0\t0.0\n") < 0) return 0;    }    /* Close file. */    if (fclose(pMatrixFile) < 0) return 0;    return 1;}/* *  OUTPUT SOURCE VECTOR TO FILE * *  Writes vector to file in format suitable to be read back in by the *  matrix test program.  This routine should be executed after the function *  spFileMatrix. * *  >>> Returns: *  One is returned if routine was successful, otherwise zero is returned. *  The calling function can query errno (the system global error variable) *  as to the reason why this routine failed. * *  >>> Arguments: *  Matrix  <input>  (char *) *      Pointer to matrix. *  File  <input>  (char *) *      Name of file into which matrix is to be written. *  RHS  <input>  (RealNumber []) *      Right-hand side vector, real portion *  iRHS  <input>  (RealNumber []) *      Right-hand side vector, imaginary portion. * *  >>> Local variables: *  pMatrixFile  (FILE *) *      File pointer to the matrix file. *  Size  (int) *      The size of the matrix. * */intspFileVector(void *eMatrix, char *File, RealVector RHS, RealVector iRHS){    MatrixPtr  Matrix = (MatrixPtr)eMatrix;    int  I, Size, Err;    FILE  *pMatrixFile;    FILE  *fopen();    /* Begin `spFileVector'. */    assert( IS_SPARSE( Matrix ) && RHS != NULL);    /* Open File in append mode. */    pMatrixFile = fopen(File,"a");    if (pMatrixFile == NULL)	return 0;    /* Output vector. */    Size = Matrix->Size;    if (Matrix->Complex)    {        for (I = 1; I <= Size; I++)        {	    Err = fprintf		(   pMatrixFile, "%-.15g\t%-.15g\n",		    (double)RHS[I], (double)iRHS[I]		    );            if (Err < 0) return 0;        }    }    else    {	for (I = 1; I <= Size; I++)        {	    if (fprintf(pMatrixFile, "%-.15g\n", (double)RHS[I]) < 0)                return 0;        }    }    /* Close file. */    if (fclose(pMatrixFile) < 0) return 0;    return 1;}/* *  OUTPUT STATISTICS TO FILE * *  Writes useful information concerning the matrix to a file.  Should be *  executed after the matrix is factored. *  *  >>> Returns: *  One is returned if routine was successful, otherwise zero is returned. *  The calling function can query errno (the system global error variable) *  as to the reason why this routine failed. * *  >>> Arguments: *  Matrix  <input>  (char *) *      Pointer to matrix. *  File  <input>  (char *) *      Name of file into which matrix is to be written. *  Label  <input>  (char *) *      String that is transferred to file and is used as a label. * *  >>> Local variables: *  Data  (RealNumber) *      The value of the matrix element being output. *  LargestElement  (RealNumber) *      The largest element in the matrix. *  NumberOfElements  (int) *      Number of nonzero elements in the matrix. *  pElement  (ElementPtr) *      Pointer to an element in the matrix. *  pStatsFile  (FILE *) *      File pointer to the statistics file. *  Size  (int) *      The size of the matrix. *  SmallestElement  (RealNumber) *      The smallest element in the matrix excluding zero elements. */intspFileStats(void *eMatrix, char *File, char *Label){    MatrixPtr  Matrix = (MatrixPtr)eMatrix;    int  Size, I;    ElementPtr  pElement;    int NumberOfElements;    RealNumber  Data, LargestElement, SmallestElement;    FILE  *pStatsFile, *fopen();    /* Begin `spFileStats'. */    assert( IS_SPARSE( Matrix ) );    /* Open File in append mode. */    if ((pStatsFile = fopen(File, "a")) == NULL)        return 0;    /* Output statistics. */    Size = Matrix->Size;    if (!Matrix->Factored)        fprintf(pStatsFile, "Matrix has not been factored.\n");    fprintf(pStatsFile, "|||  Starting new matrix  |||\n");    fprintf(pStatsFile, "%s\n", Label);    if (Matrix->Complex)        fprintf(pStatsFile, "Matrix is complex.\n");    else        fprintf(pStatsFile, "Matrix is real.\n");    fprintf(pStatsFile,"     Size = %d\n",Size);    /* Search matrix. */    NumberOfElements = 0;    LargestElement = 0.0;    SmallestElement = LARGEST_REAL;    for (I = 1; I <= Size; I++)    {	pElement = Matrix->FirstInCol[I];        while (pElement != NULL)        {	    NumberOfElements++;            Data = ELEMENT_MAG(pElement);            if (Data > LargestElement)                LargestElement = Data;            if (Data < SmallestElement && Data != 0.0)                SmallestElement = Data;            pElement = pElement->NextInCol;        }    }    SmallestElement = MIN( SmallestElement, LargestElement );    /* Output remaining statistics. */    fprintf(pStatsFile, "     Initial number of elements = %d\n",            NumberOfElements - Matrix->Fillins);    fprintf(pStatsFile,            "     Initial average number of elements per row = %f\n",            (double)(NumberOfElements - Matrix->Fillins) / (double)Size);    fprintf(pStatsFile, "     Fill-ins = %d\n",Matrix->Fillins);    fprintf(pStatsFile, "     Average number of fill-ins per row = %f%%\n",            (double)Matrix->Fillins / (double)Size);    fprintf(pStatsFile, "     Total number of elements = %d\n",            NumberOfElements);    fprintf(pStatsFile, "     Average number of elements per row = %f\n",            (double)NumberOfElements / (double)Size);    fprintf(pStatsFile,"     Density = %f%%\n",            (double)(100.0*NumberOfElements)/(double)(Size*Size));    fprintf(pStatsFile,"     Relative Threshold = %e\n", Matrix->RelThreshold);    fprintf(pStatsFile,"     Absolute Threshold = %e\n", Matrix->AbsThreshold);    fprintf(pStatsFile,"     Largest Element = %e\n", LargestElement);    fprintf(pStatsFile,"     Smallest Element = %e\n\n\n", SmallestElement);    /* Close file. */    (void)fclose(pStatsFile);    return 1;}#endif /* DOCUMENTATION */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -