1 /* basics.c */
2
3 #include "../InpMtx.h"
4
5 #define MYDEBUG 0
6
7 /*--------------------------------------------------------------------*/
8 /*
9 -----------------------
10 simplest constructor
11
12 created -- 98jan28, cca
13 -----------------------
14 */
15 InpMtx *
InpMtx_new(void)16 InpMtx_new (
17 void
18 ) {
19 InpMtx *inpmtx ;
20
21 ALLOCATE(inpmtx, struct _InpMtx, 1) ;
22 InpMtx_setDefaultFields(inpmtx) ;
23
24 return(inpmtx) ; }
25
26 /*--------------------------------------------------------------------*/
27 /*
28 -----------------------
29 set the default fields
30
31 created -- 98jan28, cca
32 -----------------------
33 */
34 void
InpMtx_setDefaultFields(InpMtx * inpmtx)35 InpMtx_setDefaultFields (
36 InpMtx *inpmtx
37 ) {
38 if ( inpmtx == NULL ) {
39 fprintf(stderr, "\n fatal error in InpMtx_setDefaultFields(%p)"
40 "\n bad input", inpmtx) ;
41 exit(-1) ;
42 }
43 inpmtx->coordType = INPMTX_BY_ROWS ;
44 inpmtx->storageMode = INPMTX_RAW_DATA ;
45 inpmtx->inputMode = SPOOLES_REAL ;
46 inpmtx->maxnent = 0 ;
47 inpmtx->nent = 0 ;
48 inpmtx->resizeMultiple = 1.25 ;
49 inpmtx->maxnvector = 0 ;
50 inpmtx->nvector = 0 ;
51 IV_setDefaultFields(&inpmtx->ivec1IV) ;
52 IV_setDefaultFields(&inpmtx->ivec2IV) ;
53 DV_setDefaultFields(&inpmtx->dvecDV) ;
54 IV_setDefaultFields(&inpmtx->vecidsIV) ;
55 IV_setDefaultFields(&inpmtx->sizesIV) ;
56 IV_setDefaultFields(&inpmtx->offsetsIV) ;
57
58 return ; }
59
60 /*--------------------------------------------------------------------*/
61 /*
62 --------------------------------------------------
63 clear the data fields, releasing allocated storage
64
65 created -- 98jan28, cca
66 --------------------------------------------------
67 */
68 void
InpMtx_clearData(InpMtx * inpmtx)69 InpMtx_clearData (
70 InpMtx *inpmtx
71 ) {
72 /*
73 ---------------
74 check the input
75 ---------------
76 */
77 if ( inpmtx == NULL ) {
78 fprintf(stderr, "\n fatal error in InpMtx_clearData(%p)"
79 "\n bad input\n", inpmtx) ;
80 exit(-1) ;
81 }
82 /*
83 -----------------------------------------------------
84 free any storage held in the IV and DV vector objects
85 -----------------------------------------------------
86 */
87 IV_clearData(&inpmtx->ivec1IV) ;
88 IV_clearData(&inpmtx->ivec2IV) ;
89 DV_clearData(&inpmtx->dvecDV) ;
90 IV_clearData(&inpmtx->vecidsIV) ;
91 IV_clearData(&inpmtx->sizesIV) ;
92 IV_clearData(&inpmtx->offsetsIV) ;
93 /*
94 ----------------------
95 set the default fields
96 ----------------------
97 */
98 InpMtx_setDefaultFields(inpmtx) ;
99
100 return ; }
101
102 /*--------------------------------------------------------------------*/
103 /*
104 ------------------------------------------
105 destructor, free's the object and its data
106
107 created -- 98jan28, cca
108 ------------------------------------------
109 */
110 InpMtx *
InpMtx_free(InpMtx * inpmtx)111 InpMtx_free (
112 InpMtx *inpmtx
113 ) {
114 if ( inpmtx == NULL ) {
115 fprintf(stderr, "\n fatal error in InpMtx_free(%p)"
116 "\n bad input\n", inpmtx) ;
117 exit(-1) ;
118 }
119 InpMtx_clearData(inpmtx) ;
120 FREE(inpmtx) ;
121
122 return(NULL) ; }
123
124 /*--------------------------------------------------------------------*/
125