/[escript]/trunk/esys2/finley/src/finleyC/System_saveMM.c
ViewVC logotype

Annotation of /trunk/esys2/finley/src/finleyC/System_saveMM.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 108 - (hide annotations)
Thu Jan 27 06:21:59 2005 UTC (15 years, 4 months ago) by jgs
File MIME type: text/plain
File size: 2403 byte(s)
*** empty log message ***

1 jgs 82 /* $Id$ */
2    
3     /**************************************************************/
4    
5     /* Finley: 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 "Finley.h"
15     #include "mmio.h"
16     #include "System.h"
17    
18     void Finley_SystemMatrix_saveMM(Finley_SystemMatrix * A_p, char * fileName_p) {
19    
20 jgs 102 int iRow, iCol, iPtr,ir,ic;
21 jgs 82
22     /* open the file */
23     FILE * fileHandle_p = fopen(fileName_p, "w");
24     if (fileHandle_p==NULL) {
25     Finley_ErrorCode =IO_ERROR;
26     sprintf(Finley_ErrorMsg, "file %s could not be opened for writing",fileName_p);
27     return;
28     }
29    
30     /* set the matrix code */
31     MM_typecode matrixCode;
32     mm_initialize_typecode(&matrixCode);
33     mm_set_matrix(&matrixCode);
34     mm_set_coordinate(&matrixCode);
35     mm_set_real(&matrixCode);
36    
37     mm_write_banner(fileHandle_p, matrixCode);
38 jgs 102 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);
39 jgs 82
40     switch(A_p->type) {
41     case CSR:
42 jgs 102 for (iRow = 0; iRow< A_p->pattern->n_ptr; iRow++) {
43     for (ir = 0; ir< A_p->row_block_size; ir++) {
44     for (iPtr = A_p->pattern->ptr[iRow] - PTR_OFFSET;iPtr < A_p->pattern->ptr[iRow+1] - PTR_OFFSET; iPtr++) {
45     for (ic = 0; ic< A_p->col_block_size; ic++) {
46 jgs 108 fprintf(fileHandle_p, "%12d %12d %e\n",
47 jgs 102 iRow*A_p->row_block_size+ir+ 1,
48     (A_p->pattern->index[iPtr]-INDEX_OFFSET)*A_p->col_block_size+ic+1,
49     A_p->val[iPtr*A_p->block_size+ir+A_p->row_block_size*ic]);
50     }
51     }
52     }
53     }
54     break;
55 jgs 82 case CSC:
56 jgs 102 for (iCol = 0; iCol< A_p->pattern->n_ptr; iCol++) {
57     for (ic = 0; ic< A_p->col_block_size; ic++) {
58     for (iPtr = A_p->pattern->ptr[iCol] - PTR_OFFSET;iPtr < A_p->pattern->ptr[iCol+1] - PTR_OFFSET; iPtr++) {
59     for (ir = 0; ir< A_p->row_block_size; ir++) {
60 jgs 108 fprintf(fileHandle_p, "%12d %12d %e\n",
61 jgs 102 (A_p->pattern->index[iPtr]-INDEX_OFFSET)*A_p->row_block_size+ir+1,
62     iCol*A_p->col_block_size+ic+ 1,
63     A_p->val[iPtr*A_p->block_size+ir+A_p->row_block_size*ic]);
64     }
65     }
66     }
67     }
68 jgs 82 }
69    
70     /* close the file */
71     fclose(fileHandle_p);
72    
73     return;
74     }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26