comparison liboctave/UMFPACK/UMFPACK/Source/umfpack_save_numeric.c @ 5164:57077d0ddc8e

[project @ 2005-02-25 19:55:24 by jwe]
author jwe
date Fri, 25 Feb 2005 19:55:28 +0000
parents
children
comparison
equal deleted inserted replaced
5163:9f3299378193 5164:57077d0ddc8e
1 /* ========================================================================== */
2 /* === UMFPACK_save_numeric ================================================= */
3 /* ========================================================================== */
4
5 /* -------------------------------------------------------------------------- */
6 /* UMFPACK Version 4.4, Copyright (c) 2005 by Timothy A. Davis. CISE Dept, */
7 /* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. */
8 /* web: http://www.cise.ufl.edu/research/sparse/umfpack */
9 /* -------------------------------------------------------------------------- */
10
11 /*
12 User-callable. Saves a Numeric object to a file. It can later be read back
13 in via a call to umfpack_*_load_numeric.
14 */
15
16 #include "umf_internal.h"
17 #include "umf_valid_numeric.h"
18
19 #define WRITE(object,type,n) \
20 { \
21 ASSERT (object != (type *) NULL) ; \
22 if (fwrite (object, sizeof (type), n, f) != n) \
23 { \
24 fclose (f) ; \
25 return (UMFPACK_ERROR_file_IO) ; \
26 } \
27 }
28
29 /* ========================================================================== */
30 /* === UMFPACK_save_numeric ================================================= */
31 /* ========================================================================== */
32
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 WRITE (Numeric->Memory, Unit, Numeric->size) ;
87
88 /* close the file */
89 fclose (f) ;
90
91 return (UMFPACK_OK) ;
92 }