/[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 100 - (hide annotations)
Wed Dec 15 03:48:48 2004 UTC (15 years, 5 months ago) by jgs
File MIME type: text/plain
File size: 2737 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 100 int iRow, iCol, iPtr;
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 100 mm_write_mtx_crd_size(fileHandle_p, A_p->num_rows, A_p->num_cols, A_p->ptr[A_p->num_cols] - PTR_OFFSET);
39 jgs 82
40     switch(A_p->type) {
41     case CSR:
42 jgs 100 #if INDEX_OFFSET==0
43     /* add 1 for 1-based indexing */
44     for (iRow = 0; iRow < A_p->num_rows; iRow++)
45     for (iPtr = A_p->ptr[iRow] - PTR_OFFSET;
46     iPtr < A_p->ptr[iRow+1] - PTR_OFFSET; iPtr++)
47     fprintf(fileHandle_p, "%12d %12d %22.15g\n",
48     iRow + 1, A_p->index[iPtr] + 1, A_p->val[iPtr]);
49     #else
50     /* matrix market uses 1-based indexing */
51     for (iRow = 0; iRow< A_p->num_rows; iRow++)
52     for (iPtr = A_p->ptr[iRow] - PTR_OFFSET;
53     iPtr < A_p->ptr[iRow+1] - PTR_OFFSET; iPtr++)
54     fprintf(fileHandle_p, "%12d %12d %22.15g\n",
55     iRow + INDEX_OFFSET, A_p->index[iPtr], A_p->val[iPtr]);
56     #endif
57     break;
58 jgs 82 case CSC:
59 jgs 100 #if INDEX_OFFSET==0
60     /* add 1 for 1-based indexing */
61     for (iCol = 0; iCol < A_p->num_cols; iCol++)
62     for (iPtr = A_p->ptr[iCol] - PTR_OFFSET;
63     iPtr < A_p->ptr[iCol+1] - PTR_OFFSET; iPtr++)
64     fprintf(fileHandle_p, "%12d %12d %22.15g\n", A_p->index[iPtr] + 1, iCol + 1, A_p->val[iPtr]);
65     #else
66     /* matrix market uses 1-based indexing */
67     for (iCol = 0; iCol< A_p->num_cols; iCol++)
68     for (iPtr = A_p->ptr[iCol] - PTR_OFFSET;
69     iPtr < A_p->ptr[iCol+1] - PTR_OFFSET; iPtr++)
70     fprintf(fileHandle_p, "%12d %12d %22.15g\n", A_p->index[iPtr],
71     iCol + INDEX_OFFSET, A_p->val[iPtr]);
72     #endif
73 jgs 82 }
74    
75     /* close the file */
76     fclose(fileHandle_p);
77    
78     return;
79     }
80     /*
81     * $Log$
82 jgs 100 * Revision 1.3 2004/12/15 03:48:47 jgs
83 jgs 97 * *** empty log message ***
84 jgs 82 *
85 jgs 97 * Revision 1.1.1.1 2004/10/26 06:53:57 jgs
86     * initial import of project esys2
87     *
88 jgs 82 * Revision 1.1 2004/07/02 04:21:13 gross
89     * Finley C code has been included
90     *
91     *
92     */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26