#include "get_tac_akc.h" /* C source code name: get_tac_akc.c */ /* edit, e.g., with emacs. compile with Makefile */ /* By: Alexander K. Converse, University of Wisconsin-Madison */ /* Created: 21 Aug 2012 */ /* Modified: 26 March 2014 */ /* Purpose: get ASIPro TAC */ // Note: for this to extract the correct mean activity levels, the mean values must be located under the name // of the corresponding ROI void get_tac_akc(struct TAC_t *p, struct ROI *iROI, int index) { FILE *fp_in; char line[MAXLEN]; char *ROI; char *tok; char inTacsFile; int i, j, found, column, tokenNum; double mean; strtok(p->inTacsFile,"\r\n"); /* If file opens print should return a number not 0 */ fp_in = fopen(p->inTacsFile,"r"); if (fp_in == NULL) { printf("Error: Failed to open file - %s\n", p->inTacsFile); return; } /* read header line 1, File Path */ fgets(line,MAXLEN,fp_in); /* read header line 2, descriptors */ fgets(line,MAXLEN,fp_in); /* find column for ith ROI as passed from ROIs[index]*/ // Value of index is the ith iteration through the loop in McKay_akc.c ROI = strtok(p->ROIs[index], "\r\n"); found = 1; tok = strtok(line,","); /* NOTE: Ensure max i value is greater than number of columns in inTacsFile */ // Look through the second header line for the name of the ith ROI // This will determine which column all of the ROI data is in for (i=0; i<100 && found != 0; i++){ found = strncmp(tok,ROI,strcspn(ROI,"\n")); if (found == 0) { // Store which column this ROI info is located in column = i; } tok = strtok(NULL,","); } fclose(fp_in); /* Re-open file to prepare for extracting ROI data */ fp_in = fopen(p->inTacsFile, "r"); if (fp_in == NULL) { printf("Error: Failed to open file - %s\n", p->inTacsFile); return; } /* read header line 1 */ fgets(line, MAXLEN, fp_in); /* read header line 2 */ fgets(line, MAXLEN, fp_in); /* read header line 3 */ fgets(line, MAXLEN, fp_in); /* read data and write to ROI[index] structure*/ // Time written to the time[] array of the ROI structure // Mean activity data written to actualObserved array tokenNum = 0; j = 0; /*read input line */ while (fgets(line, MAXLEN, fp_in) != NULL) { /*Tokenize based on , */ tok = strtok(line, ","); /* Process one line */ while (tok != NULL && tokenNum <= column) { /* Mean is in (column - 1) token */ if (j != 0 && tokenNum == column) { mean = atof(tok); iROI->actualObserved[j] = mean; j = j + 1; } else if (j == 0 && (tokenNum == (column - 1))) { mean = atof(tok); iROI->actualObserved[j] = mean; j = j + 1; tokenNum = tokenNum + 1; } /* Increment token number when haven't found ROI column */ tokenNum = tokenNum + 1; tok = strtok(NULL, ","); } tokenNum = 1; } for (i = 0; i < p->nFrames; ++i) { iROI->time[i] = p->inFileTime[i]; } fclose(fp_in); }