diff --git a/TODO b/TODO index 661b545bde001e2fd552a691cd004187ca3099fe..6a196b960a44a110e62d94ea17d09df8b3703342 100644 --- a/TODO +++ b/TODO @@ -7,14 +7,13 @@ == TO CHECK == -- as-on-disk indicator repaired -- review definition of cauchy(,) - == WISHLIST: TODO == - user interface - - restore ask callback help for lists (prompt for list, not for string) - - restore help on "?" (e.g. expression help for 'md') + - dialog generics + - restore ask callback help for lists (prompt for list, not for string) + - restore help on "?" (e.g. expression help for 'md') + - default for plot range - 'hf' add explanation (formulae) - 'gp!' <filename> ? - 'op' to give expressions for all parameters diff --git a/pub/old/r-temp.cpp b/old/src-fragm/r-temp.cpp similarity index 100% rename from pub/old/r-temp.cpp rename to old/src-fragm/r-temp.cpp diff --git a/pub/old/r-temp.h b/old/src-fragm/r-temp.h similarity index 100% rename from pub/old/r-temp.h rename to old/src-fragm/r-temp.h diff --git a/pub/CHANGELOG b/pub/CHANGELOG index 4340b29e4020c022cdf4c16c5f5804dc896262f8..53e195e80cb372b58465623e86a2a4c06434b4d0 100644 --- a/pub/CHANGELOG +++ b/pub/CHANGELOG @@ -1,3 +1,14 @@ +Release + +- new functionality: + - 'dd' now shows doc lines, 'ed' allows to edit them via vi +- improved behavior: + - reduce noise in lDoc (no 'cf'; basic merge in 'mfj') +- internal changes: + - eliminate remnants of SPHERES/XML read in +- bugfixes: + - repaired 'ry' after 100511 introduction of shared_ptr + Release 2.1.0c of 21may10: - bugfixes, among them: @@ -10,7 +21,7 @@ Release 2.1.0c of 21may10: Release 2.1.0b of 15may10: -- fix bugs introduced by release 100511: +- fix bugs introduced by release 100511 (especially by shared_ptr): - enable ody - repair oio when nJ=1 - oy was setting nonsense dy when expr yielded no error diff --git a/pub/src/curve.cpp b/pub/src/curve.cpp index addbaeeeba331c436bb287007cfc75d30dd4d1be..df3c3b31b397f3ae4954091399e76605f8dca26a 100644 --- a/pub/src/curve.cpp +++ b/pub/src/curve.cpp @@ -600,7 +600,8 @@ void NCurveFile::Fit( bool _allow_slow_conv ) } if ( fc->ProtectedSpecs.size() ) cout << "INFO: some spectra are protected\n"; - fc->lDoc.push_back( "fitted to file " + strg(fc->kd) + " " + fd->name ); + // fc->lDoc.push_back( + // "fitted to file " + strg(fc->kd) + " " + fd->name ); if( fc->range_T ) { fd = POld( fd->new_old() ); diff --git a/pub/src/edif.cpp b/pub/src/edif.cpp index 033c48334ad2a3e91fe195b30afe56b0c48967e4..2bee76f4f73c2729fcdc976c24da17ffa768b422 100644 --- a/pub/src/edif.cpp +++ b/pub/src/edif.cpp @@ -9,6 +9,7 @@ #include <stdio.h> #include <math.h> #include <iostream> +#include <fstream> #include <algorithm> #include <boost/format.hpp> @@ -29,12 +30,12 @@ namespace NEdif { //**************************************************************************// -//* Display different views on the data; edit parameters *// +//* Show listings *// //**************************************************************************// //! Display list of online files. -void NEdif::Dir() +void NEdif::ShowFiles() { NOlm::IterateO fiter; fiter.choose_all(); @@ -85,9 +86,9 @@ void NEdif::Dir() } -//! Display list of z-values and x-ranges for spectra in selected files. +//! Display list of z-values and x-ranges for spectra. -void NEdif::DirZ() +void NEdif::ShowSpectra() { NOlm::SelAssert(); @@ -120,9 +121,29 @@ void NEdif::DirZ() } -//! Display z coordinates (names and units) for selected files. +//! Display coordinate names and units. -void NEdif::ListZ() +void NEdif::ShowCoord() +{ + NOlm::SelAssert(); + + NOlm::IterateO fiter; + POlo f; + while( f = fiter() ) { + string out = str( format( "%3d" ) % fiter.k() ); + out += " x: " + f->xco.str(); + out += " y: " + f->yco.str(); + for ( uint i=0; i<f->nZ(); i++ ) { + out += " z" + strg(i) + ": " + f->ZCo[i].str() + "\n"; + } + cout << out; + } +} + + +//! Display z coordinates (names and units). + +void NEdif::ShowCoordZ() { NOlm::SelAssert(); @@ -153,9 +174,9 @@ void NEdif::ListZ() } -//! Display numeric parameters for selected files. +//! Display numeric parameters. -void NEdif::DirNumpar() +void NEdif::ShowNumpar() { NOlm::SelAssert(); @@ -171,6 +192,28 @@ void NEdif::DirNumpar() } +//! Display documentation lines. + +void NEdif::ShowDoc() +{ + NOlm::SelAssert(); + + NOlm::IterateO fiter; + POlo f; + while( f = fiter() ) { + if( fiter.iteration()>0 ) + cout << "\n"; + cout << fiter.k() << "\n"; + for ( uint i=0; i<f->lDoc.size(); i++ ) + cout << f->lDoc[i] << "\n"; + } +} + + +//**************************************************************************// +//* Edit data *// +//**************************************************************************// + //! Interactive modification of numeric parameters. //! QUESTIONABLE. Why not use generic expressions and specific commands? @@ -321,26 +364,6 @@ CParam* NEdif::RFind( POlo f, CCoord OneR ) } -//! Display coordinate names and units for selected files. - -void NEdif::DirCoord() -{ - NOlm::SelAssert(); - - NOlm::IterateO fiter; - POlo f; - while( f = fiter() ) { - string out = str( format( "%3d" ) % fiter.k() ); - out += " x: " + f->xco.str(); - out += " y: " + f->yco.str(); - for ( uint i=0; i<f->nZ(); i++ ) { - out += " z" + strg(i) + ": " + f->ZCo[i].str() + "\n"; - } - cout << out; - } -} - - //! Modify file name void NEdif::EditFNam() @@ -372,7 +395,7 @@ void NEdif::EditCoord( string which ) NOlm::IterateO fiter; POlo fin; - while( fin = fiter() ) { + while ( fin = fiter() ) { POlo fout = fin; CCoord old_co; @@ -394,22 +417,52 @@ void NEdif::EditCoord( string which ) } -//! Display documentation lines for selected files. - -//! MISSING: Interactive modification of documentation. +//! Edit documentation lines. void NEdif::EditDoc() { NOlm::SelAssert(); + // transfer to tmp file: + ofstream Fo( "/tmp/frida.tmp.doc" ); NOlm::IterateO fiter; POlo f; - while( f = fiter() ) { - if( fiter.iteration()>0 ) - cout << "\n"; - cout << fiter.k() << "\n"; + while ( f = fiter() ) { + Fo << "### FILE " << fiter.k() << " " << f->name << " ###\n"; for ( uint i=0; i<f->lDoc.size(); i++ ) - cout << f->lDoc[i] << "\n"; + Fo << f->lDoc[i] << "\n"; + } + Fo.close(); + + // let user edit that file: + system( "vi /tmp/frida.tmp.doc" ); + + // read back from tmp file: + fiter.reset(); + FILE* Fi; + if( !(Fi = fopen( "/tmp/frida.tmp.doc", "r" )) ) + throw string( "cannot read back from tmp file" ); + string line; + while ( mystd::freadln(Fi, &line)>=0 ){ + if ( line.substr(0,3)=="###" ) { + f = fiter(); + if ( line.substr(3,6)!=" FILE " ) + throw string( "invalid change in ### line: 'FILE' not found" ); + string aux; + mystd::string_extract_word( line.substr(9), &aux, &line ); + uint kin; + if ( !mystd::any2uint( aux, &kin ) ) + throw string( + "invalid change in ### line: file number not found" ); + if ( kin!=fiter.k() ) + throw string( "invalid change in ### line: wrong file number" ); + mystd::string_extract_word( line, &aux, &line ); + if ( aux!=f->name ) + throw string( "invalid change in ### line: wrong file name" ); + f->lDoc.clear(); + } else { + f->lDoc.push_back( line ); + } } } diff --git a/pub/src/edif.h b/pub/src/edif.h index b045f22c1f271d278a4851e807a4a6f54e705642..a08bd6fd1018b5c48c374c611bf149af95d1110c 100644 --- a/pub/src/edif.h +++ b/pub/src/edif.h @@ -1,13 +1,16 @@ namespace NEdif { - void Dir(); - void DirZ(); - void ListZ(); - void DirNumpar(); + void ShowFiles(); + void ShowSpectra(); + void ShowCoord(); + void ShowCoordZ(); + void ShowNumpar(); + void ShowDoc(); + void EditNumpar(); - void DirCoord(); void EditFNam(); void EditCoord( string which ); void EditDoc(); + void ReadIn(); void ReadTab( string qualif ); void MakeGrid(); diff --git a/pub/src/frida2.cpp b/pub/src/frida2.cpp index df6d4a212f21a79d86f79dd3cd2f10e4efb2ce99..c1c81077d296d803d025a1c3bbf4d9349ffc7b80 100644 --- a/pub/src/frida2.cpp +++ b/pub/src/frida2.cpp @@ -217,27 +217,30 @@ int main() } else if ( cmd == "d" ) { - cout << "Show directory:\n" + cout << "Show list:\n" " df on-line files\n" - " dz z-values\n" + " dz z-values and spectral ranges\n" " dp x|y-values\n" " dy y-values\n" " dn numeric parameters\n" " dc coordinate names and units\n" + " dd doc lines\n" ; } else if (cmd == "df") { - NEdif::Dir(); + NEdif::ShowFiles(); } else if (cmd == "dz") { - NEdif::DirZ(); + NEdif::ShowSpectra(); } else if (cmd == "dp" ) { NOperate::Show( "xyd" ); } else if (cmd == "dy" ) { NOperate::Show( "y" ); - } else if (cmd == "dn" ) { - NEdif::DirNumpar(); + } else if (cmd == "dn") { + NEdif::ShowNumpar(); } else if (cmd == "dc") { - NEdif::DirCoord(); + NEdif::ShowCoord(); + } else if (cmd == "dd") { + NEdif::ShowDoc(); } else if ( cmd == "e" ) { cout << "Edit parameters:\n" @@ -254,7 +257,7 @@ int main() } else if (cmd == "ef") { NEdif::EditFNam(); } else if (cmd == "en") { - NEdif::EditNumpar(); + NEdif::ShowNumpar(); } else if (cmd == "f") { @@ -468,7 +471,7 @@ int main() } else if (cmd == "mzx") { NManip::ZExchange(); } else if (cmd == "mz-") { - NEdif::ListZ(); + NEdif::ShowCoordZ(); NManip::ZDelete(); } else if (cmd == "mso") { NManip::ScaSortByExpr(); @@ -518,49 +521,22 @@ int main() " ryd load only spectra for two directions\n" " rs load series of energy spectra\n" " rs2 load also spectra for open state\n" - " rold list old-format commands\n" - ; - - } else if (cmd == "rold") { - cout << "read old/internal RSSM data files:\n" - " rx load energy spectra\n" - " rx2 load also spectra for open state\n" - " rx4 load also chopper histograms\n" - " rx8 load spectra for two directions separately\n" - " rxd load only spectra for two directions\n" - " rxs load series of energy spectra\n" - " rxs2 load also spectra for open state\n" ; } else if (cmd == "ry" ) { - NRSSM::ReadSpec( 5, 0 ); + NRSSM::ReadSpec( 0 ); } else if (cmd == "ry2") { - NRSSM::ReadSpec( 5, 1 ); + NRSSM::ReadSpec( 1 ); } else if (cmd == "ry4") { - NRSSM::ReadSpec( 5, 3 ); + NRSSM::ReadSpec( 3 ); } else if (cmd == "ry8") { - NRSSM::ReadSpec( 5, 7 ); + NRSSM::ReadSpec( 7 ); } else if (cmd == "ryd") { - NRSSM::ReadSpec( 5, 12 ); + NRSSM::ReadSpec( 12 ); } else if (cmd == "rs") { - NRSSM::ReadSeries( 5, 0 ); + NRSSM::ReadSeries( 0 ); } else if (cmd == "rs2") { - NRSSM::ReadSeries( 5, 1 ); - - } else if (cmd == "rx") { - NRSSM::ReadSpec( 2, 0 ); - } else if (cmd == "rx2") { - NRSSM::ReadSpec( 2, 1 ); - } else if (cmd == "rx4") { - NRSSM::ReadSpec( 2, 3 ); - } else if (cmd == "rx8") { - NRSSM::ReadSpec( 2, 7 ); - } else if (cmd == "rxd") { - NRSSM::ReadSpec( 2, 12 ); - } else if (cmd == "rxx") { - NRSSM::ReadSeries( 2, 0 ); - } else if (cmd == "rxs2") { - NRSSM::ReadSeries( 2, 1 ); + NRSSM::ReadSeries( 1 ); } else if (cmd == "t") { diff --git a/pub/src/manip.cpp b/pub/src/manip.cpp index 31f0b983753a7a8d856dff66aa086f09015db2a0..f76f796d0444ed0e6dac1bd5db0c13001b8a9413 100644 --- a/pub/src/manip.cpp +++ b/pub/src/manip.cpp @@ -1016,10 +1016,23 @@ void NManip::FilMerge( const string& opts ) // doc lines: fout->lDoc.push_back(fnam + " is merger of:"); fiter.reset(); + POlo f1 = fiter(); + fiter.reset(); while ( (fin = fiter()) ) { fout->lDoc.push_back(" " + fin->name); - for ( uint i=0; i<fin->lDoc.size(); ++i ) - fout->lDoc.push_back(" " + fin->lDoc[i]); + if ( fiter.iteration()==0 ) { + for ( uint i=0; i<fin->lDoc.size(); ++i ) + fout->lDoc.push_back(" " + fin->lDoc[i]); + } else { + string line = " "; + for ( uint i=0; i<fin->lDoc.size(); ++i ) { + if( i<f1->lDoc.size() && fin->lDoc[i]==f1->lDoc[i] ) { + line += "="; + } else { + fout->lDoc.push_back( line + fin->lDoc[i] ); + } + } + } } // now merge the Zentries, and add new z's: diff --git a/pub/src/mystd.h b/pub/src/mystd.h index da352ac04d76bdfea3e2493ab584b6c287a706b4..597a66a704cfc058fbf075ad1a7af027ecfbef0e 100644 --- a/pub/src/mystd.h +++ b/pub/src/mystd.h @@ -36,7 +36,7 @@ namespace mystd { void system( string cmd ); //! time - double justnow( void ); + double justnow(); string myasctime( double time, int offs ); //! rounding @@ -54,18 +54,17 @@ namespace mystd { // file names, globbing, file read void fname_divide( const string& fname, string *fdir, string *fshort, string *fext); - int glob_file_list(const string& text, - const string& pre, const string& ext, - vector<string> *flong, vector<string> *fshort=0); - int glob_one_file(const string& text, - const string& pre, const string& ext, string *fname); - FILE* glob_fopen(const string& text, const string& pre, const string& ext, - const char* mod, string *fname=0); + int glob_file_list( const string& text, + const string& pre, const string& ext, + vector<string> *flong, vector<string> *fshort=0); + int glob_one_file( const string& text, + const string& pre, const string& ext, string *fname); + FILE* glob_fopen( const string& text, const string& pre, const string& ext, + const char* mod, string *fname=0); int freadln( FILE *fd, string *s ); // integration double Integrate( double (*func_) (double, void*), void *data_, double low, double hig, - uint mode, double epsabs, - double epsrel ); + uint mode, double epsabs, double epsrel ); } diff --git a/pub/src/rssm.cpp b/pub/src/rssm.cpp index d7de2c98a12fad0ee75af5fc23eb4770f57f1d52..4189c24eb3a5b346e2aca2990883887ea0629f99 100644 --- a/pub/src/rssm.cpp +++ b/pub/src/rssm.cpp @@ -22,7 +22,7 @@ using namespace std; -class RssmRawFile { +class CRawfileSpheres { public: void RdRawYam( ifstream& F_in ); double daq_time_step; @@ -38,15 +38,15 @@ class RssmRawFile { //! Read raw data file, store contents as class variables -//void RssmRawFile::RdRawYam( FILE *F_in ) -void RssmRawFile::RdRawYam( ifstream& F_in ) +//void CRawfileSpheres::RdRawYam( FILE *F_in ) +void CRawfileSpheres::RdRawYam( ifstream& F_in ) { string lin, key, val, bla, blub; CCoord co; CSpec sout; - int ndet; double num; vector<double> numvec; + uint ndet; maj_outform = 5; min_outform = 1; @@ -58,27 +58,27 @@ void RssmRawFile::RdRawYam( ifstream& F_in ) YAML::Node doc; parser.GetNextDocument(doc); - //start to read Meta + // read Meta: if(!doc.FindValue("Meta")) throw string("no Meta" ); try { YAML::CONTENT_TYPE Metatype = doc["Meta"].GetType(); if ( Metatype != YAML::CT_MAP && doc["Meta"].size() > 0) - throw string("Meta is not a MAP type" ); + throw string("DATA BUG: Meta is not a MAP" ); if(!doc["Meta"].FindValue("format")) - throw string("no format in Meta" ); + throw string("DATA BUG: no format in Meta" ); doc["Meta"]["format"] >> val; if( strncmp( val.c_str(), "acq5.1 for yaml1", 16 ) ) - throw( string("Unexpected format: ") + val + " instead of acq5.1" ); + throw "UNEXPECTED DATA: format: " + val + " instead of acq5.1"; } catch(YAML::ParserException& e) { - std::cout << "no Meta" << e.what() << "\n"; + throw string( "DATA BUG: failed to read Meta section" ) + e.what(); } - //do nothing in History + // ignore History. - //start to read Shortpar + // read Shortpar: if(!doc.FindValue("Shortpar")) - throw string("no Shortpar" ); + throw string( "DATA BUG: no Shortpar" ); for(YAML::Iterator it=doc["Shortpar"].begin(); it!=doc["Shortpar"].end();++it) { it.first() >> key; @@ -89,8 +89,8 @@ void RssmRawFile::RdRawYam( ifstream& F_in ) else if ( val=="false" ) incremental = false; else - throw string( "Invalid value [" ) + val + - "] of 'incremental'"; + throw string( "DATA BUG: invalid value [" ) + val + + "] of 'incremental'"; } else if ( key=="measured_until" ){ char date_string[24]; sscanf( val.c_str(), "%24c", date_string ); @@ -98,54 +98,52 @@ void RssmRawFile::RdRawYam( ifstream& F_in ) strptime( date_string, "%F %A %H:%M:%S", &date_broken ); measured_until = mktime( &date_broken ); } else if ( key=="ndet" ){ - if( !mystd::any2int( val, &ndet ) ) - throw string( "invalid ndet" ); + if( !mystd::any2uint( val, &ndet ) ) + throw string( "DATA BUG: invalid ndet" ); } else if ( key=="daq_time_step" ){ mystd::string_extract_word( val, &bla, &blub ); mystd::any2dbl( bla, &daq_time_step ); } } if( !daq_time_step ) - throw string( "daq time step not found" ); + throw string( "DATA BUG: daq time step not found" ); - //do nothing in Longpar + // ignore Longpar. - //start to read Detectors + // read Detectors: if(!doc.FindValue("Detectors")) - throw string("no Detectors" ); - if ( doc["Detectors"].GetType() != YAML::CT_SEQUENCE && - doc["Detectors"].size() > 0 ) - throw string("Detectors is not a SEQUENCE type" ); - for (unsigned int iDet = 0; iDet < (doc["Detectors"].size()); - iDet++) { + throw string("DATA BUG: no Detectors" ); + if ( doc["Detectors"].GetType() != YAML::CT_SEQUENCE ) + throw string("DATA BUG: Detectors is not a SEQUENCE" ); + if( doc["Detectors"].size()!=ndet ) + throw string("DATA BUG: Detectors has not size ndet" ); + for (uint iDet = 0; iDet<ndet; iDet++) { if ( doc["Detectors"][iDet].GetType() != YAML::CT_MAP ) - throw string("Detectors " + strg(iDet) + - " is not a MAP type" ); + throw string("DATA BUG: Detector ") + strg(iDet) + " is not a MAP"; if( const YAML::Node *pName = doc["Detectors"][iDet].FindValue("angle") ){ *pName >> val; if( !mystd::any2dbl( val, &num ) ){ num = 0; - printf( "warning: invalid angle %s\n", + printf( "WARNING: invalid angle %s\n", val.c_str() ); } }else - throw string( "missing angle" ); + throw string( "DATA BUG: missing angle" ); // path_offset ? angles.push_back( num ); } - //start to read EnergyHistograms - if(!doc.FindValue("EnergyHistograms")) - throw string("no EnergyHistograms" ); - if ( doc["EnergyHistograms"].GetType() != YAML::CT_SEQUENCE && - doc["EnergyHistograms"].size() > 0 ) - throw string("EnergyHistograms is not a SEQUENCE type" ); - for (unsigned int iEne = 0; - iEne < (doc["EnergyHistograms"].size()); iEne++) { + // read EnergyHistograms: + if( !doc.FindValue("EnergyHistograms") ) + throw string("DATA BUG: no EnergyHistograms" ); + if ( doc["EnergyHistograms"].GetType() != YAML::CT_SEQUENCE ) + throw string("DATA BUG: EnergyHistograms is not a SEQUENCE" ); + uint nEne = doc["EnergyHistograms"].size(); + for ( uint iEne = 0; iEne<nEne; iEne++ ) { if ( doc["EnergyHistograms"][iEne].GetType() != YAML::CT_SEQUENCE ) - throw "EnergyHistograms " + strg(iEne) + - " is not a SEQUENCE type"; + throw "DATA BUUG: EnergyHistogram " + strg(iEne) + + " is not a SEQUENCE"; doc["EnergyHistograms"][iEne][0] >> val; if( !mystd::any2dbl( val, &num ) ) throw string( "E-Hist: invalid x-value " ) + val; @@ -154,61 +152,57 @@ void RssmRawFile::RdRawYam( ifstream& F_in ) for( int i=0; i<4; ++i ){ doc["EnergyHistograms"][iEne][i+1] >> val;// cnts line if( !mystd::str2vec( val, &numvec ) ) - throw string( "cnts line extraction failed" ); + throw string( "DATA BUG: cnts line extraction failed" ); if( numvec.size()!=ndet ) - throw string( "hist: ndet incompatibility" ); + throw string( "DATA BUG: hist: ndet incompatibility" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); } for( int i=0; i<4; ++i ){ doc["EnergyHistograms"][iEne][i+1+4] >> val;// time line if( !mystd::str2vec( val, &numvec ) ) - throw string( "time line extraction failed" ); + throw string( "DATA BUG: time line extraction failed" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); } } - //start to read ChopperHistograms + // read ChopperHistograms: if(!doc.FindValue("ChopperHistograms")) throw string("no ChopperHistograms" ); - if ( doc["ChopperHistograms"].GetType() != YAML::CT_SEQUENCE && - doc["ChopperHistograms"].size() > 0 ) - throw string("ChopperHistograms is not a SEQUENCE type" ); - for (unsigned int iCho = 0; - iCho < (doc["ChopperHistograms"].size()); iCho++) { + if ( doc["ChopperHistograms"].GetType() != YAML::CT_SEQUENCE ) + throw string( "DATA BUG: ChopperHistograms is not a SEQUENCE" ); + uint nCho = doc["ChopperHistograms"].size(); + for (uint iCho = 0; iCho<nCho; iCho++) { if ( doc["ChopperHistograms"][iCho].GetType() != YAML::CT_SEQUENCE ) - throw string("ChopperHistograms " + strg(iCho) + - " is not a SEQUENCE type" ); + throw string( "DATA BUG: ChopperHistograms " ) + strg(iCho) + + " is not a SEQUENCE"; doc["ChopperHistograms"][iCho][0] >> val; if( !mystd::any2dbl( val, &num ) ) - throw string( "C-Hist: invalid x-value " ) + val; + throw string( "DATA BUG: C-Hist: invalid x-value " ) + val; for( int i=4; i<6; ++i ) rawdata[i].push_back( num ); for( int i=4; i<6; ++i ){ // 2 cnts lines doc["ChopperHistograms"][iCho][i-4+1] >> val;//cnts line if( !mystd::str2vec( val, &numvec ) ) - throw string( "cnts line extraction failed" ); + throw string( "DATA BUG: cnts line extraction failed" ); if( numvec.size()!=ndet ) - throw string( "hist: ndet incompatibility" ); + throw string( "DATA BUG: hist: ndet incompatibility" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); } for( int i=4; i<6; ++i ){ // 2 time lines doc["ChopperHistograms"][iCho][i-4+1+2] >> val;//time line if( !mystd::str2vec( val, &numvec ) ) - throw string( "time line extraction failed" ); + throw string( "DATA BUG: time line extraction failed" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); } } } -void NRSSM::ReadSpec( int format, int flag ) +void NRSSM::ReadSpec( int flag ) -// format values: -// 2 acq2-4 xml -// 5 acq5 yaml // flag values (to be OR'ed): // 1 save also open // 2 save also chop histo @@ -218,33 +212,13 @@ void NRSSM::ReadSpec( int format, int flag ) { string file_f, name; file_f = wask("Read SPHERES data from file"); - RssmRawFile R; - int ret; + CRawfileSpheres R; ifstream F_in; - if ( format==2 ){ - throw string( "XML support has been withdrawn from frida2 on 19may09" ); - } else if ( format==5 ){ - F_in.open (file_f.c_str(),fstream::in); - if( !(F_in.is_open()) ) { - cerr << "Cannot read " << file_f << "\n"; - return; - } - try{ - R.RdRawYam( F_in ); - } - catch( string &e) { - cerr << "Cannot read " << file_f << ":\n"; - cerr << e << endl; - if (F_in.is_open()) F_in.close(); - return; - } - ret = 0; - } else { - throw string( "invalid format" ); - } - if( ret ) - return; + F_in.open (file_f.c_str(),fstream::in); + if( !(F_in.is_open()) ) + throw "Cannot read " + file_f; + R.RdRawYam( F_in ); double tstep = R.daq_time_step; vector<double> *raw = R.rawdata; @@ -280,19 +254,20 @@ void NRSSM::ReadSpec( int format, int flag ) olf[6]->lDoc.push_back( doc + " # refl" ); olf[7]->lDoc.push_back( doc + " # open" ); - for( int j=0; j<ndet; ++j ){ - PSpec S( new CSpec ); - S->z.resize( 1 ); - S->z[0] = R.angles[j]; - for( iolf=0; iolf<8; ++iolf ) + for( iolf=0; iolf<8; ++iolf ){ + for( int j=0; j<ndet; ++j ){ + PSpec S( new CSpec ); + S->z.resize( 1 ); + S->z[0] = R.angles[j]; olf[iolf]->V.push_back(S); + } } - if( R.maj_outform<=2 ){ + if( R.maj_outform<=2 ){ // old data format double x, tmeas, count; // transfer data from raw arrays: for( iolf=0; iolf<6; ++iolf ){ - for( int iraw=0; iraw<(raw+iolf)->size(); iraw+=(ndet+2) ){ + for( int iraw=0; iraw<raw[iolf].size(); iraw+=(ndet+2) ){ x = raw[iolf][iraw]; tmeas = raw[iolf][iraw+ndet+1]; if( tmeas<1 ) continue; @@ -306,11 +281,9 @@ void NRSSM::ReadSpec( int format, int flag ) for( int ichop=0; ichop<2; ++ichop ){ int iolf0 = ichop*2; int iolf1 = ichop*2+1; - int nline = (raw+iolf0)->size(); - if( (raw+iolf1)->size()!=nline ){ - printf( "inconsistent raw array sizes\n" ); - return; - } + int nline = raw[iolf0].size(); + if( raw[iolf1].size()!=nline ) + throw string( "inconsistent raw array sizes" ); for( int iraw=0; iraw<nline; iraw+=(ndet+2) ){ x = raw[iolf0][iraw]; tmeas = raw[iolf0][iraw+ndet+1]+raw[iolf1][iraw+ndet+1]; @@ -326,7 +299,7 @@ void NRSSM::ReadSpec( int format, int flag ) double x, tmeas, count; // transfer data from raw arrays: for( iolf=0; iolf<6; ++iolf ){ - for( int iraw=0; iraw<(raw+iolf)->size(); iraw+=(1+ndet*2) ){ + for( int iraw=0; iraw<raw[iolf].size(); iraw+=(1+ndet*2) ){ x = raw[iolf][iraw]; for ( int j=0; j<ndet; ++j ){ tmeas = raw[iolf][iraw+1+ndet+j]; @@ -340,13 +313,9 @@ void NRSSM::ReadSpec( int format, int flag ) for( int ichop=0; ichop<2; ++ichop ){ int iolf0 = ichop*2; int iolf1 = ichop*2+1; - int nline = (raw+iolf0)->size(); - if( (raw+iolf1)->size()!=nline ){ - printf( "inconsistent raw array sizes: " - "left %zu right %zu lines\n", - (raw+iolf0)->size(), (raw+iolf1)->size() ); - return; - } + int nline = raw[iolf0].size(); + if( raw[iolf1].size()!=nline ) + throw string( "inconsistent raw array sizes" ); for( int iraw=0; iraw<nline; iraw+=(1+ndet*2) ){ x = raw[iolf0][iraw]; for ( int j=0; j<ndet; ++j ){ @@ -382,10 +351,8 @@ void NRSSM::ReadSpec( int format, int flag ) } -void NRSSM::ReadSeries( int format, int flag ) +void NRSSM::ReadSeries( int flag ) -// format values: -// as above // flag values (to be OR'ed): // 1 save also open @@ -393,42 +360,26 @@ void NRSSM::ReadSeries( int format, int flag ) char tstrg[30]; string fser, fnam, name; time_t t; - int ret, isub; - vector<RssmRawFile> RR; + int isub; + vector<CRawfileSpheres> RR; // Read consolidated files: fser = wask("Read SPHERES data from series"); for( isub=0; ; ++isub ){ - if ( format==2 ) { - throw string( - "XML support has been withdrawn from frida2 on 19may09" ); - } else if( format==5 ) { - fnam = fser+"a"+strg(isub); - ifstream F_in; - F_in.open(fnam.c_str(),fstream::in); - if( !(F_in.is_open()) ) - break; - // cout << "successfully opened "<<fnam<<"\n"; - try{ - RssmRawFile rf; - rf.RdRawYam( F_in ); - RR.push_back( rf ); - } - catch(exception& e) { - cerr << e.what() << endl; - if (F_in.is_open()) F_in.close(); - return; - } - ret = 0; - } else { - throw string( "invalid format parameter" ); - } - if ( ret ) - return; + fnam = fser+"a"+strg(isub); + ifstream F_in; + F_in.open(fnam.c_str(),fstream::in); + if( !(F_in.is_open()) ) + break; + // cout << "successfully opened "<<fnam<<"\n"; + CRawfileSpheres rf; + rf.RdRawYam( F_in ); + RR.push_back( rf ); } + int nsub = RR.size(); if( nsub==0 ) - throw string( "could not open file " ) + fnam; + throw "could not open file " + fnam; else if( nsub==1 ) throw string( "series contains just one spectrum -> use a simpler method"); printf( "successfully read %d files\n", nsub ); @@ -521,10 +472,10 @@ void NRSSM::ReadSeries( int format, int flag ) for( int ichop=0; ichop<2; ++ichop ){ int iolf0 = ichop*2; int iolf1 = ichop*2+1; - if( (raw+iolf1)->size()/(1+ndet*2)!=nE ){ + if( raw[iolf1].size()/(1+ndet*2)!=nE ){ printf( "inconsistent raw array sizes:\n" " chop %i raw1 %zu nE %i\n", - ichop, (raw+iolf1)->size(), nE ); + ichop, raw[iolf1].size(), nE ); return; } for( int iE=0; iE<nE; ++iE ){ @@ -569,7 +520,7 @@ void NRSSM::ReadSeries( int format, int flag ) for( int ichop=0; ichop<2; ++ichop ){ int iolf0 = ichop*2; int iolf1 = ichop*2+1; - if( (raw+iolf1)->size()/(ndet+2)!=nE ){ + if( raw[iolf1].size()/(ndet+2)!=nE ){ printf( "inconsistent raw array sizes\n" ); return; } diff --git a/pub/src/rssm.h b/pub/src/rssm.h index 69ebc91b5ae2f90e0729337040e73b0c970675c2..174e4d4bee98b04d69eb37a4d8410409c73fd5fc 100644 --- a/pub/src/rssm.h +++ b/pub/src/rssm.h @@ -1,4 +1,4 @@ namespace NRSSM { - void ReadSpec( int format, int flag ); - void ReadSeries( int format, int flag ); + void ReadSpec( int flag ); + void ReadSeries( int flag ); };