void checkStatus(ifstream &fin) { ios::iostate i; i = fin.rdstate(); if(i & ios::eofbit) cout << endl << "EOF encountered \n"; else if(i & ios::failbit) cout << "Non-fatal I/O error \n"; else if(i & ios::badbit) cout << "Fatal I/O error \n"; }
/** * Constructor responsible for reading data from the EDF file. * It reads data from the header and stores key-value pairs in dictionry. * Also EDF image is read. */ edf_reader::edf_reader(ifstream &in){ char buffer[256], value_string[256]; double value; char a = ' '; bool is_header = 0; int dim1, dim2; // //read first character from the file // in.get(a); // // read file until bace closing the header is met // while(in.peek()!='}'){ // //prevention from corrupted bits in file // if(in.fail()){ in.clear(in.rdstate() & ~ios::failbit); in.getline(buffer, 255); break; } // //check if the header begins // if((a=='{') || is_header==1){ // //set flag if first time in the loop // if(!is_header){ in.get(a); is_header = 1; } // //get key // in.getline(buffer, 255,' '); string key(buffer); // //check if key corresponds to float value // if(!strcmp(buffer,"Center_1")||!strcmp(buffer,"Center_2")||!strcmp(buffer,"DDummy")||!strcmp(buffer,"Dummy")||!strcmp(buffer,"Offset_2")||!strcmp(buffer,"Psize_1")||!strcmp(buffer,"Psize_2")||!strcmp(buffer,"SampleDistance")||!strcmp(buffer,"SaxsDataVersion")||!strcmp(buffer,"WaveLength")||!strcmp(buffer,"EDF_BinarySize")||!strcmp(buffer,"Image")||!strcmp(buffer, "Offset_1")) { // //get value corresponding to key // in.getline(buffer, 255, '='); while(in.peek()==' ')in.ignore(1,'\n'); in >> value; // //store pairs key-double value in key_double dictionary // key_double.insert(pair<string, double>(key, value)); } // //get dimension separately and store in dictionary // else if(!strcmp(buffer,"Dim_1")){ in.getline(buffer, 255, '='); while(in.peek()==' ')in.ignore(1,'\n'); in >> value; dim1 = (int)value; (void)dim1; // TODO unused varable - quiet warnings key_double.insert(pair<string, double>(key, value)); }