diff --git a/pub/src/curve.cpp b/pub/src/curve.cpp index 75327c5449601106ac678fb67115939f30295141..628a7f46431c9070a57865304eb00a04aa4d148a 100644 --- a/pub/src/curve.cpp +++ b/pub/src/curve.cpp @@ -176,7 +176,7 @@ vector<string> COlc::pInfo() const lin += wrd; } for ( uint ip=0; ip<nPar(); ip++ ) { - snprintf( wrd, PINFO_WRD_SIZ, "p%02d ", ip ); + snprintf( wrd, PINFO_WRD_SIZ, "p%2d ", ip ); lin += wrd; } ret.push_back( lin ); @@ -191,7 +191,7 @@ vector<string> COlc::pInfo() const } for ( uint ip=0; ip<nPar(); ip++ ) { snprintf( wrd, PINFO_WRD_SIZ, "%c%-12.7g ", - Fixed[ip].contained(j), VC[j].P[ip] ); + Fixed[ip].contained(j) ? 'x':' ', VC[j].P[ip] ); lin += wrd; } ret.push_back( lin ); @@ -261,56 +261,36 @@ void NCurveFile::SetFixed() break; } - boost::sregex_token_iterator eos; boost::regex re1( "\\s+" ); boost::regex re2( "(\\d+)(\\+|\\-|\\=)(.*)" ); // Split input string in words boost::sregex_token_iterator _wrd( lin.begin(), lin.end(), re1, -1 ); - while ( _wrd!=eos ) { + while ( _wrd!=boost::sregex_token_iterator() ) { + // Parse one instruction string wrd = *_wrd++; boost::smatch tokens; if( !boost::regex_match( wrd, tokens, re2 ) ) throw "invalid instruction "+wrd; - if ( tokens[2] == "+" ) - cout << "+!!!\n"; - else if ( tokens[2] == "-" ) - cout << "-!!!\n"; - else if ( tokens[2] == "=" ) - cout << "=!!!\n"; - } - -/* - while( true ) { - mystd::string_extract_word( lin, - const char *how_opts[] = { "", "+", "-" }; - int ihow; - for ( ihow=0; ihow<=2; ++ihow ) - if ( how==how_opts[ihow] ) - goto found_how; - cout << "ERROR/ unknown option\n"; - return; - found_how: - - const char *which_quest[] = { - "toggle fix status of pars", "set fixed pars", "unfix pars" }; - - NOlm::IterateC fiter; - COlc *f; - static string pSel = "*"; - while( (f=fiter()) ) { - pSel = wask( which_quest[ihow], pSel ); - CList pLis( pSel, 0, f->nPar()-1 ); - for( size_t iv=0; iv<pLis.size(); ++iv ){ - int *p = &(f->Fixed[ pLis.V[iv] ]); - switch (ihow) { - case 0: *p = !*p; break; - case 1: *p = 1; break; - case 2: *p = 0; break; - } + if ( tokens[2]!="=" && tokens[3]!="" ) + throw "invalid instruction "+wrd; + size_t ip; + if( !mystd::any2uint( tokens[1], &ip ) ) + throw string( "BUG: unreadable ip in spite of match" ); + // Loop over selected curve files + NOlm::IterateC fiter; + COlc *f; + while( (f=fiter()) ) { + if( ip>=f->nPar() ) + throw string( "invalid parameter number" ); + if ( tokens[2] == "+" ) + f->Fixed[ip] = CList( ); + else if ( tokens[2] == "-" ) + f->Fixed[ip] = CList( 0, f->nPar()-1 ); + else if ( tokens[2] == "=" ) + f->Fixed[ip] = CList( tokens[3], 0, f->nPar()-1 ); } } -*/ } diff --git a/pub/src/edif.cpp b/pub/src/edif.cpp index 4750c16cb7ba5ee45dda70de599c55d24762825d..be0dd747990a68f8f4bac6213b08f1c794b41b77 100644 --- a/pub/src/edif.cpp +++ b/pub/src/edif.cpp @@ -550,7 +550,7 @@ void NEdif::ReadIn(void) case 1: line = sask("Enter z value", ""); // cout << "DEBUG: line [" << line << "]\n"; - if (mystd::str2vec(line, &linv, 2) < 0) { + if (!mystd::str2vec(line, &linv, 2) < 0) { cout << "-> invalid line [" << line << "]\n"; goto store; } @@ -564,7 +564,7 @@ void NEdif::ReadIn(void) break; case 2: line = sask("Enter header line with z values", ""); - if (mystd::str2vec(line, &linv, imcy+1)) { + if (!mystd::str2vec(line, &linv, imcy+1)) { cout << "-> bad input\n"; goto store; } @@ -603,7 +603,7 @@ void NEdif::ReadIn(void) quest = "[" + strg(n) + "] "; line = sask(quest.c_str(), ""); if (line==string("")) break; - if (mystd::str2vec(line, &linv, imcm+1)) { + if (!mystd::str2vec(line, &linv, imcm+1)) { printf( " could not extract value no. %u" " from string [%s]\n", imcm, line.c_str()); @@ -660,8 +660,7 @@ void NEdif::ReadIn(void) strg(S.x[i]) + " -> "; while (1) { line = sask(quest.c_str()); - if (mystd::str2vec(line, - &linv, imcy+1)) { + if (!mystd::str2vec(line, &linv, imcy+1)) { printf( " could not extract y value no. %u" " from string [%s]\n", imcy, line.c_str()); @@ -795,7 +794,7 @@ void NEdif::ReadTab( string qualif ) if( !horizontal && nblock!=0 && S.size()>0 ) olf.VS.push_back(S); if ( multiblock ) { - if( mystd::str2vec(lin, &zdat, 0, false) ) + if( !mystd::str2vec(lin, &zdat, 0, false) ) throw "invalid header line [" + lin + "] (or legitimate break ?)"; if( nblock==0 ){ // first header @@ -831,7 +830,7 @@ void NEdif::ReadTab( string qualif ) } // regular data line - if( mystd::str2vec(lin, &dat, 0, false) ) + if( !mystd::str2vec(lin, &dat, 0, false) ) throw "cannot parse line "+strg(nline)+" in block "+ strg(nblock)+" ["+lin+"]"; if(dat.size()==0) diff --git a/pub/src/mystd.cpp b/pub/src/mystd.cpp index 1c81762094fb342eeab179de98f3e4c6b447cb50..8f0d1f1986e3cfb08d8425f10471867ea05a80a9 100644 --- a/pub/src/mystd.cpp +++ b/pub/src/mystd.cpp @@ -129,7 +129,7 @@ string yaml( const string s ) //* convert from string *// //**************************************************************************// -int mystd::str2vec(string inp, vector<double> *V, uint nmax, bool force) +bool mystd::str2vec( string inp, vector<double> *V, uint nmax, bool force ) { using namespace mystd_aux; using namespace std; @@ -144,7 +144,7 @@ int mystd::str2vec(string inp, vector<double> *V, uint nmax, bool force) // cout << "DEBUG core [" << inp << "]\n"; if (inp==string("")) { // cout << "DEBUG empty\n"; - return 0; + return true; } // cout << "DEBUG nonempty\n"; @@ -162,7 +162,7 @@ int mystd::str2vec(string inp, vector<double> *V, uint nmax, bool force) cout << "! str2vec: invalid value [" << inp.substr(ji,jf-ji) << "] at pos " << ji << " in [" << inp << "]\n"; - return -1; + return false; } if (nmax && V->size()>=nmax) break; // do not decode the tail // cout << " found "<<ji<<":"<<jf<<" value "<<val<<"\n"; @@ -170,7 +170,7 @@ int mystd::str2vec(string inp, vector<double> *V, uint nmax, bool force) // cout << " continue at " << ji << "\n"; } - return 0; + return true; } bool mystd::any2dbl( const string inp, double *val ) @@ -219,6 +219,22 @@ bool mystd::any2int(const string inp, int *val) return false; } +bool mystd::any2uint(const string inp, uint *val) +{ + if(!inp.size()) { + cout << "expecting integer, found empty input\n"; + return false; + } + if(!strchr("0123456789", inp[0])) { + cout << "expecting integer, found bad char[0] in [" + << inp << "]\n"; + return false; + } + if (sscanf(inp.c_str(), "%u", val)==1) return true; + cout << "expecting integer, sscanf failed\n"; + return false; +} + void mystd::string_extract_word( const string in, string *out1, string *out2 ) { // one word (*out1) is extracted; leading " \t" are retained. diff --git a/pub/src/mystd.h b/pub/src/mystd.h index d29125cad6f0f7fc50a05ae20eb09cc671c50abd..f49d0a9f549b360dad6c2ebab8d336221a20a49c 100644 --- a/pub/src/mystd.h +++ b/pub/src/mystd.h @@ -27,9 +27,10 @@ namespace mystd { extern const char BEL; //! convert from string - int str2vec( string inp, vector<double> *V, uint nmax=0, bool force=true ); + bool str2vec( string inp, vector<double> *V, uint nmax=0, bool force=true ); bool any2dbl( const string inp, double *val ); bool any2int( const string inp, int *val ); + bool any2uint( const string inp, uint *val ); void string_extract_word( const string in, string *out1, string *out2 ); void string_extract_line( const string in, string *out1, string *out2 ); diff --git a/pub/src/rssm.cpp b/pub/src/rssm.cpp index 24666dff3540c90443dd549d58884298e07c2dd9..64c3021df038bf026e16724b86715f1279e813ee 100644 --- a/pub/src/rssm.cpp +++ b/pub/src/rssm.cpp @@ -32,7 +32,8 @@ class RssmRawFile { int maj_syntax, min_syntax, maj_outform, min_outform; }; -// Read raw data file, store contents as class variables +//! Read raw data file, store contents as class variables + void RssmRawFile::RdRawYam( FILE *F_in ) { string lin, key, val, bla, blub; @@ -146,7 +147,7 @@ void RssmRawFile::RdRawYam( FILE *F_in ) rawdata[i].push_back( num ); for( int i=0; i<4; ++i ){ val = y.getscalar( "cnts line" ); - if( mystd::str2vec( val, &numvec ) ) + if( !mystd::str2vec( val, &numvec ) ) throw string( "cnts line extraction failed" ); if( numvec.size()!=ndet ) throw string( "hist: ndet incompatibility" ); @@ -155,7 +156,7 @@ void RssmRawFile::RdRawYam( FILE *F_in ) } for( int i=0; i<4; ++i ){ val = y.getscalar( "time line" ); - if( mystd::str2vec( val, &numvec ) ) + if( !mystd::str2vec( val, &numvec ) ) throw string( "time line extraction failed" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] ); @@ -180,7 +181,7 @@ void RssmRawFile::RdRawYam( FILE *F_in ) rawdata[i].push_back( num ); for( int i=4; i<6; ++i ){ val = y.getscalar( "cnts line" ); - if( mystd::str2vec( val, &numvec ) ) + if( !mystd::str2vec( val, &numvec ) ) throw string( "cnts line extraction failed" ); if( numvec.size()!=ndet ) throw string( "hist: ndet incompatibility" ); @@ -189,7 +190,7 @@ void RssmRawFile::RdRawYam( FILE *F_in ) } for( int i=4; i<6; ++i ){ val = y.getscalar( "time line" ); - if( mystd::str2vec( val, &numvec ) ) + if( !mystd::str2vec( val, &numvec ) ) throw string( "time line extraction failed" ); for( int ii=0; ii<numvec.size(); ++ii ) rawdata[i].push_back( numvec[ii] );