diff --git a/spm.c b/spm.c index 36647a9fb50813a9dd522d39796a041785b46237..89c0518f62a170591c4ec28d2b25073c6521cbed 100644 --- a/spm.c +++ b/spm.c @@ -999,12 +999,13 @@ spmPrintInfo( const pastix_spm_t* spm, FILE *stream ) * @param[in] spm * The sparse matrix to print. * - * @param[in] f - * File to print the spm matrix. + * @param[in] stream + * File to print the spm matrix. stdout, if stream == NULL. * *******************************************************************************/ void -spmPrint( const pastix_spm_t* spm, FILE *stream ) +spmPrint( const pastix_spm_t *spm, + FILE *stream ) { if (stream == NULL) { stream = stdout; diff --git a/spm_io.c b/spm_io.c index ddf180c7401e4875b4c159bd2254f52d956e6252..ecd1ecb10024d37cb14a60a892ba49fbc3bdf1d0 100644 --- a/spm_io.c +++ b/spm_io.c @@ -451,7 +451,8 @@ readArrayOfFloat( FILE *stream, * On exit, the spm filled with the information read in the file. * * @param[in] infile - * The opened file in which the spm is stored. + * The opened file in which the spm is stored. If infile == NULL, + * matrix.spm is opened. * ******************************************************************************* * @@ -466,6 +467,12 @@ spmLoad( pastix_spm_t *spm, pastix_int_t colsize=0, rowsize=0; char line[256], *test; int rc = PASTIX_SUCCESS; + int local_stream = 0; + + if ( infile == NULL ) { + PASTIX_FOPEN( infile, "matrix.spm", "r" ); + local_stream = 1; + } /* * Skip comments @@ -599,6 +606,10 @@ spmLoad( pastix_spm_t *spm, break; } + if (local_stream) { + fclose(infile); + } + return rc; } @@ -781,7 +792,8 @@ writeArrayOfFloat( FILE *outfile, * The sparse matrix to write into the file. * * @param[in] outfile - * The opened file in which to store the spm. + * The opened file in which to store the spm. If outfile == NULL, data + * is saved into matrix.spm file. * ******************************************************************************** * @@ -793,6 +805,12 @@ spmSave( pastix_spm_t *spm, FILE *outfile ) { pastix_int_t i, colsize, rowsize; + int local_stream = 0; + + if ( outfile == NULL ) { + PASTIX_FOPEN( outfile, "matrix.spm", "w" ); + local_stream = 1; + } /* * Write header @@ -886,5 +904,8 @@ spmSave( pastix_spm_t *spm, break; } + if (local_stream) { + fclose(outfile); + } return PASTIX_SUCCESS; }