143 {
144 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
145 if(verbose>0) {printf("%s(tac, csv, hdr, status)\n", __func__); fflush(stdout);}
146
147
148
149 if(tac==NULL) {
152 }
157 }
158
159
160 if(verbose>2) {printf(" checking that CSV contains SIF\n"); fflush(stdout);}
161 int title_item_nr;
163 if(title_item_nr==1 && csv->
separator!=
' ') {
164 if(verbose>1) printf("title_item_nr := %d\n", title_item_nr);
165 if(verbose>2) {printf(" SIF has not space character as column separator; fixing title line\n");}
166
167 char s1[128]; int n=0;
169 if(!(len>0)) {
172 }
173 n++;
174 char s[128];
176 n++;
178 }
181 int j=1;
182 for(
int i=1+csv->
nr-n; i<csv->nr; i++) {
183
184 csv->
c[i].
row=0; csv->
c[i].
col=j; j++;
185 }
189
190 }
191
192 if(csv->
row_nr<2 || title_item_nr<5 ) {
193 if(verbose>1) {printf(
"title_item_nr := %d\n", title_item_nr);
csvList(csv, stdout);}
196 }
197
198 int ret;
199
200
201 if(verbose>2) {printf(" allocating memory\n"); fflush(stdout);}
203 statusSet(status, __func__, __FILE__, __LINE__, ret);
205
208
213
214
215 strcpy(tac->
c[0].
name,
"Prompts");
216 strcpy(tac->
c[1].
name,
"Randoms");
217 strcpy(tac->
c[2].
name,
"Trues");
218
219
220 if(verbose>2) {printf(" reading SIF header\n"); fflush(stdout);}
221
222 char sif_scan_start_time[20];
223 ret=0;
225 char temp[20];
226 strcpy(temp, csv->
c[0].
content); strcat(temp,
" ");
228 if(verbose>4) printf(" datetime := '%s'\n", temp);
230 if(ret!=0) {
231 if(verbose>1) printf(" invalid SIF date/time (%d).\n", ret);
232 else if(verbose>0) printf(" invalid SIF date/time.\n");
233 if(ret<0) ret=0;
234 }
235 } else ret=1;
236 if(ret!=0) {
237 if(verbose>2) {
238 printf(
" cell0 := '%s'\n", csv->
c[0].
content);
239 printf(
" cell1 := '%s'\n", csv->
c[1].
content);
240 }
244 }
245 if(verbose>1) printf("sif_scan_start_time := %s\n", sif_scan_start_time);
246
247 int frameNr;
249 if(verbose>1) printf("sif_frame_nr := %d\n", frameNr);
250 if(frameNr<1 || frameNr>tac->
_sampleNr) {
254 }
256
257 int colNr;
259 if(verbose>1) printf("sif_col_nr := %d\n", colNr);
260 if(colNr<2) {
264 }
265
266
268 if(title_item_nr>5) {
270 if(strcmp(studynr, ".")==0) strcpy(studynr, "");
271 if(verbose>2) printf("sif_studynr := %s\n", studynr);
272 }
273
275 if(title_item_nr>6) {
276 int isocode;
279 }
280 if(verbose>1) printf(
"sif_isotope := %s\n",
isotope);
281
282
283 if(verbose>2) {printf(" reading SIF frames\n"); fflush(stdout);}
284 ret=0;
285 int fi, ri, ci;
286 double v;
288 ri=fi+1;
289
291 if(isnan(v)) {ret++;
break;}
else tac->
x1[fi]=v;
292
294 if(isnan(v)) {ret++;
break;}
else tac->
x2[fi]=v;
295 tac->
x[fi]=0.5*(tac->
x1[fi]+tac->
x2[fi]);
296
300 if(colNr<3) continue;
301
303 if(isnan(v)) {ret++;
break;}
else tac->
c[0].
y[fi]=v;
304 if(colNr<4) continue;
305
307 if(isnan(v)) {ret++;
break;}
else tac->
c[1].
y[fi]=v;
308
309 if(colNr<5) {
310 tac->
c[2].
y[fi]=tac->
c[0].
y[fi]-tac->
c[1].
y[fi];
311 continue;
312 }
313
315 if(isnan(v)) {ret++;
break;}
else tac->
c[2].
y[fi]=v;
316 }
317 if(ret!=0) {
321 }
322
323
324
326
328
330 }
332
333 if(!studynr[0] && hdr!=NULL) {
334
336
338 if(verbose>2) printf("sifhdr_studynr := %s\n", studynr);
340 }
341 }
342 if(studynr[0]) {
343 if(verbose>3) printf("setting TAC studynr to '%s'\n", studynr);
345 }
346
348
350
352 }
355
356 if(verbose>4) {printf(" %s() out\n", __func__); fflush(stdout);}
359}
char * csvCell(CSV *csv, int row, int col)
int csvPutString(CSV *csv, const char *s, int newline)
int csvReorg(CSV *d, TPCSTATUS *status)
int csvRowLength(CSV *csv, int row)
int csvList(CSV *csv, FILE *fp)
int strDateTimeValid(const char *str, char *intdate)
double atofVerified(const char *s)
char * isotopeName(int isotope_code)
int isotopeIdentify(const char *isotope)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
int strTokenNCpy(const char *s1, const char *s2, int i, char *s3, int count)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
char name[MAX_TACNAME_LEN+1]
IFT h
Optional (but often useful) header information.
int verbose
Verbose level, used by statusPrint() etc.
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
int tacSetHeaderScanstarttime(IFT *h, const char *s)
int tacGetHeaderScanstarttime(IFT *h, char *s, TPCSTATUS *status)
int tacGetHeaderStudynr(IFT *h, char *s, TPCSTATUS *status)
int tacSetHeaderIsotope(IFT *h, const char *s)
int tacGetHeaderIsotope(IFT *h, char *s, TPCSTATUS *status)
int tacSetHeaderStudynr(IFT *h, const char *s)
@ TPCERROR_INVALID_VALUE
Invalid value.
@ TPCERROR_FAIL
General error.
@ TPCERROR_INVALID_FORMAT
Invalid file format.
@ TPCERROR_NO_DATA
File contains no data.
#define MAX_STUDYNR_LEN
Define max study number length.
#define MAX_ISOTOPE_LEN
Max string length for PET isotope.
@ TAC_FORMAT_SIF
Scan information file.