Reformat spoutput.c

Replace tabs by spaces
This commit is contained in:
Holger Vogt 2025-02-24 17:00:44 +01:00
parent 77131a2a33
commit 8694ce2649
1 changed files with 172 additions and 172 deletions

View File

@ -18,7 +18,7 @@
*/ */
/* /*
* Revision and copyright information. * Revision and copyright information.
* *
* Copyright (c) 1985,86,87,88,89,90 * Copyright (c) 1985,86,87,88,89,90
@ -34,7 +34,7 @@
* or implied warranty. * or implied warranty.
*/ */
/* /*
* IMPORTS * IMPORTS
* *
* >>> Import descriptions: * >>> Import descriptions:
@ -63,7 +63,7 @@ int Printer_Width = PRINTER_WIDTH;
#if DOCUMENTATION #if DOCUMENTATION
/* /*
* PRINT MATRIX * PRINT MATRIX
* *
@ -144,14 +144,14 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
double SmallestDiag = 0; double SmallestDiag = 0;
double SmallestElement = 0; double SmallestElement = 0;
double LargestElement = 0.0, LargestDiag = 0.0; double LargestElement = 0.0, LargestDiag = 0.0;
ElementPtr pElement, *pImagElements; ElementPtr pElement, * pImagElements;
int *PrintOrdToIntRowMap, *PrintOrdToIntColMap; int* PrintOrdToIntRowMap, * PrintOrdToIntColMap;
/* Begin `spPrint'. */ /* Begin `spPrint'. */
assert( IS_SPARSE( Matrix ) ); assert(IS_SPARSE(Matrix));
Size = Matrix->Size; Size = Matrix->Size;
SP_CALLOC(pImagElements, ElementPtr, Printer_Width / 10 + 1); SP_CALLOC(pImagElements, ElementPtr, Printer_Width / 10 + 1);
if ( pImagElements == NULL) if (pImagElements == NULL)
{ {
Matrix->Error = spNO_MEMORY; Matrix->Error = spNO_MEMORY;
SP_FREE(pImagElements); SP_FREE(pImagElements);
@ -165,14 +165,14 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
#else #else
Top = Matrix->AllocatedSize; Top = Matrix->AllocatedSize;
#endif #endif
SP_CALLOC( PrintOrdToIntRowMap, int, Top + 1 ); SP_CALLOC(PrintOrdToIntRowMap, int, Top + 1);
if ( PrintOrdToIntRowMap == NULL) if (PrintOrdToIntRowMap == NULL)
{ {
Matrix->Error = spNO_MEMORY; Matrix->Error = spNO_MEMORY;
SP_FREE(pImagElements); SP_FREE(pImagElements);
return; return;
} }
SP_CALLOC( PrintOrdToIntColMap, int, Top + 1 ); SP_CALLOC(PrintOrdToIntColMap, int, Top + 1);
if (PrintOrdToIntColMap == NULL) if (PrintOrdToIntColMap == NULL)
{ {
Matrix->Error = spNO_MEMORY; Matrix->Error = spNO_MEMORY;
@ -182,20 +182,20 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
} }
for (I = 1; I <= Size; I++) for (I = 1; I <= Size; I++)
{ {
PrintOrdToIntRowMap[ Matrix->IntToExtRowMap[I] ] = I; PrintOrdToIntRowMap[Matrix->IntToExtRowMap[I]] = I;
PrintOrdToIntColMap[ Matrix->IntToExtColMap[I] ] = I; PrintOrdToIntColMap[Matrix->IntToExtColMap[I]] = I;
} }
/* Pack the arrays. */ /* Pack the arrays. */
for (J = 1, I = 1; I <= Top; I++) for (J = 1, I = 1; I <= Top; I++)
{ {
if (PrintOrdToIntRowMap[I] != 0) if (PrintOrdToIntRowMap[I] != 0)
PrintOrdToIntRowMap[ J++ ] = PrintOrdToIntRowMap[ I ]; PrintOrdToIntRowMap[J++] = PrintOrdToIntRowMap[I];
} }
for (J = 1, I = 1; I <= Top; I++) for (J = 1, I = 1; I <= Top; I++)
{ {
if (PrintOrdToIntColMap[I] != 0) if (PrintOrdToIntColMap[I] != 0)
PrintOrdToIntColMap[ J++ ] = PrintOrdToIntColMap[ I ]; PrintOrdToIntColMap[J++] = PrintOrdToIntColMap[I];
} }
/* Print header. */ /* Print header. */
@ -203,11 +203,11 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
{ {
printf("MATRIX SUMMARY\n\n"); printf("MATRIX SUMMARY\n\n");
printf("Size of matrix = %1d x %1d.\n", Size, Size); printf("Size of matrix = %1d x %1d.\n", Size, Size);
if ( Matrix->Reordered && PrintReordered ) if (Matrix->Reordered && PrintReordered)
printf("Matrix has been reordered.\n"); printf("Matrix has been reordered.\n");
putchar('\n'); putchar('\n');
if ( Matrix->Factored ) if (Matrix->Factored)
printf("Matrix after factorization:\n"); printf("Matrix after factorization:\n");
else else
printf("Matrix before factorization:\n"); printf("Matrix before factorization:\n");
@ -219,12 +219,12 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
/* Determine how many columns to use. */ /* Determine how many columns to use. */
Columns = Printer_Width; Columns = Printer_Width;
if (Header) Columns -= 5; if (Header) Columns -= 5;
if (Data) Columns = (Columns+1) / 10; if (Data) Columns = (Columns + 1) / 10;
/* Print matrix by printing groups of complete columns until all /* Print matrix by printing groups of complete columns until all
* the columns are printed. */ * the columns are printed. */
J = 0; J = 0;
while ( J <= Size ) while (J <= Size)
{ {
/* Calculatestrchr of last column to printed in this group. */ /* Calculatestrchr of last column to printed in this group. */
StopCol = StartCol + Columns - 1; StopCol = StartCol + Columns - 1;
@ -243,19 +243,19 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
Col = I; Col = I;
else else
Col = PrintOrdToIntColMap[I]; Col = PrintOrdToIntColMap[I];
printf(" %9d", Matrix->IntToExtColMap[ Col ]); printf(" %9d", Matrix->IntToExtColMap[Col]);
} }
printf("\n\n"); printf("\n\n");
} }
else else
{ {
if (PrintReordered) if (PrintReordered)
printf("Columns %1d to %1d.\n",StartCol,StopCol); printf("Columns %1d to %1d.\n", StartCol, StopCol);
else else
{ {
printf("Columns %1d to %1d.\n", printf("Columns %1d to %1d.\n",
Matrix->IntToExtColMap[ PrintOrdToIntColMap[StartCol] ], Matrix->IntToExtColMap[PrintOrdToIntColMap[StartCol]],
Matrix->IntToExtColMap[ PrintOrdToIntColMap[StopCol] ]); Matrix->IntToExtColMap[PrintOrdToIntColMap[StopCol]]);
} }
} }
} }
@ -273,7 +273,7 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
if (PrintReordered && !Data) if (PrintReordered && !Data)
printf("%4d", I); printf("%4d", I);
else else
printf("%4d", Matrix->IntToExtRowMap[ Row ]); printf("%4d", Matrix->IntToExtRowMap[Row]);
if (!Data) putchar(' '); if (!Data) putchar(' ');
} }
@ -286,7 +286,7 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
Col = PrintOrdToIntColMap[J]; Col = PrintOrdToIntColMap[J];
pElement = Matrix->FirstInCol[Col]; pElement = Matrix->FirstInCol[Col];
while(pElement != NULL && pElement->Row != Row) while (pElement != NULL && pElement->Row != Row)
pElement = pElement->NextInCol; pElement = pElement->NextInCol;
if (Data) if (Data)
@ -301,7 +301,7 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
putchar('x'); putchar('x');
/* Update status variables */ /* Update status variables */
if ( (Magnitude = ELEMENT_MAG(pElement)) > LargestElement ) if ((Magnitude = ELEMENT_MAG(pElement)) > LargestElement)
LargestElement = Magnitude; LargestElement = Magnitude;
if ((Magnitude < SmallestElement) && (Magnitude != 0.0)) if ((Magnitude < SmallestElement) && (Magnitude != 0.0))
SmallestElement = Magnitude; SmallestElement = Magnitude;
@ -327,7 +327,7 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
if (pImagElements[J - StartCol] != NULL) if (pImagElements[J - StartCol] != NULL)
{ {
printf(" %8.2gj", printf(" %8.2gj",
pImagElements[J-StartCol]->Imag); pImagElements[J - StartCol]->Imag);
} }
else printf(" "); else printf(" ");
} }
@ -350,14 +350,14 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
{ {
if (Matrix->Diag[I] != NULL) if (Matrix->Diag[I] != NULL)
{ {
Magnitude = ELEMENT_MAG( Matrix->Diag[I] ); Magnitude = ELEMENT_MAG(Matrix->Diag[I]);
if ( Magnitude > LargestDiag ) LargestDiag = Magnitude; if (Magnitude > LargestDiag) LargestDiag = Magnitude;
if ( Magnitude < SmallestDiag ) SmallestDiag = Magnitude; if (Magnitude < SmallestDiag) SmallestDiag = Magnitude;
} }
} }
/* Print the largest and smallest diagonal values */ /* Print the largest and smallest diagonal values */
if ( Matrix->Factored ) if (Matrix->Factored)
{ {
printf("\nLargest diagonal element = %-1.4g.\n", LargestDiag); printf("\nLargest diagonal element = %-1.4g.\n", LargestDiag);
printf("Smallest diagonal element = %-1.4g.\n", SmallestDiag); printf("Smallest diagonal element = %-1.4g.\n", SmallestDiag);
@ -393,7 +393,7 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
/* /*
* OUTPUT MATRIX TO FILE * OUTPUT MATRIX TO FILE
* *
@ -437,16 +437,16 @@ spPrint(MatrixPtr Matrix, int PrintReordered, int Data, int Header)
*/ */
int int
spFileMatrix(MatrixPtr Matrix, char *File, char *Label, int Reordered, spFileMatrix(MatrixPtr Matrix, char* File, char* Label, int Reordered,
int Data, int Header) int Data, int Header)
{ {
int I, Size; int I, Size;
ElementPtr pElement; ElementPtr pElement;
int Row, Col, Err; int Row, Col, Err;
FILE *pMatrixFile; FILE* pMatrixFile;
/* Begin `spFileMatrix'. */ /* Begin `spFileMatrix'. */
assert( IS_SPARSE( Matrix ) ); assert(IS_SPARSE(Matrix));
/* Open file matrix file in write mode. */ /* Open file matrix file in write mode. */
if ((pMatrixFile = fopen(File, "w")) == NULL) if ((pMatrixFile = fopen(File, "w")) == NULL)
@ -466,7 +466,7 @@ spFileMatrix(MatrixPtr Matrix, char *File, char *Label, int Reordered,
} }
if (fprintf(pMatrixFile, "%s\n", Label) < 0) if (fprintf(pMatrixFile, "%s\n", Label) < 0)
return 0; return 0;
Err = fprintf( pMatrixFile, "%d\t%s\n", Size, Err = fprintf(pMatrixFile, "%d\t%s\n", Size,
(Matrix->Complex ? "complex" : "real")); (Matrix->Complex ? "complex" : "real"));
if (Err < 0) if (Err < 0)
return 0; return 0;
@ -517,7 +517,7 @@ spFileMatrix(MatrixPtr Matrix, char *File, char *Label, int Reordered,
Col = Matrix->IntToExtColMap[I]; Col = Matrix->IntToExtColMap[I];
} }
Err = fprintf Err = fprintf
( pMatrixFile,"%d\t%d\t%-.15g\t%-.15g\n", (pMatrixFile, "%d\t%d\t%-.15g\t%-.15g\n",
Row, Col, pElement->Real, pElement->Imag Row, Col, pElement->Real, pElement->Imag
); );
if (Err < 0) return 0; if (Err < 0) return 0;
@ -526,7 +526,7 @@ spFileMatrix(MatrixPtr Matrix, char *File, char *Label, int Reordered,
} }
/* Output terminator, a line of zeros. */ /* Output terminator, a line of zeros. */
if (Header) if (Header)
if (fprintf(pMatrixFile,"0\t0\t0.0\t0.0\n") < 0) return 0; if (fprintf(pMatrixFile, "0\t0\t0.0\t0.0\n") < 0) return 0;
} }
@ -540,7 +540,7 @@ spFileMatrix(MatrixPtr Matrix, char *File, char *Label, int Reordered,
Row = Matrix->IntToExtRowMap[pElement->Row]; Row = Matrix->IntToExtRowMap[pElement->Row];
Col = Matrix->IntToExtColMap[I]; Col = Matrix->IntToExtColMap[I];
Err = fprintf Err = fprintf
( pMatrixFile,"%d\t%d\t%-.15g\n", (pMatrixFile, "%d\t%d\t%-.15g\n",
Row, Col, pElement->Real Row, Col, pElement->Real
); );
if (Err < 0) return 0; if (Err < 0) return 0;
@ -549,7 +549,7 @@ spFileMatrix(MatrixPtr Matrix, char *File, char *Label, int Reordered,
} }
/* Output terminator, a line of zeros. */ /* Output terminator, a line of zeros. */
if (Header) if (Header)
if (fprintf(pMatrixFile,"0\t0\t0.0\n") < 0) return 0; if (fprintf(pMatrixFile, "0\t0\t0.0\n") < 0) return 0;
} }
@ -563,7 +563,7 @@ spFileMatrix(MatrixPtr Matrix, char *File, char *Label, int Reordered,
/* /*
* OUTPUT SOURCE VECTOR TO FILE * OUTPUT SOURCE VECTOR TO FILE
* *
@ -595,22 +595,22 @@ spFileMatrix(MatrixPtr Matrix, char *File, char *Label, int Reordered,
*/ */
int int
spFileVector(MatrixPtr Matrix, char *File, RealVector RHS, RealVector iRHS) spFileVector(MatrixPtr Matrix, char* File, RealVector RHS, RealVector iRHS)
{ {
int I, Size, Err; int I, Size, Err;
FILE *pMatrixFile; FILE* pMatrixFile;
/* Begin `spFileVector'. */ /* Begin `spFileVector'. */
assert( IS_SPARSE( Matrix ) && RHS != NULL); assert(IS_SPARSE(Matrix) && RHS != NULL);
if (File) { if (File) {
/* Open File in write mode. */ /* Open File in write mode. */
pMatrixFile = fopen(File,"w"); pMatrixFile = fopen(File, "w");
if (pMatrixFile == NULL) if (pMatrixFile == NULL)
return 0; return 0;
} }
else else
pMatrixFile=stdout; pMatrixFile = stdout;
/* Output vector. */ /* Output vector. */
Size = Matrix->Size; Size = Matrix->Size;
@ -619,7 +619,7 @@ spFileVector(MatrixPtr Matrix, char *File, RealVector RHS, RealVector iRHS)
for (I = 1; I <= Size; I++) for (I = 1; I <= Size; I++)
{ {
Err = fprintf Err = fprintf
( pMatrixFile, "%-.15g\t%-.15g\n", (pMatrixFile, "%-.15g\t%-.15g\n",
RHS[I], iRHS[I] RHS[I], iRHS[I]
); );
if (Err < 0) return 0; if (Err < 0) return 0;
@ -647,7 +647,7 @@ spFileVector(MatrixPtr Matrix, char *File, RealVector RHS, RealVector iRHS)
/* /*
* OUTPUT STATISTICS TO FILE * OUTPUT STATISTICS TO FILE
* *
@ -685,16 +685,16 @@ spFileVector(MatrixPtr Matrix, char *File, RealVector RHS, RealVector iRHS)
*/ */
int int
spFileStats(MatrixPtr Matrix, char *File, char *Label) spFileStats(MatrixPtr Matrix, char* File, char* Label)
{ {
int Size, I; int Size, I;
ElementPtr pElement; ElementPtr pElement;
int NumberOfElements; int NumberOfElements;
RealNumber Data, LargestElement, SmallestElement; RealNumber Data, LargestElement, SmallestElement;
FILE *pStatsFile; FILE* pStatsFile;
/* Begin `spFileStats'. */ /* Begin `spFileStats'. */
assert( IS_SPARSE( Matrix ) ); assert(IS_SPARSE(Matrix));
/* Open File in append mode. */ /* Open File in append mode. */
if ((pStatsFile = fopen(File, "a")) == NULL) if ((pStatsFile = fopen(File, "a")) == NULL)
@ -710,7 +710,7 @@ spFileStats(MatrixPtr Matrix, char *File, char *Label)
fprintf(pStatsFile, "Matrix is complex.\n"); fprintf(pStatsFile, "Matrix is complex.\n");
else else
fprintf(pStatsFile, "Matrix is real.\n"); fprintf(pStatsFile, "Matrix is real.\n");
fprintf(pStatsFile," Size = %d\n",Size); fprintf(pStatsFile, " Size = %d\n", Size);
/* Search matrix. */ /* Search matrix. */
NumberOfElements = 0; NumberOfElements = 0;
@ -732,7 +732,7 @@ spFileStats(MatrixPtr Matrix, char *File, char *Label)
} }
} }
SmallestElement = MIN( SmallestElement, LargestElement ); SmallestElement = MIN(SmallestElement, LargestElement);
/* Output remaining statistics. */ /* Output remaining statistics. */
fprintf(pStatsFile, " Initial number of elements = %d\n", fprintf(pStatsFile, " Initial number of elements = %d\n",
@ -740,19 +740,19 @@ spFileStats(MatrixPtr Matrix, char *File, char *Label)
fprintf(pStatsFile, fprintf(pStatsFile,
" Initial average number of elements per row = %f\n", " Initial average number of elements per row = %f\n",
(double)(NumberOfElements - Matrix->Fillins) / (double)Size); (double)(NumberOfElements - Matrix->Fillins) / (double)Size);
fprintf(pStatsFile, " Fill-ins = %d\n",Matrix->Fillins); fprintf(pStatsFile, " Fill-ins = %d\n", Matrix->Fillins);
fprintf(pStatsFile, " Average number of fill-ins per row = %f%%\n", fprintf(pStatsFile, " Average number of fill-ins per row = %f%%\n",
(double)Matrix->Fillins / (double)Size); (double)Matrix->Fillins / (double)Size);
fprintf(pStatsFile, " Total number of elements = %d\n", fprintf(pStatsFile, " Total number of elements = %d\n",
NumberOfElements); NumberOfElements);
fprintf(pStatsFile, " Average number of elements per row = %f\n", fprintf(pStatsFile, " Average number of elements per row = %f\n",
(double)NumberOfElements / (double)Size); (double)NumberOfElements / (double)Size);
fprintf(pStatsFile," Density = %f%%\n", fprintf(pStatsFile, " Density = %f%%\n",
(double)(100.0*NumberOfElements)/(double)(Size*Size)); (double)(100.0 * NumberOfElements) / (double)(Size * Size));
fprintf(pStatsFile," Relative Threshold = %e\n", Matrix->RelThreshold); fprintf(pStatsFile, " Relative Threshold = %e\n", Matrix->RelThreshold);
fprintf(pStatsFile," Absolute Threshold = %e\n", Matrix->AbsThreshold); fprintf(pStatsFile, " Absolute Threshold = %e\n", Matrix->AbsThreshold);
fprintf(pStatsFile," Largest Element = %e\n", LargestElement); fprintf(pStatsFile, " Largest Element = %e\n", LargestElement);
fprintf(pStatsFile," Smallest Element = %e\n\n\n", SmallestElement); fprintf(pStatsFile, " Smallest Element = %e\n\n\n", SmallestElement);
/* Close file. */ /* Close file. */
(void)fclose(pStatsFile); (void)fclose(pStatsFile);