1 |
/* $Id$ */ |
2 |
|
3 |
/**************************************************************/ |
4 |
|
5 |
/* Paso: SystemMatrix is saved to Matrix Market format */ |
6 |
|
7 |
/**************************************************************/ |
8 |
|
9 |
/* Copyrights by ACcESS Australia 2003,2004 */ |
10 |
/* Author: davies@access.edu.au */ |
11 |
|
12 |
/**************************************************************/ |
13 |
|
14 |
#include "Paso.h" |
15 |
#include "mmio.h" |
16 |
#include "SystemMatrix.h" |
17 |
|
18 |
void Paso_SystemMatrix_saveMM(Paso_SystemMatrix * A_p, char * fileName_p) { |
19 |
|
20 |
int iRow, iCol, iPtr,ir,ic; |
21 |
|
22 |
/* open the file */ |
23 |
FILE * fileHandle_p = fopen(fileName_p, "w"); |
24 |
if (fileHandle_p==NULL) { |
25 |
Paso_setError(IO_ERROR,"file could not be opened for writing"); |
26 |
return; |
27 |
} |
28 |
|
29 |
/* set the matrix code */ |
30 |
MM_typecode matrixCode; |
31 |
mm_initialize_typecode(&matrixCode); |
32 |
mm_set_matrix(&matrixCode); |
33 |
mm_set_coordinate(&matrixCode); |
34 |
mm_set_real(&matrixCode); |
35 |
|
36 |
mm_write_banner(fileHandle_p, matrixCode); |
37 |
mm_write_mtx_crd_size(fileHandle_p, A_p->num_rows*A_p->row_block_size, A_p->num_cols*A_p->col_block_size,A_p->len); |
38 |
|
39 |
switch(A_p->type) { |
40 |
case CSR: |
41 |
for (iRow = 0; iRow< A_p->pattern->n_ptr; iRow++) { |
42 |
for (ir = 0; ir< A_p->row_block_size; ir++) { |
43 |
for (iPtr = A_p->pattern->ptr[iRow] - PTR_OFFSET;iPtr < A_p->pattern->ptr[iRow+1] - PTR_OFFSET; iPtr++) { |
44 |
for (ic = 0; ic< A_p->col_block_size; ic++) { |
45 |
fprintf(fileHandle_p, "%12d %12d %e\n", |
46 |
iRow*A_p->row_block_size+ir+ 1, |
47 |
(A_p->pattern->index[iPtr]-INDEX_OFFSET)*A_p->col_block_size+ic+1, |
48 |
A_p->val[iPtr*A_p->block_size+ir+A_p->row_block_size*ic]); |
49 |
} |
50 |
} |
51 |
} |
52 |
} |
53 |
break; |
54 |
case CSC: |
55 |
for (iCol = 0; iCol< A_p->pattern->n_ptr; iCol++) { |
56 |
for (ic = 0; ic< A_p->col_block_size; ic++) { |
57 |
for (iPtr = A_p->pattern->ptr[iCol] - PTR_OFFSET;iPtr < A_p->pattern->ptr[iCol+1] - PTR_OFFSET; iPtr++) { |
58 |
for (ir = 0; ir< A_p->row_block_size; ir++) { |
59 |
fprintf(fileHandle_p, "%12d %12d %e\n", |
60 |
(A_p->pattern->index[iPtr]-INDEX_OFFSET)*A_p->row_block_size+ir+1, |
61 |
iCol*A_p->col_block_size+ic+ 1, |
62 |
A_p->val[iPtr*A_p->block_size+ir+A_p->row_block_size*ic]); |
63 |
} |
64 |
} |
65 |
} |
66 |
} |
67 |
} |
68 |
|
69 |
/* close the file */ |
70 |
fclose(fileHandle_p); |
71 |
|
72 |
return; |
73 |
} |
74 |
|
75 |
/* |
76 |
* $Log$ |
77 |
* Revision 1.2 2005/09/15 03:44:39 jgs |
78 |
* Merge of development branch dev-02 back to main trunk on 2005-09-15 |
79 |
* |
80 |
* Revision 1.1.2.1 2005/09/05 06:29:48 gross |
81 |
* These files have been extracted from finley to define a stand alone libray for iterative |
82 |
* linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but |
83 |
* has not been tested yet. |
84 |
* |
85 |
* |
86 |
*/ |