Changeset 2180 in Sophya for trunk/SophyaPI
- Timestamp:
- Aug 13, 2002, 12:43:33 PM (23 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/basexecut.cc
r2176 r2180 716 716 } 717 717 718 // >>>>>>>>>>> Calcul d'expression arithmetique 719 else 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 } 718 728 719 729 else { … … 1230 1240 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting"); 1231 1241 1242 1243 kw = "eval"; 1244 usage = "Compute arithmetic expression\n"; 1245 usage += "\n Usage: eval resultvarname arithmetic expression...."; 1246 usage += "\n resultvarname: store result in variable resultvarname"; 1247 usage += "\n - If first character is not alphabetic, just print result"; 1248 usage += "\n arithmetic expression:"; 1249 usage += "\n ex: x + sqrt(y)+z +3.14 (x,y,z are variables)"; 1250 usage += "\n ex: $x + sqrt($y)+$z +3.14 (x,y,z are variables)"; 1251 usage += "\n ex: 360 * M_PI / 180."; 1252 mpiac->RegisterCommand(kw, usage, this, "Expr. Arithmetic"); 1253 1232 1254 } 1233 1255 -
trunk/SophyaPI/PIext/nobjmgr.cc
r2132 r2180 823 823 void NamedObjMgr::ReadObj(PInPersist& s, int num) 824 824 { 825 int_4 i, cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey 825 int_4 i; // $CHECK$ int -> int_4 a cause de TagKey 826 #ifdef SANS_EVOLPLANCK 827 int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey 828 #endif 826 829 int n0, n1; 827 830 bool ok = true; … … 899 902 PPersist* obj=NULL; 900 903 901 PInPersist* ppin ;904 PInPersist* ppin=NULL; 902 905 #ifdef SANS_EVOLPLANCK 903 906 TRY{ … … 932 935 void NamedObjMgr::ReadFits(string const & flnm, string & nobj) 933 936 { 937 938 #ifdef SANS_EVOLPLANCK 934 939 bool ok = false; 935 936 #ifdef SANS_EVOLPLANCK937 940 RzImage* obj=NULL; 938 941 TRY{ … … 1018 1021 1019 1022 bool ok = true; 1020 POutPersist* pout ;1023 POutPersist* pout=NULL; 1021 1024 #ifdef SANS_EVOLPLANCK 1022 1025 TRY{ … … 1051 1054 bool ok = true; 1052 1055 1053 POutPersist* pout ;1056 POutPersist* pout=NULL; 1054 1057 #ifdef SANS_EVOLPLANCK 1055 1058 TRY{ … … 1317 1320 bool errx=false, erry=false, errz=false; 1318 1321 if(err.length()>0) { 1319 for(int i=0;i< err.length();i++)1322 for(int i=0;i<(int_4)err.length();i++) 1320 1323 if (err[i]=='x' || err[i]=='X') errx = true; 1321 1324 else if(err[i]=='y' || err[i]=='Y') erry = true; … … 1416 1419 string title = ny + " (Y) vs. " + nx + " (X)"; 1417 1420 // display 2D 1418 int wrsid =myImgApp->DispScDrawer(vxydrw, title, dopt);1421 myImgApp->DispScDrawer(vxydrw, title, dopt); 1419 1422 1420 1423 return; -
trunk/SophyaPI/PIext/servnobjm.cc
r1971 r2180 313 313 314 314 /* --Methode-- */ 315 void 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-- */ 315 379 void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy, 316 380 string& experrx, string& experry, … … 624 688 for(k=0; k<nt->NEntry(); k++) { 625 689 xn = nt->GetLineD(k); 626 i = xn[0]+0.5;690 i = int(xn[0]+0.5); 627 691 if ( (i < 0) || i >= v1->NElts() ) continue; 628 692 (*v1)(i) = xn[1]; … … 673 737 for(k=0; k<nt->NEntry(); k++) { 674 738 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); 677 741 if ( (ic < 0) || ic >= mtx->NCol() ) continue; 678 742 if ( (jl < 0) || jl >= mtx->NRows() ) continue; … … 850 914 if (k1 < 0) k1 = 0; 851 915 if (k2 < 0) k2 = objnt->NbLines(); 852 if (k2 > objnt->NbLines()) k2 = objnt->NbLines();916 if (k2 > (int_4)objnt->NbLines()) k2 = objnt->NbLines(); 853 917 if (dk <= 0) dk = 1; 854 918 … … 1121 1185 if (k1 < 0) k1 = 0; 1122 1186 if (k2 < 0) k2 = objnt->NbLines(); 1123 if (k2 > objnt->NbLines()) k2 = objnt->NbLines();1187 if (k2 > (int_4)objnt->NbLines()) k2 = objnt->NbLines(); 1124 1188 if (dk <= 0) dk = 1; 1125 1189 -
trunk/SophyaPI/PIext/servnobjm.h
r1971 r2180 62 62 virtual void PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, 63 63 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=""); 64 67 65 68 // Trace d'expression de NTuple, et d'autres objets
Note:
See TracChangeset
for help on using the changeset viewer.