TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpctac
hcio.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include "
tpcift.h
"
8
#include "
tpcisotope.h
"
9
#include "
tpccsv.h
"
10
/*****************************************************************************/
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <math.h>
14
#include <time.h>
15
#include <string.h>
16
/*****************************************************************************/
17
#include "
tpctac.h
"
18
/*****************************************************************************/
19
20
/*****************************************************************************/
25
int
tacReadHRRTHC
(
27
TAC
*tac,
31
CSV
*csv,
33
TPCSTATUS
*status
34
) {
35
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
36
if
(tac==NULL) {
37
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_FAIL
);
38
return
TPCERROR_FAIL
;
39
}
40
if
(verbose>0) printf(
"%s()\n"
, __func__);
41
42
tacFree
(tac);
43
44
if
(csv==NULL || csv->
row_nr
<2 || csv->
col_nr
<4) {
45
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
46
return
TPCERROR_NO_DATA
;
47
}
48
49
/* Check from the title fields that data indeed is HRRT HC data */
50
int
ret=0;
51
if
(strcasecmp(csv->
c
[0].
content
,
"Singles"
)!=0) ret++;
52
if
(strcasecmp(csv->
c
[1].
content
,
"Randoms"
)!=0) ret++;
53
if
(strcasecmp(csv->
c
[2].
content
,
"Prompts"
)!=0) ret++;
54
if
(strncasecmp(csv->
c
[3].
content
,
"Time(ms)"
, 4)!=0) ret++;
55
if
(ret>0) {
56
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_INVALID_FORMAT
);
57
return
TPCERROR_INVALID_FORMAT
;
58
}
59
60
/* Allocate memory for TAC data */
61
ret=
tacAllocate
(tac, csv->
row_nr
-1, 3);
62
statusSet
(status, __func__, __FILE__, __LINE__, ret);
63
if
(ret!=
TPCERROR_OK
)
return
ret;
64
tac->
tacNr
=3; tac->
sampleNr
=csv->
row_nr
-1;
65
if
(verbose>2) printf(
" sampleNr=%d\n"
, tac->
sampleNr
);
66
67
/* Set time type */
68
tac->
isframe
=0;
69
/* Get time unit from the last title field, inside parens */
70
char
*cptr=strchr(csv->
c
[3].
content
,
'('
);
71
if
(cptr==NULL) {
72
tac->
tunit
=
UNIT_UNKNOWN
;
73
}
else
{
74
char
*tmp=
strdup
(cptr+1);
75
cptr=strrchr(tmp,
')'
);
if
(cptr!=NULL) *cptr=
'\0'
;
76
tac->
tunit
=
unitIdentify
(tmp);
77
free(tmp);
78
}
79
/* Set concentration unit */
80
tac->
cunit
=
UNIT_KCPS
;
81
82
/* Set TAC names */
83
strcpy(tac->
c
[0].
name
,
"Singles"
);
84
strcpy(tac->
c
[1].
name
,
"Randoms"
);
85
strcpy(tac->
c
[2].
name
,
"Prompts"
);
86
87
/* Copy x and y data from CSV into TAC struct */
88
double
v;
int
oknr=0;
89
for
(
int
i=4; i<csv->
nr
; i++) {
90
if
(csv->
c
[i].
row
<1 || csv->
c
[i].
row
>tac->
sampleNr
|| csv->
c
[i].
col
>3)
91
continue
;
92
v=
atofVerified
(csv->
c
[i].
content
);
if
(!isnan(v)) oknr++;
93
if
(csv->
c
[i].
col
==3) tac->
x
[csv->
c
[i].
row
-1]=v;
94
else
tac->
c
[csv->
c
[i].
col
].
y
[csv->
c
[i].
row
-1]=v;
95
}
96
if
(oknr<4) {
97
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
98
return
TPCERROR_NO_DATA
;
99
}
100
101
/* Set file format */
102
tac->
format
=
TAC_FORMAT_HRRT_HC
;
103
104
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
105
return
(
TPCERROR_OK
);
106
}
107
/*****************************************************************************/
108
109
/*****************************************************************************/
114
int
tacReadHRPLUSHC
(
116
TAC
*tac,
120
CSV
*csv,
122
TPCSTATUS
*status
123
) {
124
int
verbose=0;
if
(status!=NULL) verbose=status->
verbose
;
125
if
(tac==NULL) {
126
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_FAIL
);
127
return
TPCERROR_FAIL
;
128
}
129
if
(verbose>0) printf(
"%s()\n"
, __func__);
130
131
tacFree
(tac);
132
133
if
(csv==NULL || csv->
row_nr
<2 || csv->
col_nr
<8) {
134
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
135
return
TPCERROR_NO_DATA
;
136
}
137
138
/* Check from the title fields that data indeed is HRRT HC data */
139
int
ret=0;
140
if
(strcasecmp(csv->
c
[0].
content
,
"time"
)!=0) ret++;
141
if
(strcasecmp(csv->
c
[1].
content
,
"prompt"
)!=0) ret++;
142
if
(strcasecmp(csv->
c
[2].
content
,
"delayed"
)!=0) ret++;
143
if
(strcasecmp(csv->
c
[3].
content
,
"p_rate"
)!=0) ret++;
144
if
(strcasecmp(csv->
c
[4].
content
,
"d_rate"
)!=0) ret++;
145
if
(strcasecmp(csv->
c
[5].
content
,
"dtime"
)!=0) ret++;
146
if
(strcasecmp(csv->
c
[6].
content
,
"frame"
)!=0) ret++;
147
if
(strcasecmp(csv->
c
[7].
content
,
"singles"
)!=0) ret++;
148
if
(ret>0) {
149
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_INVALID_FORMAT
);
150
return
TPCERROR_INVALID_FORMAT
;
151
}
152
153
/* Allocate memory for TAC data */
154
ret=
tacAllocate
(tac, csv->
row_nr
-1, 7);
155
statusSet
(status, __func__, __FILE__, __LINE__, ret);
156
if
(ret!=
TPCERROR_OK
)
return
ret;
157
tac->
tacNr
=7; tac->
sampleNr
=csv->
row_nr
-1;
158
if
(verbose>2) printf(
" sampleNr=%d\n"
, tac->
sampleNr
);
159
160
/* Set time type */
161
tac->
isframe
=0;
162
/* Set time unit */
163
tac->
tunit
=
UNIT_MSEC
;
164
/* Set concentration unit */
165
tac->
cunit
=
UNIT_KCPS
;
166
167
/* Set TAC names */
168
strcpy(tac->
c
[0].
name
,
"prompt"
);
169
strcpy(tac->
c
[1].
name
,
"delayed"
);
170
strcpy(tac->
c
[2].
name
,
"p_rate"
);
171
strcpy(tac->
c
[3].
name
,
"d_rate"
);
172
strcpy(tac->
c
[4].
name
,
"dtime"
);
173
strcpy(tac->
c
[5].
name
,
"frame"
);
174
strcpy(tac->
c
[6].
name
,
"singles"
);
175
176
/* Copy x and y data from CSV into TAC struct */
177
double
v;
int
oknr=0;
178
for
(
int
i=8; i<csv->
nr
; i++) {
179
if
(csv->
c
[i].
row
<1 || csv->
c
[i].
row
>tac->
sampleNr
|| csv->
c
[i].
col
>7)
180
continue
;
181
v=
atofVerified
(csv->
c
[i].
content
);
if
(!isnan(v)) oknr++;
182
if
(csv->
c
[i].
col
==0) tac->
x
[csv->
c
[i].
row
-1]=v;
183
else
tac->
c
[csv->
c
[i].
col
-1].
y
[csv->
c
[i].
row
-1]=v;
184
}
185
if
(oknr<8) {
186
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_NO_DATA
);
187
return
TPCERROR_NO_DATA
;
188
}
189
190
/* Set file format */
191
tac->
format
=
TAC_FORMAT_HRPLUS_HC
;
192
193
statusSet
(status, __func__, __FILE__, __LINE__,
TPCERROR_OK
);
194
return
(
TPCERROR_OK
);
195
}
196
/*****************************************************************************/
197
198
/*****************************************************************************/
atofVerified
double atofVerified(const char *s)
Definition
decpoint.c:75
tacReadHRPLUSHC
int tacReadHRPLUSHC(TAC *tac, CSV *csv, TPCSTATUS *status)
Definition
hcio.c:114
tacReadHRRTHC
int tacReadHRRTHC(TAC *tac, CSV *csv, TPCSTATUS *status)
Definition
hcio.c:25
statusSet
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition
statusmsg.c:142
strdup
char * strdup(const char *s)
Definition
stringext.c:185
CSV_item::col
int col
Definition
tpccsv.h:28
CSV_item::row
int row
Definition
tpccsv.h:26
CSV_item::content
char * content
Definition
tpccsv.h:30
CSV
Definition
tpccsv.h:36
CSV::row_nr
int row_nr
Definition
tpccsv.h:44
CSV::col_nr
int col_nr
Definition
tpccsv.h:46
CSV::c
CSV_item * c
Definition
tpccsv.h:38
CSV::nr
int nr
Definition
tpccsv.h:42
TACC::name
char name[MAX_TACNAME_LEN+1]
Definition
tpctac.h:81
TACC::y
double * y
Definition
tpctac.h:75
TAC
Definition
tpctac.h:87
TAC::x
double * x
Definition
tpctac.h:97
TAC::cunit
unit cunit
Definition
tpctac.h:105
TAC::format
tacformat format
Definition
tpctac.h:93
TAC::sampleNr
int sampleNr
Definition
tpctac.h:89
TAC::isframe
int isframe
Definition
tpctac.h:95
TAC::c
TACC * c
Definition
tpctac.h:117
TAC::tunit
unit tunit
Definition
tpctac.h:109
TAC::tacNr
int tacNr
Definition
tpctac.h:91
TPCSTATUS
Definition
tpcextensions.h:241
TPCSTATUS::verbose
int verbose
Verbose level, used by statusPrint() etc.
Definition
tpcextensions.h:242
tacFree
void tacFree(TAC *tac)
Definition
tac.c:106
tacAllocate
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
Definition
tac.c:130
tpccsv.h
Header file for library libtpccsv.
UNIT_MSEC
@ UNIT_MSEC
milliseconds
Definition
tpcextensions.h:88
UNIT_UNKNOWN
@ UNIT_UNKNOWN
Unknown unit.
Definition
tpcextensions.h:85
UNIT_KCPS
@ UNIT_KCPS
kilocounts/s
Definition
tpcextensions.h:124
TPCERROR_FAIL
@ TPCERROR_FAIL
General error.
Definition
tpcextensions.h:192
TPCERROR_INVALID_FORMAT
@ TPCERROR_INVALID_FORMAT
Invalid file format.
Definition
tpcextensions.h:201
TPCERROR_OK
@ TPCERROR_OK
No error.
Definition
tpcextensions.h:191
TPCERROR_NO_DATA
@ TPCERROR_NO_DATA
File contains no data.
Definition
tpcextensions.h:203
unitIdentify
int unitIdentify(const char *s)
Definition
units.c:162
tpcift.h
Header file for library libtpcift.
tpcisotope.h
Header file for library libtpcisotope.
tpctac.h
Header file for library libtpctac.
TAC_FORMAT_HRPLUS_HC
@ TAC_FORMAT_HRPLUS_HC
HR+ head curve format (reading supported).
Definition
tpctac.h:52
TAC_FORMAT_HRRT_HC
@ TAC_FORMAT_HRRT_HC
HRRT head curve format (reading supported).
Definition
tpctac.h:51
Generated on
for TPCCLIB by
1.17.0