1 /* basics.c */
2
3 #include "../SubMtx.h"
4
5 #define MYDEBUG 0
6
7 /*--------------------------------------------------------------------*/
8 /*
9 -----------------------
10 simplest constructor
11
12 created -- 98may01, cca
13 -----------------------
14 */
15 SubMtx *
SubMtx_new(void)16 SubMtx_new (
17 void
18 ) {
19 SubMtx *mtx ;
20
21 ALLOCATE(mtx, struct _SubMtx, 1) ;
22 SubMtx_setDefaultFields(mtx) ;
23
24 return(mtx) ; }
25
26 /*--------------------------------------------------------------------*/
27 /*
28 -----------------------
29 set the default fields
30
31 created -- 98may01, cca
32 -----------------------
33 */
34 void
SubMtx_setDefaultFields(SubMtx * mtx)35 SubMtx_setDefaultFields (
36 SubMtx *mtx
37 ) {
38 if ( mtx == NULL ) {
39 fprintf(stderr, "\n fatal error in SubMtx_setDefaultFields(%p)"
40 "\n bad input", mtx) ;
41 exit(-1) ;
42 }
43 mtx->type = SPOOLES_REAL ;
44 mtx->mode = SUBMTX_DENSE_COLUMNS ;
45 mtx->rowid = -1 ;
46 mtx->colid = -1 ;
47 mtx->nrow = 0 ;
48 mtx->ncol = 0 ;
49 mtx->nent = 0 ;
50 mtx->next = NULL ;
51 DV_setDefaultFields(&mtx->wrkDV) ;
52
53 return ; }
54
55 /*--------------------------------------------------------------------*/
56 /*
57 --------------------------------------------------
58 clear the data fields, releasing allocated storage
59
60 created -- 98may01, cca
61 --------------------------------------------------
62 */
63 void
SubMtx_clearData(SubMtx * mtx)64 SubMtx_clearData (
65 SubMtx *mtx
66 ) {
67 /*
68 ---------------
69 check the input
70 ---------------
71 */
72 if ( mtx == NULL ) {
73 fprintf(stderr, "\n fatal error in SubMtx_clearData(%p)"
74 "\n bad input\n", mtx) ;
75 exit(-1) ;
76 }
77 /*
78 ------------------------
79 free the working storage
80 ------------------------
81 */
82 DV_clearData(&mtx->wrkDV) ;
83 /*
84 ----------------------
85 set the default fields
86 ----------------------
87 */
88 SubMtx_setDefaultFields(mtx) ;
89
90 return ; }
91
92 /*--------------------------------------------------------------------*/
93 /*
94 ------------------------------------------
95 destructor, free's the object and its data
96
97 created -- 98may01, cca
98 ------------------------------------------
99 */
100 void
SubMtx_free(SubMtx * mtx)101 SubMtx_free (
102 SubMtx *mtx
103 ) {
104 if ( mtx == NULL ) {
105 fprintf(stderr, "\n fatal error in SubMtx_free(%p)"
106 "\n bad input\n", mtx) ;
107 exit(-1) ;
108 }
109 SubMtx_clearData(mtx) ;
110 FREE(mtx) ;
111
112 return ; }
113
114 /*--------------------------------------------------------------------*/
115