TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpctac
mtac.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include "
tpcift.h
"
8
#include "
tpcisotope.h
"
9
/*****************************************************************************/
10
#include <stdio.h>
11
#include <stdlib.h>
12
#include <math.h>
13
#include <time.h>
14
#include <string.h>
15
/*****************************************************************************/
16
#include "
tpctac.h
"
17
/*****************************************************************************/
18
19
/*****************************************************************************/
23
void
mtacInit
(
25
MTAC
*mtac
26
) {
27
if
(mtac==NULL)
return
;
28
mtac->
nr
=mtac->
_nr
=0;
29
mtac->
tac
=NULL;
30
}
31
/*****************************************************************************/
32
33
/*****************************************************************************/
38
void
mtacFree
(
40
MTAC
*mtac
41
) {
42
if
(mtac==NULL)
return
;
43
/* Free allocated TACs. */
44
for
(
int
i=0; i<mtac->
_nr
; i++)
tacFree
(&mtac->
tac
[i]);
45
free(mtac->
tac
);
46
// then set everything to zero or NULL again
47
mtacInit
(mtac);
48
}
49
/*****************************************************************************/
50
51
/*****************************************************************************/
56
int
mtacAllocate
(
59
MTAC
*mtac,
61
int
nr
62
) {
63
if
(mtac==NULL)
return
TPCERROR_FAIL
;
64
/* Delete any previous contents */
65
mtacFree
(mtac);
66
/* If no memory is requested, then just return */
67
if
(nr<1)
return
TPCERROR_OK
;
68
/* Allocate the list of TACs */
69
mtac->
tac
=(
TAC
*)malloc(nr*
sizeof
(
TAC
));
70
if
(mtac->
tac
==NULL)
return
TPCERROR_OUT_OF_MEMORY
;
71
for
(
int
i=0; i<nr; i++)
tacInit
(&mtac->
tac
[i]);
72
mtac->
_nr
=nr;
73
return
TPCERROR_OK
;
74
}
75
/*****************************************************************************/
76
77
/*****************************************************************************/
83
int
mtacAllocateMore
(
86
MTAC
*mtac,
89
int
nr
90
) {
91
if
(mtac==NULL)
return
TPCERROR_FAIL
;
92
93
/* If not allocated before, then use mtacAllocate */
94
if
(mtac->
_nr
==0)
return
(
mtacAllocate
(mtac, nr));
95
96
/* Check if there is enough space already */
97
int
newNr, addNr;
98
newNr=mtac->
nr
+ nr;
99
addNr=newNr - mtac->
_nr
;
100
if
(addNr<=0)
return
TPCERROR_OK
;
101
102
/* Reallocate memory for TACC data */
103
TAC
*tacPtr;
104
tacPtr=realloc(mtac->
tac
,
sizeof
(
TAC
)*newNr);
105
if
(tacPtr==NULL)
return
TPCERROR_OUT_OF_MEMORY
;
106
mtac->
tac
=tacPtr;
107
108
/* Update the nr of allocated TACs and initiate new TACs */
109
for
(
int
i=mtac->
_nr
; i<newNr; i++)
tacInit
(&mtac->
tac
[i]);
110
mtac->
_nr
=newNr;
111
112
return
TPCERROR_OK
;
113
}
114
/*****************************************************************************/
115
116
/*****************************************************************************/
121
int
mtacAddTAC
(
123
MTAC
*mtac,
125
TAC
*tac
126
) {
127
if
(mtac==NULL || tac==NULL)
return
TPCERROR_FAIL
;
128
/* Make room for the TAC */
129
int
ret=
mtacAllocateMore
(mtac, 1);
if
(ret!=
TPCERROR_OK
)
return
(ret);
130
/* Copy TAC into the end of the list */
131
ret=
tacDuplicate
(tac, &mtac->
tac
[mtac->
nr
]);
if
(ret!=
TPCERROR_OK
)
return
(ret);
132
mtac->
nr
++;
133
return
TPCERROR_OK
;
134
}
135
/*****************************************************************************/
136
137
/*****************************************************************************/
mtacAllocateMore
int mtacAllocateMore(MTAC *mtac, int nr)
Definition
mtac.c:83
mtacAllocate
int mtacAllocate(MTAC *mtac, int nr)
Definition
mtac.c:56
mtacAddTAC
int mtacAddTAC(MTAC *mtac, TAC *tac)
Definition
mtac.c:121
mtacFree
void mtacFree(MTAC *mtac)
Definition
mtac.c:38
mtacInit
void mtacInit(MTAC *mtac)
Definition
mtac.c:23
MTAC
Definition
tpctac.h:149
MTAC::tac
TAC * tac
Definition
tpctac.h:151
MTAC::_nr
int _nr
Definition
tpctac.h:155
MTAC::nr
int nr
Definition
tpctac.h:153
TAC
Definition
tpctac.h:87
tacFree
void tacFree(TAC *tac)
Definition
tac.c:106
tacDuplicate
int tacDuplicate(TAC *tac1, TAC *tac2)
Make a duplicate of TAC structure.
Definition
tac.c:356
tacInit
void tacInit(TAC *tac)
Definition
tac.c:24
TPCERROR_FAIL
@ TPCERROR_FAIL
General error.
Definition
tpcextensions.h:192
TPCERROR_OUT_OF_MEMORY
@ TPCERROR_OUT_OF_MEMORY
Cannot allocate memory.
Definition
tpcextensions.h:193
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
tpcift.h
Header file for library libtpcift.
tpcisotope.h
Header file for library libtpcisotope.
tpctac.h
Header file for library libtpctac.
Generated on
for TPCCLIB by
1.17.0