Changeset 2921 in Sophya
- Timestamp:
- Mar 27, 2006, 6:56:24 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/ProgPI/sopiamodule.cc
r2920 r2921 4 4 #include <stdlib.h> 5 5 #include <iostream> 6 #include <ctype.h> 6 7 #include <math.h> 7 8 … … 32 33 33 34 void SophyaFFT_forw(string& nom, string& nomout, string dopt); 34 void SophyaFFT_back(string& nom, string& nomout, string dopt );35 void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt);36 void SophyaFFT_filter(string& nom, string& nomfilter, string dopt);35 void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8=false); 36 // void SophyaFFT_crefilter(string& nomvec, string& nomfilter, string func, string dopt); 37 void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec=false); 37 38 38 39 class sopiamoduleExecutor : public CmdExecutor { … … 196 197 mpiac = omg.GetImgApp()->CmdInterpreter(); 197 198 198 string hgrp = "SophyaCmd";199 199 string kw,usage; 200 201 kw = "powerspec"; 202 usage = "FFT on a vector -> Plots power spectrum "; 203 usage += "\n Usage: powerspec vecName vecFFT [graphic_att] "; 204 mpiac->RegisterCommand(kw, usage, this, hgrp); 200 // ------------- Help group FFT 201 string hgrp = "FFT"; 205 202 206 203 kw = "fftforw"; 207 usage = "FFT on a vector -> Plots power spectrum (same as powerspec)"; 208 usage += "\n Usage: fftforw vecName vecFFT [graphic_att] "; 204 usage = "FFT on a vector -> computes forward Fourier transform"; 205 usage += "\n Usage: fftforw vecSig vecSpec [graphic_att] "; 206 usage += "\n vecSpec = FFTForward(vecSig) "; 207 usage += "\n vecSig: Input data vector of type r_8 or complex<r_8> "; 208 usage += "\n vecSpec: Output data vector of type complex<r_8> "; 209 usage += "\n See also : fftback fftfilter fftfuncfilter "; 209 210 mpiac->RegisterCommand(kw, usage, this, hgrp); 210 211 211 212 kw = "fftback"; 212 usage = "FFT on a vector -> Plots power spectrum"; 213 usage += "\n Usage: fftback vecFFT vecName [graphic_att] "; 214 usage += "\n vecFFT is complex<r_8>"; 215 usage += "\n If vecName already exist, it gives the type(r_8 or complex<r_8>)"; 216 usage += "\n If vecName does not exist, return type is complex<r_8>"; 217 mpiac->RegisterCommand(kw, usage, this, hgrp); 218 219 kw = "crefilter"; 220 usage = "Create a filter for vecFFT (vector complex<r_8>)"; 221 usage += "\n Usage: crefilter vecFFT filter f(x) [graphic_att] "; 213 usage = "FFT on a vector -> computes backward Fourier transform "; 214 usage += "\n Usage: fftback vecSpec vecSig [graphic_att] [C/Z] "; 215 usage += "\n vecSig = FFTBackward(vecSpec) "; 216 usage += "\n vecSpec: Input data vector of type complex<r_8> "; 217 usage += "\n vecSig: Output Data vector of type r_8 (default) "; 218 usage += "\n or complex<r_8> if C/Z specified or "; 219 usage += "\n vecSpec computed by fftforw on a complex vector"; 220 usage += "\n See also : fftforw fftfilter fftfuncfilter "; 222 221 mpiac->RegisterCommand(kw, usage, this, hgrp); 223 222 224 223 kw = "fftfilter"; 225 usage = "Filter (multiply) vecFFT (vector complex<r_8>) by filter (vector<r_8>)"; 226 usage += "\n Usage: fftfilter vecFFT filter [graphic_att] "; 227 mpiac->RegisterCommand(kw, usage, this, hgrp); 224 usage = "Filter (multiply) vecSpec (vector complex<r_8>) by Filter (vector<r_8>)"; 225 usage += "\n Usage: fftfilter vecSpec FilterVec vecFiltSpec [graphic_att] "; 226 usage += "\n vecFiltSpec(i) = vecSpec(i) * complex(FilterVec(i),0) "; 227 usage += "\n See also : fftforw fftbackw fftfuncfilter "; 228 mpiac->RegisterCommand(kw, usage, this, hgrp); 229 230 kw = "fftfuncfilter"; 231 usage = "Filter (multiply) vecSpec (vector complex<r_8>) by FilterFunc(i) "; 232 usage += "\n Usage: fftfilter vecSpec FilterFunc vecFiltSpec [graphic_att] "; 233 usage += "\n vecFiltSpec(i) = vecSpec(i) * complex(FilterFunc(i),0) "; 234 usage += "\n See also : fftforw fftbackw fftfilter "; 235 mpiac->RegisterCommand(kw, usage, this, hgrp); 236 237 //-------------------------- 238 hgrp = "SophyaCmd"; 228 239 229 240 kw = "mollgridsph"; … … 255 266 if (kw == "powerspec" || kw == "fftforw") { 256 267 if (tokens.size() < 2) { 257 cout << "Usage: powerspec nameVec vecFFT [graphic_att]" << endl;268 cout << "Usage: fftforw vecSig vecSpec [graphic_att] " << endl; 258 269 return(0); 259 270 } 260 271 if (tokens.size() < 3) tokens.push_back((string)""); 261 272 SophyaFFT_forw(tokens[0], tokens[1], tokens[2]); 262 273 } 263 274 else if (kw == "fftback") { 264 275 if (tokens.size() < 2) { 265 cout << "Usage: fftback vec FFT nameVec [graphic_att]" << endl;276 cout << "Usage: fftback vecSpec vecSig [graphic_att] [C/Z]" << endl; 266 277 return(0); 267 278 } 279 bool forcez8 = false; 280 if (tokens.size() > 3) { 281 char fcz8 = tolower(tokens[3][0]); 282 if ( (fcz8 == 'c') || (fcz8 == 'z') ) forcez8 = true; 283 } 268 284 if (tokens.size() < 3) tokens.push_back((string)""); 269 SophyaFFT_back(tokens[0], tokens[1], tokens[2] );270 271 else if ( kw == "crefilter") {285 SophyaFFT_back(tokens[0], tokens[1], tokens[2], forcez8); 286 } 287 else if ( (kw == "fftfilter") || (kw == "fftfuncfilter") ) { 272 288 if (tokens.size() < 3) { 273 cout << "Usage: crefilter vecFFT filter f(x)[graphic_att]" << endl;289 cout << "Usage: fftfilter/fftfunfilter vecSpec Filter vecFiltSpec [graphic_att]" << endl; 274 290 return(0); 275 291 } 276 292 if (tokens.size() < 4) tokens.push_back((string)""); 277 SophyaFFT_crefilter(tokens[0], tokens[1], tokens[2], tokens[3]); 278 } 279 else if (kw == "fftfilter") { 280 if (tokens.size() < 2) { 281 cout << "Usage: fftfilter vecFFT filter [graphic_att]" << endl; 282 return(0); 283 } 284 if (tokens.size() < 3) tokens.push_back((string)""); 285 SophyaFFT_filter(tokens[0], tokens[1], tokens[2]); 286 } 293 bool fgvec = false; 294 if (kw == "fftfilter") fgvec = true; 295 SophyaFFT_filter(tokens[0], tokens[1], tokens[2], tokens[3], fgvec); 296 } 287 297 288 298 else if (kw == "prjmoldefval") { … … 292 302 } 293 303 Set_Project_Mol_DefVal(atof(tokens[0].c_str()) ); 294 } 304 } 305 295 306 else if ( (kw == "mollgridsph") || (kw == "mollgrid") ) { 296 307 NamedObjMgr omg; … … 394 405 ffts.FFTForward(*vin, *vout); 395 406 cout<<"...Output TVector<complex<r_8>> of size: "<<vout->NElts()<<endl; 407 vout->Info()["FFTTYPE"]="F:R8->Z8"; 396 408 } else { 397 409 cout<<"SophyaFFT_forw() - Computing FFT of vector TVector<complex<r_8>> of size "<<vinc->NElts()<< endl; 398 410 ffts.FFTForward(*vinc, *vout); 399 411 cout<<"...Output TVector<complex<r_8>> of size: "<<vout->NElts()<<endl; 412 vout->Info()["FFTTYPE"] = "F:Z8->Z8"; 400 413 } 401 414 // cout << " SophyaFFT - FFT done " << endl; … … 410 423 411 424 /* Nouvelle-Fonction */ 412 void SophyaFFT_back(string& nom, string& nomout, string dopt )425 void SophyaFFT_back(string& nom, string& nomout, string dopt, bool forcez8) 413 426 { 414 427 //Timer tm("powerspec"); … … 428 441 TVector< r_8 > * vout = NULL; 429 442 TVector< complex<r_8> > * voutc = NULL; 430 obj=omg.GetObj(nomout); 431 if (obj == NULL) {443 444 if (forcez8 || (vinc->Info().GetS("FFTTYPE") == "F:Z8->Z8") ) { 432 445 voutc = new TVector< complex<r_8> >; 433 } else { 434 vout = dynamic_cast<TVector<r_8>*>(obj); 435 if(vout==NULL) voutc = dynamic_cast<TVector< complex<r_8> >*>(obj); 436 } 437 if(vout==NULL && voutc==NULL) { 438 cout << "SophyaFFT_back() Error , Output objet n'est pas un vecteur r_8 ou complex<r_8>" << endl; 439 return; 446 } 447 else { 448 vout = new TVector< r_8 >; 440 449 } 441 450 … … 445 454 ffts.FFTBackward(*vinc, *vout); 446 455 cout<<"...Output TVector<r_8> of size: "<<vout->NElts()<<endl; 456 vout->Info()["FFTTYPE"]="B:Z8->R8"; 447 457 omg.AddObj(vout, nomout); 448 458 } else { 449 459 ffts.FFTBackward(*vinc, *voutc); 450 460 cout<<"...Output TVector<complex<r_8>> of size: "<<voutc->NElts()<<endl; 461 voutc->Info()["FFTTYPE"]="B:Z8->Z8"; 451 462 omg.AddObj(voutc, nomout); 452 463 } … … 471 482 return; 472 483 } 473 int n = vfft->Size();484 sa_size_t n = vfft->Size(); 474 485 if(n<=0) return; 475 486 … … 479 490 480 491 /* Nouvelle-Fonction */ 481 void SophyaFFT_filter(string& nom, string& nomfilter, string dopt)492 void SophyaFFT_filter(string& nom, string& filt, string& outvec, string dopt, bool fgvec) 482 493 { 483 494 NamedObjMgr omg; … … 487 498 return; 488 499 } 489 500 TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj); 501 if(vfft == NULL) { 502 cout<<"SophyaFFT_filter() Error , Objet "<<nom<<" n'est pas un Tvector<complex<r_8>>"<< endl; 503 return; 504 } 505 int n = vfft->Size(); 506 if(n<=0) { 507 cout<<"SophyaFFT_filter() Error , vector size = 0 " << endl; 508 return; 509 } 510 511 string nomfilter = "/autoc/fft_filter"; 512 if (fgvec) { 513 nomfilter = filt; 514 cout<<"SophyaFFT_filter(): using vector " << filt << " for filtering spectrum ..." << endl; 515 } 516 else { 517 cout<<"SophyaFFT_filter(): Creating filter vector "<<nomfilter 518 <<" from function " << filt << endl; 519 string fcrdopt = "nodisp"; 520 omg.GetServiceObj()->PlotFunc(filt, nomfilter, 0., (double)n, n, fcrdopt); 521 } 490 522 AnyDataObj* objfilter=omg.GetObj(nomfilter); 491 523 if(objfilter == NULL) { … … 494 526 } 495 527 496 TVector< complex<r_8> >* vfft = dynamic_cast<TVector< complex<r_8> >*>(obj);497 if(vfft == NULL) {498 cout<<"SophyaFFT_filter() Error , Objet "<<nom<<" n'est pas un Tvector<complex<r_8>>"<< endl;499 return;500 }501 502 528 TVector<r_8>* vfilter = dynamic_cast<TVector<r_8>*>(objfilter); 503 529 if(vfft == NULL) { … … 506 532 } 507 533 508 int n = (vfilter->Size()<vfft->Size()) ? vfilter->Size(): vfft->Size(); 509 cout<<"...filtering from 0 to "<<n<<endl; 510 for(int i=0;i<n;i++) (*vfft)(i) *= (*vfilter)(i); 511 512 if(dopt.size()>0) omg.DisplayObj(nom,dopt); 534 n = (vfilter->Size()<vfft->Size()) ? vfilter->Size(): vfft->Size(); 535 536 cout<<" SophyaFFT_filter(): filtering from 0 to "<<n<<endl; 537 TVector< complex<r_8> > * filtfft = new TVector< complex<r_8> >(*vfft, false); 538 for(int i=0;i<n;i++) (*filtfft)(i) *= (*vfilter)(i); 539 540 cout<<"SophyaFFT_filter(): Adding obj: " << outvec << endl; 541 omg.AddObj(filtfft, outvec); 542 omg.DisplayObj(outvec, dopt); 513 543 return; 514 544 }
Note:
See TracChangeset
for help on using the changeset viewer.