This function reads simple data format (time + data columns), DFT format, PMOD format, Hammersmith formats (IDWC and IF), and some CSV formats.
420 {
421 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
422 if(fname==NULL || strlen(fname)<1 || d==NULL) {
425 }
426 if(verbose>1) printf("%s(%s)\n", __func__, fname);
428
429
431
432
433 FILE *fp;
434 fp=fopen(fname, "r");
435 if(fp==NULL) {
438 }
439
440
441 {
442 int n, binpart;
444 if(verbose>4) printf("file_size := %d\n", n);
445 if(n<2 || binpart!=0) {
446 if(verbose>0) {
447 printf("file_size := %d\n", n);
448 printf("binpart := %d\n", binpart);
449 fflush(stdout);
450 }
451 fclose(fp);
454 }
455 }
456
457
458 int ret;
460 rewind(fp);
462 fclose(fp);
464 if(verbose>20) {
465 printf("\n --- CSV contents ---\n");
467 fflush(stdout);
468 }
469
470
471 if(verbose>1) printf("checking for magic number\n");
472 if(strncasecmp(csv.
c[0].
content,
"DFT", 3)==0) {
474 }
else if(strncasecmp(csv.
c[0].
content,
"cpt", 3)==0) {
476 }
else if(csv.
nr>8 && strcasecmp(csv.
c[0].
content,
"time")==0 &&
477 strcasecmp(csv.
c[1].
content,
"prompt")==0 &&
478 strcasecmp(csv.
c[2].
content,
"delayed")==0 &&
479 strcasecmp(csv.
c[3].
content,
"p_rate")==0) {
481 }
else if(strncasecmp(csv.
c[0].
content,
"Time", 4)==0) {
483 }
else if(strncasecmp(csv.
c[0].
content,
"Start", 5)==0) {
485 }
else if(strncasecmp(csv.
c[0].
content,
"<?xml version", 6)==0) {
487 }
else if(csv.
nr>12 && strcasecmp(csv.
c[0].
content,
"directory")==0 &&
488 strcasecmp(csv.
c[1].
content,
"file name")==0 &&
489 strcasecmp(csv.
c[2].
content,
"num")==0 &&
490 strcasecmp(csv.
c[3].
content,
"slice")==0 &&
491 strcasecmp(csv.
c[4].
content,
"mean")==0 &&
492 strcasecmp(csv.
c[5].
content,
"sd")==0 &&
493 strcasecmp(csv.
c[6].
content,
"cov")==0 &&
494 strcasecmp(csv.
c[7].
content,
"max")==0 &&
495 strcasecmp(csv.
c[8].
content,
"min")==0 &&
496 strcasecmp(csv.
c[9].
content,
"pixel")==0 &&
497 strcasecmp(csv.
c[10].
content,
"total")==0 &&
498 strcasecmp(csv.
c[11].
content,
"group")==0) {
500 }
else if(csv.
nr>10 && strcasecmp(csv.
c[0].
content,
"PatientName")==0 &&
501 strcasecmp(csv.
c[2].
content,
"Patient MRN")==0 ) {
503 }
else if(csv.
nr>5 && strstr(csv.
c[0].
content,
" - Time")!=NULL &&
504 strstr(csv.
c[2].
content,
"(upper bound)")!=NULL &&
505 strstr(csv.
c[3].
content,
"(lower bound)")!=NULL &&
506 strstr(csv.
c[4].
content,
"(standard deviation)")!=NULL) {
508 }
else if(strcasecmp(csv.
c[0].
content,
"TAC")==0) {
512
513 }
else if(csv.
nr>4 && strcasecmp(csv.
c[0].
content,
"Singles")==0 &&
514 strcasecmp(csv.
c[1].
content,
"Randoms")==0 &&
515 strcasecmp(csv.
c[2].
content,
"Prompts")==0 &&
516 strncasecmp(csv.
c[3].
content,
"Time(ms)", 4)==0) {
518 }
else if(
csvCell(&csv, 1, 0) && strcasecmp(
csvCell(&csv, 1, 0),
"Num Voxels")==0 )
519 {
521 }
522
523
524
526 if(verbose>1) printf("checking file name extension\n");
527 char *cptr, *extension;
529 if(cptr!=NULL && strlen(cptr)>1) extension=
strdup(cptr+1);
530 else extension=
strdup(
"");
531 if(verbose>1) printf("extension := '%s'\n", extension);
532 cptr=extension;
533 if(strcasecmp(cptr, "IDWC")==0 || strcasecmp(cptr, "IDW")==0) {
535 } else if(strcasecmp(cptr, "IF")==0) {
537 } else if(strcasecmp(cptr, "XML")==0) {
539 } else if(strcasecmp(cptr, "HTML")==0 || strcasecmp(cptr, "HTM")==0) {
541 } else if(strcasecmp(cptr, "SIF")==0) {
543 } else if(strcasecmp(cptr, "HC")==0) {
545 } else if(strcasecmp(cptr, "R")==0) {
547 }
548 free(extension);
549 }
550
551
554 if(verbose>2) {printf("reading all data in IFT structure\n"); fflush(stdout);}
555 fp=fopen(fname, "r");
556 if(fp!=NULL) {
iftRead(&hdr, fp, 0, 1, status); fclose(fp);}
557 }
559
563 {
565
569 else
571 }
else if(
iftFindKey(&hdr,
"Discriminators", 0)>=0) {
573
576 }
577 }
578
579
581 if(verbose>2) printf("\nRegular CSV, therefore trying Mat file format\n");
582
583 int ok=1; char *c; int len;
584 for(
int r=1; r<csv.
row_nr; r++) {
585 c=
csvCell(&csv, r, 0);
if(c==NULL) {ok=0;
break;}
586 len=strlen(c); if(len<2) {ok=0; break;}
587 if(c[0]!='\'' || c[len-1]!='\'') {ok=0; break;}
588 }
590 }
591
592
594 if(verbose>10) {
595 printf("\n FORMAT NOT IDENTIFIED \n");
596 printf("\n --- CSV contents ---\n");
598 fflush(stdout);
599 }
600 }
601
602
604
605 if(verbose>1) {printf(
" file format: %s\n",
tacFormattxt(format)); fflush(stdout);}
606
607
608
609
610
611
612
613
614 switch(format) {
617 fp=fopen(fname, "r");
618 if(fp!=NULL) {
iftRead(&hdr, fp, 0, 2, status); fclose(fp);}
620 break;
623 fp=fopen(fname, "r");
624 if(fp!=NULL) {
iftRead(&hdr, fp, 0, 2, status); fclose(fp);}
626 break;
629 fp=fopen(fname, "r");
630 if(fp!=NULL) {
iftRead(&hdr, fp, 0, 2, status); fclose(fp);}
632 break;
635 break;
638 break;
640 ret=tacRead4DM(d, &csv, status);
641 break;
647 fp=fopen(fname, "r");
648 if(fp!=NULL) {
iftRead(&hdr, fp, 0, 2, status); fclose(fp);}
650 break;
653 break;
656 break;
659 fp=fopen(fname, "r");
660 if(fp!=NULL) {
iftRead(&hdr, fp, 0, 2, status); fclose(fp);}
662 break;
665 break;
668 break;
670
671
672
674 break;
677 break;
680 break;
683 break;
684 default:
685
686 if(verbose>0) printf(
"identified as %s file\n",
tacFormattxt(format));
688 statusSet(status, __func__, __FILE__, __LINE__, ret);
689 }
692
693
694 if(verbose>1) printf("checking studynr\n");
696 if(verbose>2) printf("studynr not found in %s\n", fname);
698
700 if(ret==0) {
701 if(verbose>2) printf("studynr based on filename: %s\n", studynr);
703 } else if(verbose>1)
704 fprintf(stderr, "Error: cannot get valid studynr from filename.\n");
705 }
706
707
708 if(verbose>1) printf("checking concentration units\n");
712 printf(
"concentration units based on filename := %s\n",
unitName(d->
cunit)); fflush(stdout);
713 }
714 }
715
718}
int csvIsRegular(CSV *csv)
char * csvCell(CSV *csv, int row, int col)
int csvWrite(CSV *csv, int regular, FILE *fp, TPCSTATUS *status)
int tacReadDFT(TAC *tac, CSV *csv, IFT *hdr, TPCSTATUS *status)
char * filenameGetExtension(const char *s)
Get the last extension of a file name.
int tacReadHRPLUSHC(TAC *tac, CSV *csv, TPCSTATUS *status)
int tacReadHRRTHC(TAC *tac, CSV *csv, TPCSTATUS *status)
int iftSearchValue(IFT *ift, const char *s, int start_index)
int iftFindPair(IFT *ift, const char *key, const char *value, int start_index)
int iftFindKey(IFT *ift, const char *key, int start_index)
int iftRead(IFT *ift, FILE *fp, int is_key_required, int is_comment_accepted, TPCSTATUS *status)
int tacReadMat(TAC *tac, CSV *csv, TPCSTATUS *status)
int tacReadPMOD(TAC *tac, CSV *csv, IFT *hdr, TPCSTATUS *status)
int tacReadQView(TAC *tac, CSV *csv, const int grouponly, TPCSTATUS *status)
int tacReadSIF(TAC *tac, CSV *csv, IFT *hdr, TPCSTATUS *status)
int tacReadSimple(TAC *tac, CSV *csv, IFT *hdr, TPCSTATUS *status)
char * strdup(const char *s)
IFT h
Optional (but often useful) header information.
int studynrFromFilename(const char *fname, char *studynr, int force)
int tacReadScanditronics(TAC *tac, IFT *hdr, TPCSTATUS *status)
int tacReadGEMS(TAC *tac, IFT *hdr, TPCSTATUS *status)
int tacReadAllogg(TAC *tac, IFT *hdr, TPCSTATUS *status)
int tacReadOldAllogg(TAC *tac, IFT *hdr, TPCSTATUS *status)
int tacReadInveonCSV(TAC *tac, CSV *csv, TPCSTATUS *status)
int tacReadCSV(TAC *tac, CSV *csv, IFT *hdr, TPCSTATUS *status)
int tacReadCarimasTxt(TAC *tac, CSV *csv, TPCSTATUS *status)
int tacGetHeaderStudynr(IFT *h, char *s, TPCSTATUS *status)
int tacSetHeaderStudynr(IFT *h, const char *s)
@ UNIT_UNKNOWN
Unknown unit.
int unitIdentifyFilename(const char *s)
char * unitName(int unit_code)
#define MAX_STUDYNR_LEN
Define max study number length.
@ TAC_FORMAT_ABSS_ALLOGG
ALLOGG ABSS data; reading supported.
@ TAC_FORMAT_MAT
Matlab matrix TAC format (reading supported)
@ TAC_FORMAT_ABSS_GEMS
GEMS ABSS data; reading supported.
@ TAC_FORMAT_CARIMAS_TXT
Carimas txt format (reading supported)
@ TAC_FORMAT_HRPLUS_HC
HR+ head curve format (reading supported)
@ TAC_FORMAT_HRRT_HC
HRRT head curve format (reading supported)