1 /* ========================================================================== */
2 /* === UMFPACK_save_numeric ================================================= */
3 /* ========================================================================== */
4
5 /* -------------------------------------------------------------------------- */
6 /* Copyright (c) 2005-2012 by Timothy A. Davis, http://www.suitesparse.com. */
7 /* All Rights Reserved. See ../Doc/License.txt for License. */
8 /* -------------------------------------------------------------------------- */
9
10 /*
11 User-callable. Saves a Numeric object to a file. It can later be read back
12 in via a call to umfpack_*_load_numeric.
13 */
14
15 #include "umf_internal.h"
16 #include "umf_valid_numeric.h"
17
18 #define WRITE(object,type,n) \
19 { \
20 ASSERT (object != (type *) NULL) ; \
21 if (fwrite (object, sizeof (type), n, f) != (size_t) n) \
22 { \
23 fclose (f) ; \
24 return (UMFPACK_ERROR_file_IO) ; \
25 } \
26 fflush (f) ; \
27 }
28
29 /* ========================================================================== */
30 /* === UMFPACK_save_numeric ================================================= */
31 /* ========================================================================== */
32
UMFPACK_save_numeric(void * NumericHandle,char * user_filename)33 GLOBAL Int UMFPACK_save_numeric
34 (
35 void *NumericHandle,
36 char *user_filename
37 )
38 {
39 NumericType *Numeric ;
40 char *filename ;
41 FILE *f ;
42
43 /* get the Numeric object */
44 Numeric = (NumericType *) NumericHandle ;
45
46 /* make sure the Numeric object is valid */
47 if (!UMF_valid_numeric (Numeric))
48 {
49 return (UMFPACK_ERROR_invalid_Numeric_object) ;
50 }
51
52 /* get the filename, or use the default name if filename is NULL */
53 if (user_filename == (char *) NULL)
54 {
55 filename = "numeric.umf" ;
56 }
57 else
58 {
59 filename = user_filename ;
60 }
61 f = fopen (filename, "wb") ;
62 if (!f)
63 {
64 return (UMFPACK_ERROR_file_IO) ;
65 }
66
67 /* write the Numeric object to the file, in binary */
68 WRITE (Numeric, NumericType, 1) ;
69 WRITE (Numeric->D, Entry, MIN (Numeric->n_row, Numeric->n_col)+1) ;
70 WRITE (Numeric->Rperm, Int, Numeric->n_row+1) ;
71 WRITE (Numeric->Cperm, Int, Numeric->n_col+1) ;
72 WRITE (Numeric->Lpos, Int, Numeric->npiv+1) ;
73 WRITE (Numeric->Lilen, Int, Numeric->npiv+1) ;
74 WRITE (Numeric->Lip, Int, Numeric->npiv+1) ;
75 WRITE (Numeric->Upos, Int, Numeric->npiv+1) ;
76 WRITE (Numeric->Uilen, Int, Numeric->npiv+1) ;
77 WRITE (Numeric->Uip, Int, Numeric->npiv+1) ;
78 if (Numeric->scale != UMFPACK_SCALE_NONE)
79 {
80 WRITE (Numeric->Rs, double, Numeric->n_row) ;
81 }
82 if (Numeric->ulen > 0)
83 {
84 WRITE (Numeric->Upattern, Int, Numeric->ulen+1) ;
85 }
86 /* It is possible that some parts of Numeric->Memory are
87 unitialized and unused; this is OK, but it can generate
88 a valgrind warning. */
89 WRITE (Numeric->Memory, Unit, Numeric->size) ;
90
91 /* close the file */
92 fclose (f) ;
93
94 return (UMFPACK_OK) ;
95 }
96