mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-02 02:40:04 +02:00
data file read/write now work with both file names and file streams
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@119 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
a556b2a7da
commit
23aea6007b
@ -758,14 +758,13 @@ int slsDetectorUtils::writeDataFile(string fname, int nch, int *data){
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*writes raw data file */
|
||||
int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, int *data){
|
||||
if (data==NULL)
|
||||
return FAIL;
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Writing to file " << fname << std::endl;
|
||||
#endif
|
||||
for (int ichan=0; ichan<nch; ichan++)
|
||||
outfile << ichan << " " << *(data+ichan) << std::endl;
|
||||
|
||||
@ -782,7 +781,7 @@ int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, int *data){
|
||||
|
||||
|
||||
|
||||
int slsDetectorUtils::readDataFile(int nch, string fname, float *data, float *err, float *ang, char dataformat){
|
||||
int slsDetectorUtils::readDataFile(int nch, string fname, float *data, float *err, float *ang, char dataformat){
|
||||
|
||||
|
||||
ifstream infile;
|
||||
@ -801,6 +800,30 @@ int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, int *data){
|
||||
#endif
|
||||
infile.open(fname.c_str(), ios_base::in);
|
||||
if (infile.is_open()) {
|
||||
readDataFile(nch, infile, data, err, ang, dataformat);
|
||||
infile.close();
|
||||
} else {
|
||||
std::cout<< "Could not read file " << fname << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return iline;
|
||||
};
|
||||
|
||||
|
||||
int slsDetectorUtils::readDataFile(int nch, ifstream &infile, float *data, float *err, float *ang, char dataformat){
|
||||
|
||||
|
||||
int ichan, iline=0;
|
||||
int interrupt=0;
|
||||
float fdata, ferr, fang;
|
||||
int maxchans;
|
||||
int ich;
|
||||
string str;
|
||||
|
||||
|
||||
maxchans=nch;
|
||||
|
||||
|
||||
while (infile.good() and interrupt==0) {
|
||||
getline(infile,str);
|
||||
#ifdef VERBOSE
|
||||
@ -844,11 +867,6 @@ int slsDetectorUtils::writeDataFile(ofstream &outfile, int nch, int *data){
|
||||
break;
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
} else {
|
||||
std::cout<< "Could not read file " << fname << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return iline;
|
||||
};
|
||||
|
||||
@ -866,7 +884,23 @@ int slsDetectorUtils::readDataFile(string fname, int *data, int nch){
|
||||
#endif
|
||||
infile.open(fname.c_str(), ios_base::in);
|
||||
if (infile.is_open()) {
|
||||
while (infile.good() and interrupt==0) {
|
||||
readDataFile(infile, data, nch);
|
||||
infile.close();
|
||||
} else {
|
||||
std::cout<< "Could not read file " << fname << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return iline;
|
||||
};
|
||||
|
||||
int slsDetectorUtils::readDataFile(ifstream &infile, int *data, int nch){
|
||||
|
||||
int ichan, idata, iline=0;
|
||||
int interrupt=0;
|
||||
string str;
|
||||
|
||||
|
||||
while (infile.good() and interrupt==0) {
|
||||
getline(infile,str);
|
||||
#ifdef VERBOSE
|
||||
std::cout<< str << std::endl;
|
||||
@ -891,11 +925,6 @@ int slsDetectorUtils::readDataFile(string fname, int *data, int nch){
|
||||
}
|
||||
}
|
||||
}
|
||||
infile.close();
|
||||
} else {
|
||||
std::cout<< "Could not read file " << fname << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return iline;
|
||||
};
|
||||
|
||||
@ -911,6 +940,13 @@ int slsDetectorUtils::writeDataFile(string fname, float *data, float *err, float
|
||||
return writeDataFile(fname, nch, data, err, ang, dataformat);
|
||||
|
||||
}
|
||||
int slsDetectorUtils::writeDataFile(ofstream &outfile, float *data, float *err, float *ang, char dataformat, int nch){
|
||||
if (nch==-1)
|
||||
nch=getTotalNumberOfChannels();
|
||||
|
||||
return writeDataFile(outfile, nch, data, err, ang, dataformat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -920,6 +956,11 @@ int slsDetectorUtils::writeDataFile(string fname, int *data){
|
||||
return writeDataFile(fname, getTotalNumberOfChannels(), data);
|
||||
}
|
||||
|
||||
int slsDetectorUtils::writeDataFile(ofstream &outfile, int *data){
|
||||
|
||||
return writeDataFile(outfile, getTotalNumberOfChannels(), data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsDetectorUtils::readDataFile(string fname, float *data, float *err, float *ang, char dataformat) {
|
||||
@ -927,6 +968,11 @@ int slsDetectorUtils::readDataFile(string fname, float *data, float *err, float
|
||||
|
||||
}
|
||||
|
||||
int slsDetectorUtils::readDataFile(ifstream &infile, float *data, float *err, float *ang, char dataformat) {
|
||||
return readDataFile(getTotalNumberOfChannels(), infile, data, err, ang, dataformat);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int slsDetectorUtils::readDataFile(string fname, int *data){
|
||||
@ -935,6 +981,12 @@ int slsDetectorUtils::readDataFile(string fname, int *data){
|
||||
};
|
||||
|
||||
|
||||
int slsDetectorUtils::readDataFile(ifstream &infile, int *data){
|
||||
|
||||
return readDataFile(infile, data, getTotalNumberOfChannels());
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -162,7 +162,6 @@ class slsDetectorUtils : public slsDetectorCommand {
|
||||
|
||||
*/
|
||||
int writeDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1);
|
||||
|
||||
int writeDataFile(ofstream &outfile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f', int nch=-1);
|
||||
|
||||
|
||||
@ -175,6 +174,7 @@ class slsDetectorUtils : public slsDetectorCommand {
|
||||
\sa mythenDetector::writeDataFile
|
||||
*/
|
||||
int writeDataFile(string fname, int *data);
|
||||
int writeDataFile(ofstream &outfile, int *data);
|
||||
|
||||
/**
|
||||
|
||||
@ -191,6 +191,7 @@ class slsDetectorUtils : public slsDetectorCommand {
|
||||
\sa mythenDetector::readDataFile
|
||||
*/
|
||||
int readDataFile(string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
|
||||
int readDataFile(ifstream& infile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
|
||||
|
||||
/**
|
||||
|
||||
@ -201,6 +202,7 @@ class slsDetectorUtils : public slsDetectorCommand {
|
||||
\sa mythenDetector::readDataFile
|
||||
*/
|
||||
int readDataFile(string fname, int *data);
|
||||
int readDataFile(ifstream &infile, int *data);
|
||||
|
||||
/**
|
||||
|
||||
@ -218,7 +220,7 @@ class slsDetectorUtils : public slsDetectorCommand {
|
||||
*/
|
||||
|
||||
static int writeDataFile(string fname, int nch, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
|
||||
|
||||
static int writeDataFile(ofstream &outfile, int nch, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
|
||||
/**
|
||||
|
||||
writes a data file
|
||||
@ -228,6 +230,7 @@ class slsDetectorUtils : public slsDetectorCommand {
|
||||
\sa mythenDetector::writeDataFile
|
||||
*/
|
||||
static int writeDataFile(string fname,int nch, int *data);
|
||||
static int writeDataFile(ofstream &outfile,int nch, int *data);
|
||||
|
||||
/**
|
||||
|
||||
@ -244,6 +247,7 @@ class slsDetectorUtils : public slsDetectorCommand {
|
||||
\sa mythenDetector::readDataFile
|
||||
*/
|
||||
static int readDataFile(int nch, string fname, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
|
||||
static int readDataFile(int nch, ifstream &infile, float *data, float *err=NULL, float *ang=NULL, char dataformat='f');
|
||||
|
||||
/**
|
||||
|
||||
@ -254,6 +258,7 @@ class slsDetectorUtils : public slsDetectorCommand {
|
||||
\sa mythenDetector::readDataFile
|
||||
*/
|
||||
static int readDataFile(string fname, int *data, int nch);
|
||||
static int readDataFile(ifstream &infile, int *data, int nch);
|
||||
/**
|
||||
|
||||
reads an angular conversion file
|
||||
|
Loading…
x
Reference in New Issue
Block a user