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