TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpccurveio
xeleris.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
#include "
libtpccurveio.h
"
7
/*****************************************************************************/
8
9
/*****************************************************************************/
14
int
xelRead
(
16
char
*filename,
18
DFT
*dft
19
) {
20
int
ii, si, ri, fi, n, ret;
21
char
tmp[1024], tmp2[512], *cptr;
22
IFT
ift;
23
float
f[6];
24
25
26
/* Check the arguments */
27
if
(filename==NULL || dft==NULL || strlen(filename)<1) {
28
strcpy(
dfterrmsg
,
"program error"
);
return
(1);
29
}
30
31
/* Read the file contents */
32
iftInit
(&ift); ret=
iftRead
(&ift, filename, 0, 0);
33
if
(ret) {strcpy(
dfterrmsg
, ift.
status
);
iftEmpty
(&ift);
return
(2);}
34
35
/* Check that this actually is a Xeleris TAC file */
36
strcpy(tmp,
"Image Position"
); ii=
iftGet
(&ift, tmp, 0);
37
if
(ii<0) {strcpy(
dfterrmsg
,
"wrong format"
);
iftEmpty
(&ift);
return
(3);}
38
strcpy(tmp,
"XAxis"
); ii=
iftGet
(&ift, tmp, 0);
39
if
(ii<0) {strcpy(
dfterrmsg
,
"wrong format"
);
iftEmpty
(&ift);
return
(3);}
40
strcpy(tmp,
"YAxis"
); ii=
iftGet
(&ift, tmp, 0);
41
if
(ii<0) {strcpy(
dfterrmsg
,
"wrong format"
);
iftEmpty
(&ift);
return
(3);}
42
43
/* Find the data title, and assume that lines after that contain the TACs */
44
strcpy(tmp,
"Curve X Dur Max Min Mean StdDev"
);
45
ii=
iftFindNthValue
(&ift, tmp, 1, 0);
46
if
(ii<0) {strcpy(
dfterrmsg
,
"wrong format"
);
iftEmpty
(&ift);
return
(4);}
47
si=ii+1;
48
49
/* Determine the number of TACs and time frames */
50
ri=fi=0; strcpy(tmp2,
""
); n=1;
51
for
(ii=si; ii<ift.
keyNr
; ii++) {
52
if
(sscanf(ift.
item
[ii].
value
,
"%s"
, tmp)!=1) {
53
strcpy(
dfterrmsg
,
"wrong format"
);
iftEmpty
(&ift);
return
(5);}
54
if
(strcmp(tmp, tmp2)==0) {
55
n++;
if
(n>fi) fi=n;
56
}
else
{
57
ri++; strcpy(tmp2, tmp);
if
(n>fi) fi=n; n=1;
58
}
59
//printf("tmp=%s tmp2=%s n=%d, ri=%d fi=%d\n", tmp, tmp2, n, ri, fi);
60
}
61
if
(ri<1 || fi<1) {strcpy(
dfterrmsg
,
"wrong format"
);
iftEmpty
(&ift);
return
(6);}
62
63
/* Allocate memory for DFT data */
64
if
(
dftSetmem
(dft, fi, ri)) {
65
strcpy(
dfterrmsg
,
"out of memory"
);
iftEmpty
(&ift);
return
(7);}
66
dft->
frameNr
=fi; dft->
voiNr
=ri;
67
68
/* Read TAC data and fill DFT */
69
ri=fi=0; strcpy(tmp2,
""
); n=1;
70
for
(ii=si; ii<ift.
keyNr
; ii++) {
71
if
(sscanf(ift.
item
[ii].
value
,
"%s %f %f %f %f %f %f"
,
72
tmp, f, f+1, f+2, f+3, f+4, f+5)!=7) {
73
strcpy(
dfterrmsg
,
"wrong format"
);
iftEmpty
(&ift);
return
(5);}
74
if
(strcmp(tmp, tmp2)==0) n++;
75
else
{ri++; strcpy(tmp2, tmp);
if
(n>fi) fi=n; n=1;}
76
//printf("tmp=%s tmp2=%s n=%d, ri=%d fi=%d\n", tmp, tmp2, n, ri, fi);
77
/* TAC name */
78
strlcpy
(dft->
voi
[ri-1].
voiname
, tmp,
MAX_REGIONSUBNAME_LEN
+1);
79
//dft->voi[ri-1].voiname[MAX_REGIONSUBNAME_LEN]='\0';
80
/* Frame time */
81
if
(ri==1) {
82
dft->
x1
[n-1]=f[0]; dft->
x2
[n-1]=f[0]+f[1];
83
dft->
x
[n-1]=0.5*(dft->
x1
[n-1]+dft->
x2
[n-1]);
84
}
else
{
85
if
(fabs(dft->
x1
[n-1]-f[0])>1.0E-12 || fabs(dft->
x2
[n-1]-f[0]-f[1])>1.0E-12) {
86
strcpy(
dfterrmsg
,
"wrong format"
);
iftEmpty
(&ift);
return
(8);}
87
}
88
/* Concentrations */
89
dft->
voi
[ri-1].
y
[n-1]=f[4];
90
}
91
92
/* Add image position to the TAC name, if possible */
93
strcpy(tmp,
"Image Position"
); ii=
iftGet
(&ift, tmp, 0);
94
if
(ii>=0) {
95
f[0]=atof(ift.
item
[ii].
value
); sprintf(tmp,
"%-6.0f"
, f[0]); tmp[6]=
'\0'
;
96
for
(ri=0; ri<dft->
voiNr
; ri++) {
97
strcpy(dft->
voi
[ri].
place
, tmp);
98
sprintf(dft->
voi
[ri].
name
,
"%s . %s"
, dft->
voi
[ri].
voiname
, dft->
voi
[ri].
place
);
99
}
100
}
101
102
/* Determine the concentration (y axis) unit */
103
strcpy(tmp,
"YAxis"
); ii=
iftGet
(&ift, tmp, 0);
104
if
(ii>=0 && strncasecmp(ift.
item
[ii].
value
,
"Uptake (Bqml)"
, 8)==0) {
105
cptr=ift.
item
[ii].
value
+8;
106
if
( strncasecmp(cptr,
"Bqml"
, 4)==0) strcpy(dft->
unit
,
"Bq/ml"
);
107
else
if
(strncasecmp(cptr,
"kBqml"
, 5)==0) strcpy(dft->
unit
,
"kBq/ml"
);
108
else
if
(strncasecmp(cptr,
"MBqml"
, 5)==0) strcpy(dft->
unit
,
"MBq/ml"
);
109
else
if
(strncasecmp(cptr,
"Bqcc"
, 4)==0) strcpy(dft->
unit
,
"Bq/ml"
);
110
else
if
(strncasecmp(cptr,
"kBqcc"
, 5)==0) strcpy(dft->
unit
,
"kBq/ml"
);
111
else
if
(strncasecmp(cptr,
"MBqcc"
, 5)==0) strcpy(dft->
unit
,
"MBq/ml"
);
112
}
113
114
/* Determine the time (x axis) unit */
115
dft->
timeunit
=TUNIT_UNKNOWN;
116
strcpy(tmp,
"XAxis"
); ii=
iftGet
(&ift, tmp, 0);
117
if
(ii>=0) {
118
if
(strcasecmp(ift.
item
[ii].
value
,
"sec"
)==0) dft->
timeunit
=TUNIT_SEC;
119
else
if
(strcasecmp(ift.
item
[ii].
value
,
"min"
)==0) dft->
timeunit
=TUNIT_MIN;
120
}
121
122
iftEmpty
(&ift);
123
124
/* Set the study number based on filename */
125
(void)
studynr_from_fname
(filename, dft->
studynr
);
126
127
/* Set the rest of DFT "header" */
128
dft->
_type
=1;
129
dft->
timetype
=3;
130
dft->
isweight
=0;
131
132
return
(0);
133
}
134
/*****************************************************************************/
135
136
/*****************************************************************************/
dfterrmsg
char dfterrmsg[64]
Definition
dft.c:6
dftSetmem
int dftSetmem(DFT *data, int frameNr, int voiNr)
Definition
dft.c:57
iftEmpty
void iftEmpty(IFT *ift)
Definition
ift.c:60
iftInit
void iftInit(IFT *ift)
Definition
ift.c:45
iftRead
int iftRead(IFT *ift, char *filename, int is_key_required, int verbose)
Definition
iftfile.c:24
iftFindNthValue
int iftFindNthValue(IFT *ift, char *str, int n, int verbose)
Definition
iftsrch.c:120
iftGet
int iftGet(IFT *ift, char *key, int verbose)
Definition
iftsrch.c:15
libtpccurveio.h
Header file for libtpccurveio.
strlcpy
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition
strext.c:244
studynr_from_fname
int studynr_from_fname(char *fname, char *studynr)
Definition
studynr.c:119
MAX_REGIONSUBNAME_LEN
#define MAX_REGIONSUBNAME_LEN
Definition
libtpcmisc.h:158
DFT
Definition
libtpccurveio.h:73
DFT::_type
int _type
Definition
libtpccurveio.h:125
DFT::timetype
int timetype
Definition
libtpccurveio.h:99
DFT::voi
Voi * voi
Definition
libtpccurveio.h:108
DFT::timeunit
int timeunit
Definition
libtpccurveio.h:85
DFT::studynr
char studynr[MAX_STUDYNR_LEN+1]
Definition
libtpccurveio.h:80
DFT::x1
double * x1
Definition
libtpccurveio.h:104
DFT::voiNr
int voiNr
Definition
libtpccurveio.h:78
DFT::x2
double * x2
Definition
libtpccurveio.h:106
DFT::frameNr
int frameNr
Definition
libtpccurveio.h:76
DFT::isweight
int isweight
Definition
libtpccurveio.h:112
DFT::x
double * x
Definition
libtpccurveio.h:102
DFT::unit
char unit[MAX_UNITS_LEN+1]
Definition
libtpccurveio.h:83
IFT_KEY_AND_VALUE::value
char * value
Definition
libtpcmisc.h:261
IFT
Definition
libtpcmisc.h:264
IFT::keyNr
int keyNr
Definition
libtpcmisc.h:270
IFT::status
const char * status
Definition
libtpcmisc.h:277
IFT::item
IFT_KEY_AND_VALUE * item
Definition
libtpcmisc.h:279
Voi::voiname
char voiname[MAX_REGIONSUBNAME_LEN+1]
Definition
libtpccurveio.h:50
Voi::y
double * y
Definition
libtpccurveio.h:59
Voi::name
char name[MAX_REGIONNAME_LEN+1]
Definition
libtpccurveio.h:48
Voi::place
char place[MAX_REGIONSUBNAME_LEN+1]
Definition
libtpccurveio.h:54
xelRead
int xelRead(char *filename, DFT *dft)
Definition
xeleris.c:14
Generated on
for TPCCLIB by
1.17.0