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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (show annotations)
Tue Oct 26 06:53:54 2004 UTC (15 years, 7 months ago) by jgs
File MIME type: text/plain
File size: 2644 byte(s)
Initial revision

1 /* $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 int iRow, iCol, iPtr;
21
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 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
40 switch(A_p->type) {
41 case CSR:
42 #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 case CSC:
59 #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 }
74
75 /* close the file */
76 fclose(fileHandle_p);
77
78 return;
79 }
80 /*
81 * $Log$
82 * Revision 1.1 2004/10/26 06:53:57 jgs
83 * Initial revision
84 *
85 * Revision 1.1 2004/07/02 04:21:13 gross
86 * Finley C code has been included
87 *
88 *
89 */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26