file name with frame index and detector index

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@303 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2012-10-18 09:59:18 +00:00
parent a05631f2c3
commit f2be1d5fd9

View File

@ -36,34 +36,67 @@ class fileIOStatic {
/** generates file name without extension /** generates file name without extension
always appends to file path and file name the run index. always appends to file path and file name the run index.
in case also appends the position index and the two level of scan varaibles with the specified precision in case also appends the position index and the two level of scan varaibles with the specified precision
Filenames will be of the form: filepath/filename(_Sy_sw_px)_i Filenames will be of the form: filepath/(dz_)filename(_Sy_sw_px_fv)_i
where y is the scan0 variable, W is the scan 1 variable, x is the position index and i is the run index where z is the detector index, y is the scan0 variable, W is the scan 1 variable, x is the position index, v is the frame index and i is the run index
\param filepath outdir \param filepath outdir
\param filename file root name \param filename file root name
\param aMask action mask (scans, positions) \param aMask action mask (scans, positions)
\param sv0 scan variable 0 \param sv0 scan variable 0
\param prec0 scan precision 0 \param prec0 scan precision 0
\param sv1 scan variable 1 \param sv1 scan variable 1
\param prec1 scan precision 1 \param prec1 scan precision 1
\param pindex position index \param pindex position index
\param number of positions \param npos number of positions
\param findex file index \param findex file index
\returns file name without extension \param frameindex frame index
\param detindex detector id
\returns file name without extension
*/ */
static string createFileName(char *filepath, char *filename, int aMask, double sv0, int prec0, double sv1, int prec1, int pindex, int npos, int findex){ \ static string createFileName(char *filepath, char *filename, int aMask, double sv0, int prec0, double sv1, int prec1, int pindex, int npos, int findex, int frameindex=-1, int detindex=-1){ \
ostringstream osfn; \ ostringstream osfn; \
osfn << filepath << "/" << filename; \ osfn << filepath << "/" << filename; \
if(detindex!=-1) osfn << "_d"<< detindex; \
if ( aMask& (1 << (slsDetectorDefs::MAX_ACTIONS))) osfn << "_S" << fixed << setprecision(prec0) << sv0; \ if ( aMask& (1 << (slsDetectorDefs::MAX_ACTIONS))) osfn << "_S" << fixed << setprecision(prec0) << sv0; \
if (aMask & (1 << (slsDetectorDefs::MAX_ACTIONS+1))) osfn << "_s" << fixed << setprecision(prec1) << sv1; \ if (aMask & (1 << (slsDetectorDefs::MAX_ACTIONS+1))) osfn << "_s" << fixed << setprecision(prec1) << sv1; \
if (pindex>0 && pindex<=npos) osfn << "_p" << pindex; \ if (pindex>0 && pindex<=npos) osfn << "_p" << pindex; \
if(frameindex!=-1) osfn << "_f" << frameindex; \
osfn << "_" << findex; \ osfn << "_" << findex; \
return osfn.str(); \ return osfn.str(); \
}; };
/** generates file prefix for receivers without file path, frame index, file index or extension
in case also appends the position index and the two level of scan varaibles with the specified precision
File prefix will be of the form: (dz_)filename(_Sy_sw_px_)
where z is the detector index, y is the scan0 variable, W is the scan 1 variable and x is the position index
\param filename file root name
\param aMask action mask (scans, positions)
\param sv0 scan variable 0
\param prec0 scan precision 0
\param sv1 scan variable 1
\param prec1 scan precision 1
\param pindex position index
\param npos number of positions
\param detindex detector id
\returns file name without extension
*/
static string createReceiverFilePrefix(char *filename, int aMask, double sv0, int prec0, double sv1, int prec1, int pindex, int npos,int detindex=-1){ \
ostringstream osfn; \
osfn << filename; \
if(detindex!=-1) osfn << "_d"<< detindex; \
if ( aMask& (1 << (slsDetectorDefs::MAX_ACTIONS))) osfn << "_S" << fixed << setprecision(prec0) << sv0; \
if (aMask & (1 << (slsDetectorDefs::MAX_ACTIONS+1))) osfn << "_s" << fixed << setprecision(prec1) << sv1; \
if (pindex>0 && pindex<=npos) osfn << "_p" << pindex; \
return osfn.str(); \
};
/** static function that returns the file index from the file name /** static function that returns the file index from the file name
\param fname file name \param fname file name
\returns file index \returns file index
@ -107,6 +140,8 @@ class fileIOStatic {
} \ } \
else cout << "******************************** cannot parse file index" << endl; \ else cout << "******************************** cannot parse file index" << endl; \
uscore=s.rfind("_"); \ uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"f%d",&i)) \
s=fname.substr(0,uscore); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"p%d",&i)) { \ if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"p%d",&i)) { \
p_index=i; \ p_index=i; \
s=fname.substr(0,uscore); \ s=fname.substr(0,uscore); \
@ -127,359 +162,445 @@ class fileIOStatic {
}; };
/** static function that returns the variables from the file name
\param fname file name
\param index reference to index
\param f_index reference to frame index
\param p_index reference to position index
\param sv0 reference to scan variable 0
\param sv1 reference to scan variable 1
\param detindex reference to detector id
\returns file index
*/
static int getVariablesFromFileName(string fname, int &index, int &f_index, int &p_index, double &sv0, double &sv1, int &detindex) { \
int i; \
double f; \
string s; \
index=-1; \
p_index=-1; \
sv0=-1; \
sv1=-1; \
size_t uscore=fname.rfind("_"); \
if (uscore==string::npos) return -1; \
s=fname; \
if (sscanf(s.substr(uscore+1,s.size()-uscore-1).c_str(),"%d",&i)) { \
index=i; \
s=fname.substr(0,uscore); \
} \
else cout << "******************************** cannot parse file index" << endl; \
uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"f%d",&i)) { \
f_index=i; \
s=fname.substr(0,uscore); \
} \
else cout << "******************************** cannot parse frame index" << endl; \
uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"p%d",&i)) { \
p_index=i; \
s=fname.substr(0,uscore); \
} \
else cout << "******************************** cannot parse position index" << endl; \
uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"s%lf",&f)) { \
sv1=f; \
s=fname.substr(0,uscore); \
} \
else cout << "******************************** cannot parse scan varable 1" << endl; \
uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"S%lf",&f)) { \
sv0=f; \
s=fname.substr(0,uscore); \
} \
else cout << "******************************** cannot parse scan varable 0" << endl; \
uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"d%d",&i)) { \
detindex=i; \
} \
else cout << "******************************** cannot parse detector id" << endl; \
return index; \
};
/** static function that returns the name variable from the receiver complete file name prefix
\param fname complete file name prefix
\returns file name
*/
static string getNameFromReceiverFilePrefix(string fname) { \
int i; \
double f; \
string s; \
s=fname; \
size_t uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"p%d",&i)) \
s=fname.substr(0,uscore); \
uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"s%lf",&f)) \
s=fname.substr(0,uscore); \
uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"S%lf",&f)) \
s=fname.substr(0,uscore); \
uscore=s.rfind("_"); \
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"d%d",&i)) \
s=fname.substr(0,uscore); \
return s; \
};
/** /**
writes a data file
\param fname of the file to be written
\param nch number of channels to be written
\param data array of data values
\param err array of arrors on the data. If NULL no errors will be written
\param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err)
\param dataformat format of the data: can be 'i' integer or 'f' double
\returns OK or FAIL if it could not write the file or data=NULL
*/
static int writeDataFile(string fname, int nch, double *data, double *err=NULL, double *ang=NULL, char dataformat='f'){ \
ofstream outfile; \
if (data==NULL) { \
cout << "No data to write!" << endl; \
return slsDetectorDefs::FAIL; \
} \
outfile.open (fname.c_str(),ios_base::out); \
if (outfile.is_open()) { \
writeDataFile(outfile, nch, data, err, ang, dataformat, 0); \
outfile.close(); \
return slsDetectorDefs::OK; \
} else { \
std::cout<< "Could not open file " << fname << "for writing"<< std::endl; \
return slsDetectorDefs::FAIL; \
} \
};
/**
writes a data file writes a data file
\param fname of the file to be written \param outfile output file stream
\param nch number of channels to be written \param nch number of channels to be written
\param data array of data values \param data array of data values
\param err array of arrors on the data. If NULL no errors will be written \param err array of arrors on the data. If NULL no errors will be written
\param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err)
\param dataformat format of the data: can be 'i' integer or 'f' double (default) \param dataformat format of the data: can be 'i' integer or 'f' double (default)
\returns OK or FAIL if it could not write the file or data=NULL
*/
static int writeDataFile(string fname, int nch, double *data, double *err=NULL, double *ang=NULL, char dataformat='f'){ \
ofstream outfile; \
if (data==NULL) { \
cout << "No data to write!" << endl; \
return slsDetectorDefs::FAIL; \
} \
outfile.open (fname.c_str(),ios_base::out); \
if (outfile.is_open()) { \
writeDataFile(outfile, nch, data, err, ang, dataformat, 0); \
outfile.close(); \
return slsDetectorDefs::OK; \
} else { \
std::cout<< "Could not open file " << fname << "for writing"<< std::endl; \
return slsDetectorDefs::FAIL; \
} \
};
/**
writes a data file
\param outfile output file stream
\param nch number of channels to be written
\param data array of data values
\param err array of arrors on the data. If NULL no errors will be written
\param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err)
\param dataformat format of the data: can be 'i' integer or 'f' double (default)
\param offset start channel number
\returns OK or FAIL if it could not write the file or data=NULL
*/
static int writeDataFile(ofstream &outfile, int nch, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int offset=0){ \
int idata; \
if (data==NULL) { \
cout << "No data to write!" << endl; \
return slsDetectorDefs::FAIL; \
} \
for (int ichan=0; ichan<nch; ichan++) { \
if (ang==NULL) { \
outfile << ichan+offset << " "; \
} else { \
outfile << ang[ichan] << " "; \
} \
switch (dataformat) { \
case 'f': \
outfile << *(data+ichan)<< " "; \
break; \
case 'i': \
default: \
idata=(int)(*(data+ichan)); \
outfile << idata << " "; \
} \
if (err) { \
outfile << *(err+ichan)<< " "; \
} \
outfile << std::endl; \
} \
return slsDetectorDefs::OK; \
};
/**
writes a raw data file
\param fname of the file to be written
\param nch number of channels
\param data array of data values
\returns OK or FAIL if it could not write the file or data=NULL
*/
static int writeDataFile(string fname,int nch, int *data){ \
ofstream outfile; \
if (data==NULL) return slsDetectorDefs::FAIL; \
outfile.open (fname.c_str(),ios_base::out); \
if (outfile.is_open()) { \
writeDataFile(outfile, nch, data, 0); \
outfile.close(); \
return slsDetectorDefs::OK; \
} else { \
std::cout<< "Could not open file " << fname << "for writing"<< std::endl; \
return slsDetectorDefs::FAIL; \
} \
};
/**
writes a raw data file
\param outfile output file stream
\param nch number of channels
\param data array of data values
\param offset start channel number \param offset start channel number
\returns OK or FAIL if it could not write the file or data=NULL \returns OK or FAIL if it could not write the file or data=NULL
*/ */
static int writeDataFile(ofstream &outfile,int nch, int *data, int offset=0){ \ static int writeDataFile(ofstream &outfile, int nch, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int offset=0){ \
if (data==NULL) return slsDetectorDefs::FAIL; \ int idata; \
for (int ichan=0; ichan<nch; ichan++) outfile << ichan+offset << " " << *(data+ichan) << std::endl; \ if (data==NULL) { \
return slsDetectorDefs::OK; \ cout << "No data to write!" << endl; \
}; return slsDetectorDefs::FAIL; \
} \
for (int ichan=0; ichan<nch; ichan++) { \
if (ang==NULL) { \
outfile << ichan+offset << " "; \
} else { \
outfile << ang[ichan] << " "; \
} \
switch (dataformat) { \
case 'f': \
outfile << *(data+ichan)<< " "; \
break; \
case 'i': \
default: \
idata=(int)(*(data+ichan)); \
outfile << idata << " "; \
} \
if (err) { \
outfile << *(err+ichan)<< " "; \
} \
outfile << std::endl; \
} \
return slsDetectorDefs::OK; \
};
/**
writes a raw data file
\param fname of the file to be written
\param nch number of channels
\param data array of data values
\returns OK or FAIL if it could not write the file or data=NULL
*/
static int writeDataFile(string fname,int nch, int *data){ \
ofstream outfile; \
if (data==NULL) return slsDetectorDefs::FAIL; \
outfile.open (fname.c_str(),ios_base::out); \
if (outfile.is_open()) { \
writeDataFile(outfile, nch, data, 0); \
outfile.close(); \
return slsDetectorDefs::OK; \
} else { \
std::cout<< "Could not open file " << fname << "for writing"<< std::endl; \
return slsDetectorDefs::FAIL; \
} \
};
/**
writes a raw data file
\param outfile output file stream
\param nch number of channels
\param data array of data values
\param offset start channel number
\returns OK or FAIL if it could not write the file or data=NULL
*/
static int writeDataFile(ofstream &outfile,int nch, int *data, int offset=0){ \
if (data==NULL) return slsDetectorDefs::FAIL; \
for (int ichan=0; ichan<nch; ichan++) outfile << ichan+offset << " " << *(data+ichan) << std::endl; \
return slsDetectorDefs::OK; \
};
/** /**
writes a short int raw data file writes a short int raw data file
\param fname of the file to be written \param fname of the file to be written
\param nch number of channels \param nch number of channels
\param data array of data values \param data array of data values
\returns OK or FAIL if it could not write the file or data=NULL \returns OK or FAIL if it could not write the file or data=NULL
*/ */
static int writeDataFile(string fname,int nch, short int *data) { \ static int writeDataFile(string fname,int nch, short int *data) { \
ofstream outfile; \ ofstream outfile; \
if (data==NULL) return slsDetectorDefs::FAIL; \ if (data==NULL) return slsDetectorDefs::FAIL; \
outfile.open (fname.c_str(),ios_base::out); \ outfile.open (fname.c_str(),ios_base::out); \
if (outfile.is_open()) { \ if (outfile.is_open()) { \
writeDataFile(outfile, nch, data, 0); \ writeDataFile(outfile, nch, data, 0); \
outfile.close(); \ outfile.close(); \
return slsDetectorDefs::OK; \ return slsDetectorDefs::OK; \
} else { \ } else { \
std::cout<< "Could not open file " << fname << "for writing"<< std::endl; \ std::cout<< "Could not open file " << fname << "for writing"<< std::endl; \
return slsDetectorDefs::FAIL; \ return slsDetectorDefs::FAIL; \
} \ } \
}; };
/** /**
writes a short int raw data file writes a short int raw data file
\param outfile output file stream \param outfile output file stream
\param nch number of channels \param nch number of channels
\param data array of data values \param data array of data values
\param offset start channel number \param offset start channel number
\returns OK or FAIL if it could not write the file or data=NULL \returns OK or FAIL if it could not write the file or data=NULL
*/ */
static int writeDataFile(ofstream &outfile,int nch, short int *data, int offset=0){ \ static int writeDataFile(ofstream &outfile,int nch, short int *data, int offset=0){ \
if (data==NULL) return slsDetectorDefs::FAIL; \ if (data==NULL) return slsDetectorDefs::FAIL; \
for (int ichan=0; ichan<nch; ichan++) outfile << ichan+offset << " " << *(data+ichan) << std::endl; \ for (int ichan=0; ichan<nch; ichan++) outfile << ichan+offset << " " << *(data+ichan) << std::endl; \
return slsDetectorDefs::OK; \ return slsDetectorDefs::OK; \
}; };
/** /**
reads a data file reads a data file
\param nch number of channels \param nch number of channels
\param fname of the file to be read \param fname of the file to be read
\param data array of data values to be filled \param data array of data values to be filled
\param err array of arrors on the data. If NULL no errors are expected on the file \param err array of arrors on the data. If NULL no errors are expected on the file
\param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err)
\param dataformat format of the data: can be 'i' integer or 'f' double (default) \param dataformat format of the data: can be 'i' integer or 'f' double (default)
\returns number of channels read or -1 if it could not read the file or data=NULL \returns number of channels read or -1 if it could not read the file or data=NULL
*/ */
static int readDataFile(int nch, string fname, double *data, double *err=NULL, double *ang=NULL, char dataformat='f') { \ static int readDataFile(int nch, string fname, double *data, double *err=NULL, double *ang=NULL, char dataformat='f') { \
ifstream infile; \ ifstream infile; \
int iline=0; \ int iline=0; \
int maxchans; \ int maxchans; \
string str; \ string str; \
maxchans=nch; \ maxchans=nch; \
infile.open(fname.c_str(), ios_base::in); \ infile.open(fname.c_str(), ios_base::in); \
if (infile.is_open()) { \ if (infile.is_open()) { \
iline=readDataFile(nch, infile, data, err, ang, dataformat, 0); \ iline=readDataFile(nch, infile, data, err, ang, dataformat, 0); \
infile.close(); \ infile.close(); \
} else { \ } else { \
std::cout<< "Could not read file " << fname << std::endl; \ std::cout<< "Could not read file " << fname << std::endl; \
return -1; \ return -1; \
} \ } \
return iline; \ return iline; \
}; };
/** /**
reads a data file reads a data file
\param nch number of channels \param nch number of channels
\param infile input file stream \param infile input file stream
\param data array of data values to be filled \param data array of data values to be filled
\param err array of arrors on the data. If NULL no errors are expected on the file \param err array of arrors on the data. If NULL no errors are expected on the file
\param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err)
\param dataformat format of the data: can be 'i' integer or 'f' double (default) \param dataformat format of the data: can be 'i' integer or 'f' double (default)
\param offset start channel number \param offset start channel number
\returns number of channels read or -1 if it could not read the file or data=NULL \returns number of channels read or -1 if it could not read the file or data=NULL
*/ */
static int readDataFile(int nch, ifstream &infile, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int offset=0){ \ static int readDataFile(int nch, ifstream &infile, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int offset=0){ \
int ichan,iline=0; \ int ichan,iline=0; \
int interrupt=0; \ int interrupt=0; \
double fdata, ferr, fang; \ double fdata, ferr, fang; \
int maxchans; \ int maxchans; \
int ich; \ int ich; \
string str; \ string str; \
maxchans=nch; \ maxchans=nch; \
while (infile.good() and interrupt==0) { \ while (infile.good() and interrupt==0) { \
getline(infile,str); \ getline(infile,str); \
istringstream ssstr(str); \ istringstream ssstr(str); \
if (ang==NULL) { \ if (ang==NULL) { \
ssstr >> ichan >> fdata; \ ssstr >> ichan >> fdata; \
if (ssstr.fail() || ssstr.bad()) { \ if (ssstr.fail() || ssstr.bad()) { \
interrupt=1; \ interrupt=1; \
break; \ break; \
} \ } \
ich=iline; \ ich=iline; \
if (ichan<offset) \ if (ichan<offset) \
continue; \ continue; \
} else { \ } else { \
ssstr >> fang >> fdata; \ ssstr >> fang >> fdata; \
ich=iline; \ ich=iline; \
} \ } \
if (ssstr.fail() || ssstr.bad()) { \ if (ssstr.fail() || ssstr.bad()) { \
interrupt=1; \ interrupt=1; \
break; \ break; \
} \ } \
if (err) \ if (err) \
ssstr >> ferr; \ ssstr >> ferr; \
if (ssstr.fail() || ssstr.bad()) { \ if (ssstr.fail() || ssstr.bad()) { \
interrupt=1; \ interrupt=1; \
break; \ break; \
} \ } \
if (ich<maxchans) { \ if (ich<maxchans) { \
if (ang) { \ if (ang) { \
ang[ich]=fang; \ ang[ich]=fang; \
} \ } \
data[ich]=fdata; \ data[ich]=fdata; \
if (err) \ if (err) \
err[ich]=ferr; \ err[ich]=ferr; \
iline++; \ iline++; \
} \ } \
if (iline>=nch) { \ if (iline>=nch) { \
interrupt=1; \ interrupt=1; \
break; \ break; \
} \ } \
} \ } \
return iline; \ return iline; \
}; };
/** /**
reads a raw data file reads a raw data file
\param fname of the file to be read \param fname of the file to be read
\param data array of data values \param data array of data values
\param nch number of channels \param nch number of channels
\returns OK or FAIL if it could not read the file or data=NULL \returns OK or FAIL if it could not read the file or data=NULL
*/ */
static int readDataFile(string fname, int *data, int nch) { \ static int readDataFile(string fname, int *data, int nch) { \
ifstream infile; \ ifstream infile; \
int iline=0; \ int iline=0; \
string str; \ string str; \
infile.open(fname.c_str(), ios_base::in); \ infile.open(fname.c_str(), ios_base::in); \
if (infile.is_open()) { \ if (infile.is_open()) { \
iline=readDataFile(infile, data, nch, 0); \ iline=readDataFile(infile, data, nch, 0); \
infile.close(); \ infile.close(); \
} else { \ } else { \
std::cout<< "Could not read file " << fname << std::endl; \ std::cout<< "Could not read file " << fname << std::endl; \
return -1; \ return -1; \
} \ } \
return iline; \ return iline; \
}; };
/** /**
reads a raw data file reads a raw data file
\param infile input file stream \param infile input file stream
\param data array of data values \param data array of data values
\param nch number of channels \param nch number of channels
\param offset start channel value \param offset start channel value
\returns OK or FAIL if it could not read the file or data=NULL \returns OK or FAIL if it could not read the file or data=NULL
*/ */
static int readDataFile(ifstream &infile, int *data, int nch, int offset) { \ static int readDataFile(ifstream &infile, int *data, int nch, int offset) { \
int ichan, idata, iline=0; \ int ichan, idata, iline=0; \
int interrupt=0; \ int interrupt=0; \
string str; \ string str; \
while (infile.good() and interrupt==0) { \ while (infile.good() and interrupt==0) { \
getline(infile,str); \ getline(infile,str); \
istringstream ssstr(str); \ istringstream ssstr(str); \
ssstr >> ichan >> idata; \ ssstr >> ichan >> idata; \
if (ssstr.fail() || ssstr.bad()) { \ if (ssstr.fail() || ssstr.bad()) { \
interrupt=1; \ interrupt=1; \
break; \ break; \
} \ } \
if (iline<nch) { \ if (iline<nch) { \
if (ichan>=offset) { \ if (ichan>=offset) { \
data[iline]=idata; \ data[iline]=idata; \
iline++; \ iline++; \
} \ } \
} else { \ } else { \
interrupt=1; \ interrupt=1; \
break; \ break; \
} \ } \
} \ } \
return iline; \ return iline; \
}; };
/** /**
reads a short int rawdata file reads a short int rawdata file
\param name of the file to be read \param name of the file to be read
\param data array of data values \param data array of data values
\param nch number of channels \param nch number of channels
\returns OK or FAIL if it could not read the file or data=NULL \returns OK or FAIL if it could not read the file or data=NULL
*/
static int readDataFile(string fname, short int *data, int nch){ \
ifstream infile; \
int iline=0; \
string str; \
infile.open(fname.c_str(), ios_base::in); \
if (infile.is_open()) { \
iline=readDataFile(infile, data, nch, 0); \
infile.close(); \
} else { \
std::cout<< "Could not read file " << fname << std::endl; \
return -1; \
} \
return iline; \
};
/**
reads a short int raw data file
\param infile input file stream
\param data array of data values
\param nch number of channels
\param offset start channel value
\returns OK or FAIL if it could not read the file or data=NULL
*/ */
static int readDataFile(ifstream &infile, short int *data, int nch, int offset) { \ static int readDataFile(string fname, short int *data, int nch){ \
int ichan, iline=0; \ ifstream infile; \
short int idata; \ int iline=0; \
int interrupt=0; \ string str; \
string str; \ infile.open(fname.c_str(), ios_base::in); \
while (infile.good() and interrupt==0) { \ if (infile.is_open()) { \
getline(infile,str); \ iline=readDataFile(infile, data, nch, 0); \
istringstream ssstr(str); \ infile.close(); \
ssstr >> ichan >> idata; \ } else { \
if (ssstr.fail() || ssstr.bad()) { \ std::cout<< "Could not read file " << fname << std::endl; \
interrupt=1; \ return -1; \
break; \ } \
} \ return iline; \
if (iline<nch) { \ };
if (ichan>=offset) { \
data[iline]=idata; \ /**
iline++; \ reads a short int raw data file
} \ \param infile input file stream
} else { \ \param data array of data values
interrupt=1; \ \param nch number of channels
break; \ \param offset start channel value
} \ \returns OK or FAIL if it could not read the file or data=NULL
return iline; \ */
}; \ static int readDataFile(ifstream &infile, short int *data, int nch, int offset) { \
}; int ichan, iline=0; \
short int idata; \
int interrupt=0; \
string str; \
while (infile.good() and interrupt==0) { \
getline(infile,str); \
istringstream ssstr(str); \
ssstr >> ichan >> idata; \
if (ssstr.fail() || ssstr.bad()) { \
interrupt=1; \
break; \
} \
if (iline<nch) { \
if (ichan>=offset) { \
data[iline]=idata; \
iline++; \
} \
} else { \
interrupt=1; \
break; \
} \
return iline; \
}; \
};
}; };