Blame view

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