diff --git a/pub/CHANGELOG b/pub/CHANGELOG index 40203a7dac37ab7014336215f131b15c61a61ece..52974124721037472ef151ce2d4a1e02758ed29d 100644 --- a/pub/CHANGELOG +++ b/pub/CHANGELOG @@ -3,6 +3,8 @@ - sources split (olf/mem, opr/special1, dualplot/axis) - scan and parts of curve now unified in zentry - reduce .h dependencies (keyword "class"; move implementation to .cpp) + - revise exp.cpp thoroughly +- curve evaluation now c[]() instead of f[]() - suppress menu when answer is already given (oio, ..) - bugfix in plot axis rounding - bugfix mfj: z coordinates, rPar diff --git a/pub/src/expr.cpp b/pub/src/expr.cpp index 6ee18c1ea7ab993d026d86df5d50e97230da618b..ed3dd019ae7099fec928c9f9e86be2c91dccc08e 100644 --- a/pub/src/expr.cpp +++ b/pub/src/expr.cpp @@ -29,7 +29,7 @@ extern bool allow_slow_conv; // TODO unify parameter treatment CVariable::CVariable( string s ) { - num = 0; + num = -1; int isub; char c; // WARNING TO PROGRAMMERS: @@ -38,36 +38,35 @@ CVariable::CVariable( string s ) // parameter name. Everything after the parameter name must be ignored. // In other words: the stupid .substr(0,2) are NOT superfluous. int nsub = sscanf( s.c_str(), "%c%d", &c, &isub ); - if ( s.substr(0,2)=="fm" && sscanf(s.substr(2).c_str(), "%d", &isub)==1 ) { - typ = _FM; // fit metric + if ( s.substr(0,2)=="cq" && sscanf(s.substr(2).c_str(), "%d", &isub)==1 ) { + typ = _CQ; num = isub; } else if ( nsub==2 && c=='p' ) { - typ = _FP; // fit parameter + typ = _CP; num = isub; } else if ( s.substr(0,2)=="z+" ) { typ = _Z; // new z value - num = -1; } else if ( nsub==2 && c=='z' ) { - typ = _Z; // z value + typ = _Z; // existing z value num = isub; } else if ( s.substr(0,2)=="nj" ) { - typ = _NJ; // number of spectra in file + typ = _NJ; } else if ( s.substr(0,2)=="ni" ) { - typ = _NI; // number of points in spectrum + typ = _NI; } else if ( c=='x' ) { - typ = _X; // x value + typ = _X; } else if ( c=='y' ) { - typ = _Y; // y value + typ = _Y; } else if ( s.substr(0,2)=="dy" ) { - typ = _DY; // y value - } else if ( c=='f' ) { - typ = _FC; // fit curve + typ = _DY; + } else if ( c=='c' ) { + typ = _C; } else if ( c=='k' ) { - typ = _K; // internal file index + typ = _K; } else if ( c=='j' ) { - typ = _J; // index of current spectrum + typ = _J; } else if ( c=='i' ) { - typ = _I; // index of current point + typ = _I; } else { typ = _NOREF; } @@ -96,10 +95,10 @@ string CVariable::var_info() const case _X: ret = "x"; break; case _Y: ret = "y"; break; case _DY: ret = "dy"; break; - case _FC: ret = "f"; break; + case _C: ret = "c"; break; case _Z: ret = "z"; break; - case _FP: ret = "p"; break; - case _FM: ret = "fm"; break; + case _CP: ret = "p"; break; + case _CQ: ret = "cq"; break; case _K: ret = "k"; break; case _J: ret = "j"; break; case _I: ret = "i"; break; @@ -210,13 +209,13 @@ void CRef::coord( CCoord& ret, uint k_in ) const else throw( "Reference " + var_info() + " not allowed in data file" ); } else if ( fc ) { - if ( typ == _FP ) + if ( typ == _CP ) ret = fc->PCo[num]; - else if ( typ == _FM ) - ret = CCoord("fqi_"+strg(num), ""); // fit quality indicator + else if ( typ == _CQ ) + ret = CCoord("cq"+strg(num), ""); // fit quality indicator else if ( typ == _Z ) ret = fc->ZCo[num]; - else if ( typ == _FC ) + else if ( typ == _C ) ret = CCoord(fc->expr,""); else if ( typ == _NJ ) ret = CCoord("#spectra", ""); @@ -351,11 +350,11 @@ void CRef::ref_val( CResult& ret, const CContext& ctx ) const POlc fc = P2C( f ); if ( fc ) { PCurve cj = fc->VC(j); - if ( typ == _FP ) { + if ( typ == _CP ) { if ( num>= fc->nPar() ) throw( "invalid p ref(" + var_info() + ") in curve file" ); ret.set_d( cj->P[num] ); - } else if ( typ == _FM ) { + } else if ( typ == _CQ ) { if ( num >= CCurve::mQuality ) throw( "invalid fm ref(" + var_info() + ") in curve file" ); ret.set_d( cj->Quality[num] ); @@ -409,7 +408,7 @@ CTree::CTree( PRef& _ref ) : typ(_REF), fun(0), ref(_ref), has_farg(false) {}; CTree::CTree( PRef& _ref, PTree a0 ) - : typ(_FRF), fun(0), ref(_ref) + : typ(_CEV), fun(0), ref(_ref) { arg[0] = a0; has_farg = a0->has_farg; @@ -418,7 +417,7 @@ CTree::CTree( PRef& _ref, PTree a0 ) CTree::CTree( char which ) { if ( which=='t' ) { // function argument - typ = _FARG; + typ = _DUMMY; has_farg = true; } else if ( which=='d' ) { // Dirac delta function centered at 0 typ = _DIRAC; @@ -476,10 +475,10 @@ void CTree::npar_exec( uint *np ) const if ( typ == _OP || typ == _CONV || typ == _DIRAC ) for ( uint iarg=0; iarg<narg; ++iarg ) arg[iarg]->npar_exec( np ); - else if ( typ == _VAL || typ == _FARG || typ == _FRF ) + else if ( typ == _VAL || typ == _DUMMY || typ == _CEV ) ; // do nothing ( leave preset value 0 ? ) else if ( typ == _REF ) { - if ( ref->typ==CRef::_FP ) + if ( ref->typ==CRef::_CP ) *np = max (*np, ref->num+1); } else throw string( "BUG: npar(UNDEF)" ); @@ -509,9 +508,8 @@ void CTree::coord( CCoord& ret, uint k ) const ret = CCoord(strg(val), ""); else if ( typ == _REF ) ref->coord(ret,k); - else if ( typ == _FRF ) { - // ref->coord(ret,k); - ret = CCoord( "f", "" ); // primitiver gehts nicht + else if ( typ == _CEV ) { + ret = CCoord( "c", "" ); // primitiver gehts nicht } else throw string( "BUG: tree::coord(tree_typ=UNDEF)" ); } @@ -536,9 +534,9 @@ string CTree::tree_info() const return "val[" + strg(val) + "]"; else if ( typ == _REF ) return "ref[" + ref->var_info() + "]"; - else if ( typ == _FRF ) - return "frf[" + ref->var_info() + "]"; - else if ( typ == _FARG ) + else if ( typ == _CEV ) + return "c[" + ref->var_info() + "]"; + else if ( typ == _DUMMY ) return "farg"; else throw string( "BUG: tree_info: unexpected tree type" ); @@ -655,7 +653,7 @@ void CTree::tree_val( CResult& ret, const CContext& ctx ) const case _VAL: ret.set_d( val ); break; - case _FARG: + case _DUMMY: if ( !(ctx.fargs) ) throw string( "BUG: tree_val with *fargs=0" ); ret.set_vd( *(ctx.fargs) ); @@ -663,8 +661,8 @@ void CTree::tree_val( CResult& ret, const CContext& ctx ) const case _REF: ref->ref_val( ret, ctx ); break; - case _FRF: - tree_frf( ret, ctx ); + case _CEV: + tree_cev( ret, ctx ); break; default: throw string( "BUG: unexpected tree type" ); @@ -743,7 +741,7 @@ void CTree::tree_op( CResult& ret, const CContext& ctx ) const //! A curve evaluation: fc[k,j](arg). -void CTree::tree_frf( CResult& ret, const CContext& ctx ) const +void CTree::tree_cev( CResult& ret, const CContext& ctx ) const { // evaluate and pack function argument: CResult rarg; @@ -841,7 +839,7 @@ double tree_conv_eval( double tt, void *data ) void CTree::tree_conv( CResult& ret, const CContext& ctx ) const { - // Return values are requested for n values of _FARG ( = t ): + // Return values are requested for n values of _DUMMY ( = t ): if ( !(ctx.fargs) ) throw string( "BUG: treeval(conv,dirac) with *fargs=0" ); uint n = ctx.fargs->size(); diff --git a/pub/src/expr.h b/pub/src/expr.h index 08fb51242782f8695570f89935b0f79a6e4adc62..1470abdde51158b782718c36409bc6db9ce8333d 100644 --- a/pub/src/expr.h +++ b/pub/src/expr.h @@ -59,7 +59,7 @@ class CVariable { _NOREF=0, _X, _Y, _Z, // data _DY, // associated error - _FC, _FP, _FM, // "fit curve", function par's, fit metrics + _C, _CP, _CQ, // curve, curve parameters, curve quality _K, _J, _I, // indices for file, spectrum, point _NJ, _NI // number of spectra in file, points in spectrum }; @@ -74,7 +74,7 @@ class CVariable { bool pointwise() const { return typ==_X || typ==_Y || typ==_DY || typ==_I; }; bool numbered() const { - return typ==_FP || typ==_FM || typ==_Z; }; + return typ==_CP || typ==_CQ || typ==_Z; }; CVariable errvar() const; @@ -106,13 +106,13 @@ class CTree { private: enum TreeTyp { _NOTREE=0, - _OP, // operator (unary, binary, .. according to narg) - _VAL, // numeric value - _FRF, // function reference 'f' - _FARG, // function argument 't' - _REF, // reference - _CONV, // convolution - _DIRAC // Dirac delta function + _OP, // operator (unary, binary, .. according to narg) + _VAL, // numeric value + _CEV, // curve evaluation 'c' + _DUMMY, // curve argument 't' + _REF, // reference + _CONV, // convolution + _DIRAC // Dirac delta function }; TreeTyp typ; double val; @@ -124,7 +124,7 @@ class CTree { void tree_op ( CResult& ret, const CContext& ctx ) const; void tree_conv ( CResult& ret, const CContext& ctx ) const; - void tree_frf ( CResult& ret, const CContext& ctx ) const; + void tree_cev ( CResult& ret, const CContext& ctx ) const; public: bool has_farg; diff --git a/pub/src/opr.cpp b/pub/src/opr.cpp index 5d706d2dd3b00f257a133b841226c60a59dee30f..0559d25eb237f3f0aa3a57de02e22f94c4a7ae6b 100644 --- a/pub/src/opr.cpp +++ b/pub/src/opr.cpp @@ -167,7 +167,7 @@ void NOperate::Pointwise( string llabel ) POlo fout( fin->new_olo() ); - if( lref.typ!=CVariable::_FP ) + if( lref.typ!=CVariable::_CP ) fout->lDoc.push_back( "o" + lref.var_info() + " " + expr); if ( lref.pointwise() && !fd ) @@ -186,7 +186,7 @@ void NOperate::Pointwise( string llabel ) throw string( "no such z coordinate to operate on" ); else fout->ZCo[lref.num] = co; - } else if ( lref.typ==CVariable::_FP ) { + } else if ( lref.typ==CVariable::_CP ) { if( !fc ) continue; // just ignore op operations on data files if( lref.num>=fc->nPar() ) @@ -224,7 +224,7 @@ void NOperate::Pointwise( string llabel ) fout->V[j]->z.push_back( val ); else fout->V[j]->z[lref.num] = val; - } else if ( lref.typ==CVariable::_FP ) { + } else if ( lref.typ==CVariable::_CP ) { double val; T->tree_point_val( &val, 0, k, j ); (P2C(fout))->VC(j)->P[lref.num] = val; diff --git a/pub/src/xax_lex.lpp b/pub/src/xax_lex.lpp index 798d8531fe21c8ea342c0708de70d276631f2398..2bf7813882ce6a3d57c2103630548a52dca407d7 100644 --- a/pub/src/xax_lex.lpp +++ b/pub/src/xax_lex.lpp @@ -45,7 +45,7 @@ EXP [eE]"-"?[0-9]+ xaxlval->v = atof(xaxtext); return NUM; } -[xykji]|n[ij]|z{DIG}+|p{DIG}+|fm{DIG}+ { +[xykji]|n[ij]|z{DIG}+|p{DIG}+|cq{DIG}+ { // printf( "lex: The variable %s\n", xaxtext ); xaxlval->p = (void*) xaxtext; return REF; } @@ -54,10 +54,15 @@ t { // printf( "lex: The formal function argument %s\n", xaxtext ); return ARG; } -f { +c { // printf( "lex: The variable %s\n", xaxtext ); xaxlval->p = (void*) xaxtext; - return FRF; } + return CEV; } + +f { + printf( "WARNING: curve reference letter has changed from f to c\n" ); + xaxlval->p = (void*) xaxtext; + return CEV; } pi { // printf( "lex: pi\n" ); diff --git a/pub/src/xax_yacc.ypp b/pub/src/xax_yacc.ypp index d9d76625c118390f6ab5d113fe7149f1be41695d..0ccbf87497416a57c20f06cb09c32992c9015728 100644 --- a/pub/src/xax_yacc.ypp +++ b/pub/src/xax_yacc.ypp @@ -60,7 +60,7 @@ int xaxlex(YYSTYPE *xaxlval); /* created by lex.l */ %right '^' /* exponentiation */ /* other tokens created by lex.l: */ -%token NUM REF ARG FRF FNCT END CONV DIRAC +%token NUM REF ARG CEV FNCT END CONV DIRAC /* Grammar follows */ @@ -120,9 +120,9 @@ iva: /* indexed variable */ ; ifu: /* indexed function */ - FRF { $$.r = PRef( new CRef( "f" ) ); } - | FRF '[' rex ']' { $$.r = PRef( new CRef( "f", $3.t) ); } - | FRF '[' rex ',' rex ']' { $$.r = PRef( new CRef( "f", $3.t, $5.t) ); } + CEV { $$.r = PRef( new CRef( "c" ) ); } + | CEV '[' rex ']' { $$.r = PRef( new CRef( "c", $3.t) ); } + | CEV '[' rex ',' rex ']' { $$.r = PRef( new CRef( "c", $3.t, $5.t) ); } ; rex: /* reference expression */