#include typedef struct { float Average; float StandardDeviation; float Max; float Min; } ChannelInfo; typedef struct { time_t Seconds; ChannelInfo data[12]; } ChannelData; TFile *tf = NULL; TNtuple *nt = NULL; int CreateNtuple(int Create) { char *names="Time:CH0AVG:CH0STD:CH0MAX:CH0MIN:CH1AVG:CH1STD:CH1MAX:CH1MIN:CH2AVG:CH2STD:CH2MAX:CH2MIN:CH3AVG:CH3STD:CH3MAX:CH3MIN:CH4AVG:CH4STD:CH4MAX:CH4MIN:CH5AVG:CH5STD:CH5MAX:CH5MIN:CH6AVG:CH6STD:CH6MAX:CH6MIN:CH7AVG:CH7STD:CH7MAX:CH7MIN:CH8AVG:CH8STD:CH8MAX:CH8MIN:CH9AVG:CH9STD:CH9MAX:CH9MIN:CH10AVG:CH10STD:CH10MAX:CH10MIN:CH11AVG:CH11STD:CH11MAX:CH11MIN:CH12AVG:CH12STD:CH12MAX:CH12MIN"; if (Create!=0) { printf("Open New NTUPLE\n"); tf = new TFile("wind.root", "RECREATE","Abbey power analysis"); nt = new TNtuple("WIND","general",names); } else { printf("Open existing NTUPLE\n"); tf = new TFile("wind.root", "UPDATE"); } return 0; } int GetString(char *p, char *tofill, int maxfill) { const char value[32]; /* * Start where the pointer is and * find the tab, return the string. */ memset(tofill, 0, maxfill); //printf("GetString %s\n", p); for(int i=0;i1)) { return i; } else { tofill[i] = p[i]; } } } unsigned int ConvertToSeconds(const char *date) { unsigned int rc; struct tm then; char val[8], *p; p = (char *) date; memset(val,0, sizeof(val)); strncpy(val, p, 2); then.tm_mon = atoi(val) - 1; p+=3; memset(val,0, sizeof(val)); strncpy(val, p, 2); then.tm_mday = atoi(val); p +=3; memset(val,0, sizeof(val)); strncpy(val, p, 4); then.tm_year = atoi(val)-1900; p +=5; memset(val,0, sizeof(val)); strncpy(val, p, 2); then.tm_hour = atoi(val); p +=3; memset(val,0, sizeof(val)); strncpy(val, p, 2); then.tm_min = atoi(val); p +=3; memset(val,0, sizeof(val)); strncpy(val, p, 2); then.tm_sec = atoi(val); p +=3; rc = mktime(&then); return rc; } ChannelData *ParseLogLine(const char *Line) { char *p, temp[32]; int i; unsigned n; static ChannelData cd; // printf("Line to parse %s\n", Line); p = (char *) Line; /* * First 18 bytes are the date. */ memset( temp, 0, sizeof(temp)); strncpy( temp, p, 18); p += 19; cd.Seconds = ConvertToSeconds(temp); // printf("Seconds Conversion: %s\n", ctime(&cd.Seconds)); for (i=0;i<12;i++) { memset(cd.data[i], 0, sizeof(ChannelInfo)); n = GetString( p, temp, sizeof(temp)); // printf(" %d %d \n", i, n); if (n>2) { cd.data[i].Average = atof(temp); } p += n; n = GetString( p, temp, sizeof(temp)); if (n>2) { cd.data[i].StandardDeviation = atof(temp); } p += n; n = GetString( p, temp, sizeof(temp)); if (n>2) { cd.data[i].Max = atof(p); } p += n; n = GetString( p, temp, sizeof(temp)); if (n>2) { cd.data[i].Min = atof(p); } p+=n; } //printf("Data Parsed!!\n"); //DumpData(&cd); return &cd; } void DumpData(ChannelData *cd) { int i; printf("Date: %s\n", ctime(&cd->Seconds)); for (i=0;i<12;i++) { printf("%d %f %f %f %f\n", i, cd->data[i].Average, cd->data[i].StandardDeviation, cd->data[i].Max, cd->data[i].Min); } } int ReadLogger( const char *filename, int Create) { char line[2048]; int LineCount = 0; Float_t x[50]; ChannelData *cd; int i, j; printf("Open file: %s\n", filename); FILE *fd = fopen(filename, "r"); if (fd != NULL) { printf("File Open\n"); CreateNtuple(Create); while (!feof(fd)) // && LineCount < 2) { memset(line, 0, sizeof(line)); fgets(line, sizeof(line), fd); // Skip everything that doesn't have a leading digit. if (isdigit(line[0])) { cd = ParseLogLine(line); x[0] = cd->Seconds; for (i=0;i<12;i++) { j = i * 4; x[j+1] = cd->data[i].Average; x[j+2] = cd->data[i].StandardDeviation; x[j+3] = cd->data[i].Max; x[j+4] = cd->data[i].Min; } if (Create!=0) { nt->Fill(x); } else { //WIND->Fill(x); } LineCount++; } } fclose(fd); // Save all objects in this file tf->Write(); // Close the file. Note that this is automatically done when you leave // the application. tf->Close(); printf("Conversion complete\n"); } }