TPCCLIB
Loading...
Searching...
No Matches
xeleris.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "libtpccurveio.h"
7/*****************************************************************************/
8
9/*****************************************************************************/
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/*****************************************************************************/
char dfterrmsg[64]
Definition dft.c:6
int dftSetmem(DFT *data, int frameNr, int voiNr)
Definition dft.c:57
void iftEmpty(IFT *ift)
Definition ift.c:60
void iftInit(IFT *ift)
Definition ift.c:45
int iftRead(IFT *ift, char *filename, int is_key_required, int verbose)
Definition iftfile.c:24
int iftFindNthValue(IFT *ift, char *str, int n, int verbose)
Definition iftsrch.c:120
int iftGet(IFT *ift, char *key, int verbose)
Definition iftsrch.c:15
Header file for libtpccurveio.
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition strext.c:245
int studynr_from_fname(char *fname, char *studynr)
Definition studynr.c:119
#define MAX_REGIONSUBNAME_LEN
Definition libtpcmisc.h:158
int _type
int timetype
Voi * voi
int timeunit
char studynr[MAX_STUDYNR_LEN+1]
double * x1
int voiNr
double * x2
int frameNr
int isweight
double * x
char unit[MAX_UNITS_LEN+1]
int keyNr
Definition libtpcmisc.h:270
const char * status
Definition libtpcmisc.h:277
IFT_KEY_AND_VALUE * item
Definition libtpcmisc.h:279
char voiname[MAX_REGIONSUBNAME_LEN+1]
double * y
char name[MAX_REGIONNAME_LEN+1]
char place[MAX_REGIONSUBNAME_LEN+1]
int xelRead(char *filename, DFT *dft)
Definition xeleris.c:14