Changeset 2180 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Aug 13, 2002, 12:43:33 PM (23 years ago)
Author:
cmv
Message:

command eval dans spiapp cmv 13/8/02

Location:
trunk/SophyaPI/PIext
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/basexecut.cc

    r2176 r2180  
    716716  }
    717717
     718// >>>>>>>>>>>  Calcul d'expression arithmetique
     719else if ( (kw == "eval") ) {
     720  if(tokens.size()<2)
     721    {cout<<"Usage: eval resultvarname arithmetic expression...."<<endl; return(0);}
     722  string expval = "";
     723  for(unsigned int i=1;i<tokens.size();i++) expval+=tokens[i];
     724  string resultvarname = "";
     725  if(isalpha(tokens[0][0])) resultvarname=tokens[0];
     726  mObjMgr->GetServiceObj()->ExpVal(expval,resultvarname);
     727  }
    718728
    719729else  {
     
    12301240mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
    12311241
     1242
     1243kw = "eval";
     1244usage = "Compute arithmetic expression\n";
     1245usage += "\n Usage: eval resultvarname arithmetic expression....";
     1246usage += "\n  resultvarname: store result in variable resultvarname";
     1247usage += "\n    - If first character is not alphabetic, just print result";
     1248usage += "\n  arithmetic expression:";
     1249usage += "\n      ex: x + sqrt(y)+z +3.14    (x,y,z are variables)";
     1250usage += "\n      ex: $x + sqrt($y)+$z +3.14 (x,y,z are variables)";
     1251usage += "\n      ex: 360 * M_PI / 180.";
     1252mpiac->RegisterCommand(kw, usage, this, "Expr. Arithmetic");
     1253
    12321254}
    12331255
  • trunk/SophyaPI/PIext/nobjmgr.cc

    r2132 r2180  
    823823void NamedObjMgr::ReadObj(PInPersist& s, int num)
    824824{
    825 int_4 i, cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
     825int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
     826#ifdef SANS_EVOLPLANCK
     827int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
     828#endif
    826829int n0, n1;
    827830bool ok = true;
     
    899902PPersist* obj=NULL;
    900903
    901 PInPersist* ppin;
     904PInPersist* ppin=NULL;
    902905#ifdef SANS_EVOLPLANCK
    903906TRY{
     
    932935void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
    933936{
     937
     938#ifdef SANS_EVOLPLANCK
    934939bool ok = false;
    935 
    936 #ifdef SANS_EVOLPLANCK
    937940RzImage* obj=NULL;
    938941TRY{
     
    10181021
    10191022bool ok = true;
    1020 POutPersist* pout;
     1023POutPersist* pout=NULL;
    10211024#ifdef SANS_EVOLPLANCK
    10221025TRY{
     
    10511054bool ok = true;
    10521055
    1053 POutPersist* pout;
     1056POutPersist* pout=NULL;
    10541057#ifdef SANS_EVOLPLANCK
    10551058TRY{
     
    13171320bool errx=false, erry=false, errz=false;
    13181321if(err.length()>0) {
    1319   for(int i=0;i<err.length();i++)
     1322  for(int i=0;i<(int_4)err.length();i++)
    13201323    if     (err[i]=='x' || err[i]=='X') errx = true;
    13211324    else if(err[i]=='y' || err[i]=='Y') erry = true;
     
    14161419string title = ny + " (Y) vs. " + nx + " (X)";
    14171420// display 2D
    1418 int wrsid = myImgApp->DispScDrawer(vxydrw, title, dopt);
     1421myImgApp->DispScDrawer(vxydrw, title, dopt);
    14191422
    14201423return;
  • trunk/SophyaPI/PIext/servnobjm.cc

    r1971 r2180  
    313313
    314314/* --Methode-- */
     315void Services2NObjMgr::ExpVal(string expval,string resultvarname)
     316{
     317 // Fill C-file to be executed
     318 FILE *fip;
     319 string func = "eval_pia_dl_func";
     320 string fname = TmpDir + func; fname += ".c";
     321 string  cmd = "rm -f " + fname; system(cmd.c_str());
     322 if((fip=fopen(fname.c_str(), "w"))==NULL) {
     323   cout << "Services2NObjMgr/EvalExp_Error: fopen("<<fname<<")"<<endl;
     324   return;
     325 }
     326 fprintf(fip,"#include <math.h>\n");
     327 fprintf(fip,"double %s(double ___dummy_variable___) \n{\n",func.c_str());
     328 // Add all variables already declared
     329 DVList& varlist = mOmg->GetVarList();
     330 DVList::ValList::const_iterator it;
     331 for(it = varlist.Begin(); it != varlist.End(); it++) {
     332#ifdef SANS_EVOLPLANCK
     333   MuTyV mtv = (*it).second;
     334   double value = (double)(mtv);
     335#else
     336   double value = (double)((*it).second.elval);
     337#endif
     338   string name_var = (*it).first;
     339   fprintf(fip,"double %s = %.17f;\n",name_var.c_str(),value);
     340 }
     341 fprintf(fip,"return %s;\n}\n",expval.c_str());
     342 fclose(fip);
     343
     344 // Dynamically link function
     345 DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname,func);
     346 if(!f) {
     347   cout<<"Services2NObjMgr/EvalExp_Error: linking DlFunctionOfX"<<endl;
     348   cout<<"...expval = "<<expval<<endl;
     349   return;
     350 }
     351
     352 // Evaluate function and close dynamic link
     353 double result;
     354 try {
     355   result = f(0.);
     356   CloseDLL();
     357 } catch ( ... ) {
     358   cout<<"Services2NObjMgr/EvalExp_Error: Arithmetic exception"<<endl;
     359   CloseDLL();
     360   return;
     361 }
     362
     363 // Eventually store the result into variable or just print it
     364 if(resultvarname.size()>0) {
     365   if(mOmg->HasVar(resultvarname)) mOmg->DeleteVar(resultvarname);
     366   char str[512];
     367   if(result==0.) sprintf(str,"%f",result);
     368   else {
     369     double lr = log10(fabs(result));
     370     if(lr>-17. && lr<17.) sprintf(str,"%17f",result);
     371     else                   sprintf(str,"%.17e",result);
     372   }
     373   mOmg->SetVar(resultvarname,(string)str);
     374 } else cout<<result<<" = "<<expval<<endl;
     375
     376}
     377
     378/* --Methode-- */
    315379void Services2NObjMgr::DisplayPoints2D(string& nom,  string& expx, string& expy,
    316380                                       string& experrx, string& experry,
     
    624688  for(k=0; k<nt->NEntry(); k++)    {
    625689    xn = nt->GetLineD(k);
    626     i = xn[0]+0.5;
     690    i = int(xn[0]+0.5);
    627691    if ( (i < 0) || i >= v1->NElts() ) continue;
    628692    (*v1)(i) = xn[1];
     
    673737  for(k=0; k<nt->NEntry(); k++)    {
    674738    xn = nt->GetLineD(k);
    675     ic = xn[0]+0.5;
    676     jl = xn[1]+0.5;
     739    ic = int(xn[0]+0.5);
     740    jl = int(xn[1]+0.5);
    677741    if ( (ic < 0) || ic >= mtx->NCol() ) continue;
    678742    if ( (jl < 0) || jl >= mtx->NRows() ) continue;
     
    850914if (k1 < 0) k1 = 0;
    851915if (k2 < 0) k2 = objnt->NbLines();
    852 if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
     916if (k2 > (int_4)objnt->NbLines()) k2 = objnt->NbLines();
    853917if (dk <= 0) dk = 1;
    854918
     
    11211185if (k1 < 0) k1 = 0;
    11221186if (k2 < 0) k2 = objnt->NbLines();
    1123 if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
     1187if (k2 > (int_4)objnt->NbLines()) k2 = objnt->NbLines();
    11241188if (dk <= 0) dk = 1;
    11251189
  • trunk/SophyaPI/PIext/servnobjm.h

    r1971 r2180  
    6262  virtual void  PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax,
    6363                           double ymin, double ymax, int npx=50, int npy=50, string dopt="");
     64
     65// Calcul d'expression arithmetique
     66  virtual void ExpVal(string expval,string resultvarname="");
    6467
    6568//  Trace d'expression de NTuple, et d'autres objets
Note: See TracChangeset for help on using the changeset viewer.