mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-01-08 07:23:02 -06:00
Add companion output utilities based on already opened streams.
Functions csrmatrix_write_stream() and vector_write_stream() subsume the output responsibilities of csrmatrix_write() and vector_write(), respectively, but do not deal with opening or closing streams. This allows, e.g., a call such as csrmatrix_write_stream(A, stderr); for debugging purposes. Re-implement csrmatrix_write() and vector_write() in terms of csrmatrix_write_stream() and vector_write_stream(), respectively.
This commit is contained in:
parent
4e8b35f9ed
commit
70a9e8a7a8
@ -203,41 +203,60 @@ void
|
|||||||
csrmatrix_write(const struct CSRMatrix *A, const char *fn)
|
csrmatrix_write(const struct CSRMatrix *A, const char *fn)
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
size_t i, j;
|
FILE *fp;
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
fp = fopen(fn, "wt");
|
fp = fopen(fn, "wt");
|
||||||
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
for (i = j = 0; i < A->m; i++) {
|
csrmatrix_write_stream(A, fp);
|
||||||
for (; j < (size_t) (A->ia[i + 1]); j++) {
|
|
||||||
fprintf(fp, "%lu %lu %26.18e\n",
|
|
||||||
(unsigned long) (i + 1),
|
|
||||||
(unsigned long) (A->ja[j] + 1),
|
|
||||||
A->sa[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
void
|
||||||
|
csrmatrix_write_stream(const struct CSRMatrix *A, FILE *fp)
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
size_t i, j;
|
||||||
|
for (i = j = 0; i < A->m; i++) {
|
||||||
|
for (; j < (size_t) (A->ia[i + 1]); j++) {
|
||||||
|
fprintf(fp, "%lu %lu %26.18e\n",
|
||||||
|
(unsigned long) (i + 1),
|
||||||
|
(unsigned long) (A->ja[j] + 1),
|
||||||
|
A->sa[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
void
|
void
|
||||||
vector_write(size_t n, const double *v, const char *fn)
|
vector_write(size_t n, const double *v, const char *fn)
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
{
|
{
|
||||||
size_t i;
|
FILE *fp;
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
fp = fopen(fn, "wt");
|
fp = fopen(fn, "wt");
|
||||||
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
for (i = 0; i < n; i++) {
|
vector_write_stream(n, v, fp);
|
||||||
fprintf(fp, "%26.18e\n", v[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
void
|
||||||
|
vector_write_stream(size_t n, const double *v, FILE *fp)
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
fprintf(fp, "%26.18e\n", v[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define OPM_SPARSE_SYS_HEADER_INCLUDED
|
#define OPM_SPARSE_SYS_HEADER_INCLUDED
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -70,9 +71,15 @@ vector_zero(size_t n, double *v);
|
|||||||
void
|
void
|
||||||
csrmatrix_write(const struct CSRMatrix *A, const char *fn);
|
csrmatrix_write(const struct CSRMatrix *A, const char *fn);
|
||||||
|
|
||||||
|
void
|
||||||
|
csrmatrix_write_stream(const struct CSRMatrix *A, FILE *fp);
|
||||||
|
|
||||||
void
|
void
|
||||||
vector_write(size_t n, const double *v, const char *fn);
|
vector_write(size_t n, const double *v, const char *fn);
|
||||||
|
|
||||||
|
void
|
||||||
|
vector_write_stream(size_t n, const double *v, FILE *fp);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user