Changeset 2180 in Sophya for trunk/SophyaPI/PIext/servnobjm.cc
- Timestamp:
- Aug 13, 2002, 12:43:33 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.