Changeset 293 in Sophya for trunk/SophyaPI
- Timestamp:
- May 11, 1999, 6:04:58 AM (26 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/dlftypes.h
r171 r293 18 18 typedef int (* PlotExprFunc) (float* x, float* rx, float* ry, float* rz, float* wt); 19 19 typedef void (* DlUserProcFunction) (vector<string>& args); 20 typedef void (* DlFunction) (); 21 typedef void (* DlModuleInitEndFunction) (); 20 22 21 23 #endif -
trunk/SophyaPI/PIext/exclude
r165 r293 1 modrecst.cc -
trunk/SophyaPI/PIext/nobjmgr.cc
r179 r293 15 15 #include "strutil.h" 16 16 #include "datatypes.h" 17 #include "fitsimage.h"18 17 19 18 #include "nobjmgr.h" … … 26 25 #include "matrix.h" 27 26 #include "cvector.h" 28 #include "zfidu.h" 29 30 #include "fft.h" 27 28 // EVOL-PLANCK 29 #ifdef SANS_EVOLPLANCK 30 #include "fitsimage.h" 31 #include "zfidu.h" 32 #endif 33 31 34 #include "fct1dfit.h" 32 35 #include "fct2dfit.h" … … 45 48 46 49 // Si le module StarReco++ a ete compile (Pour les StarList, Transfo, etc ... 47 #if ndef SANS_StarReco50 #ifdef SANS_EVOLPLANCK 48 51 #include "pistlist.h" 49 52 #include "transfo.h" … … 388 391 TRY{ 389 392 // obj = RzReadFits((char*)flnm.c_str(), ImgOffX, ImgOffY, ImgSizX, ImgSizY, ImgBitSgn); 393 #ifdef SANS_EVOLPLANCK 390 394 obj = RzReadFits((char*)flnm.c_str()); 395 #else 396 printf("NamedObjMgr::ReadFITS( NON-Disponible EVOL-PLANCK) \n"); 397 obj = NULL; 398 #endif 391 399 if (obj == NULL) ok = false; 392 400 } CATCH(merr) { … … 438 446 void NamedObjMgr::SaveFits(string const& nom, string const & flnm) 439 447 { 448 449 #ifndef SANS_EVOLPLANCK 450 printf("NamedObjMgr::SaveFITS( NON-Disponible EVOL-PLANCK) \n"); 451 return; 452 453 #else 454 440 455 PPersist* obj=NULL; 441 456 obj = GetObj(nom); 442 457 if (obj == NULL) return; 443 444 458 int cid = obj->ClassId(); 445 459 if ( (cid < ClassId_Image) && ( cid > ClassId_Image+kr_8) ) { … … 485 499 } ENDTRY; 486 500 501 #endif 502 487 503 return; 488 504 } … … 580 596 break; 581 597 598 #ifdef SANS_EVOLPLANCK 582 599 case ClassId_ZFidu : 583 600 ((ZFidu*)obj)->Print(); 584 601 break; 585 602 586 #ifndef SANS_StarReco587 603 case ClassId_StarList : 588 604 ((StarList*)obj)->Print(10, 1, 50); … … 710 726 break; 711 727 728 #ifdef SANS_EVOLPLANCK 712 729 case ClassId_ZFidu : 713 730 { … … 723 740 } 724 741 725 #ifndef SANS_StarReco726 742 case ClassId_StarList : 727 743 { … … 1333 1349 ndata=((RzImage*)obj)->XSize()*((RzImage*)obj)->YSize(); 1334 1350 break; 1335 #if ndef SANS_StarReco1351 #ifdef SANS_EVOLPLANCK 1336 1352 case ClassId_StarList : 1337 1353 ndata=((StarList*)obj)->NbStars(); … … 1392 1408 if (!myImgApp) return; 1393 1409 1394 cmd = "rm " + fname;1410 cmd = "rm -f " + fname; 1395 1411 rc = system(cmd.c_str()); 1396 1412 printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc); … … 2010 2026 } 2011 2027 2012 /* --Methode-- */2013 void NamedObjMgr::FFT(string const& nom, string dopt)2014 {2015 PPersist* obj=GetObj(nom);2016 if (obj == NULL) {2017 cout << "NamedObjMgr::FFT() Error , Pas d'objet de nom " << nom << endl;2018 return;2019 }2020 if (!myImgApp) return;2021 2022 int cid = obj->ClassId();2023 if (cid != ClassId_Vector) {2024 string ctyp = servnobjm->PClassIdToClassName(cid);2025 cout << "NamedObjMgr::FFT() Error , Objet n'est pas un vecteur " << ctyp << endl;2026 return;2027 }2028 2029 FFT1 fft( *((Vector*)obj) );2030 2031 if (fft.NData() < 1) return;2032 2033 char* ntn[3] = {"refc", "imfc", "pfc"};2034 NTuple* nt = new NTuple(3,ntn); // Creation NTuple2035 Vector* vf = new Vector(fft.NData()/2);2036 2037 float xnt[3];2038 double pf;2039 for(int k=0; k<fft.NData()/2; k++) {2040 xnt[0] = fft.ReF(k); xnt[1] = fft.ImF(k);2041 pf = (xnt[0]*xnt[0]+xnt[1]*xnt[1]);2042 if (pf >= 0.) pf = sqrt(pf);2043 xnt[2] = pf; (*vf)(k) = pf;2044 nt->Fill(xnt);2045 }2046 2047 P1DArrayAdapter* vya = new POVectorAdapter(vf, true);2048 // vya->DefineXCoordinate(xmin, xmax); a determiner2049 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;2050 bool fgsr = true;2051 dopt = "thinline," + dopt;2052 int opt = servnobjm->DecodeDispOption(dopt, fgsr);2053 myImgApp->DispScDrawer(dr, nom, opt);2054 if (fgsr) myImgApp->RestoreGraphicAtt();2055 2056 return;2057 } -
trunk/SophyaPI/PIext/nobjmgr.h
r165 r293 87 87 string par,string step,string min,string max,string opt); 88 88 89 // Calcul de la transforme de Fourier - A titre d'exemple90 virtual void FFT(string const& nom, string dopt);91 89 92 90 // Acces au PIApplication et a la classe de service -
trunk/SophyaPI/PIext/piacmd.cc
r210 r293 1 #include "piacmd.h" 1 2 #include <stdio.h> 2 3 #include <stdlib.h> 3 4 #include <math.h> 4 5 5 #include <iostream.h> 6 #include <string> 7 #include <vector> 8 #include <map> 9 #if defined(__KCC__) 10 using std::string ; 11 #include <vector.h> 12 #include <map.h> 13 #endif 14 6 #include "basexecut.h" 7 8 #include "pdlmgr.h" 15 9 #include "ctimer.h" 16 10 // #include "dlftypes.h" 11 12 #include "pistdimgapp.h" 17 13 #include "nobjmgr.h" 18 #include "piacmd.h" 19 #include "pistdimgapp.h" 20 21 #include "histos.h" 22 #include "histos2.h" 23 #include "hisprof.h" 24 #include "ntuple.h" 25 #include "generaldata.h" 26 27 28 // Pour le decoupage des commandes en lignes 29 typedef vector<string> cmdtok; 30 31 // Fonction pour faire le Fit de PSF sur image 32 static int FitPSFImg(cmdtok& tokens); 33 static int Photom_Ouv(cmdtok& tokens); 34 35 14 15 #include PISTDWDG_H 16 #include PILIST_H 17 18 // ------------------------------------------------------------ 19 // Gestion d'une fenetre d'aide interactive 20 // ------------------------------------------------------------ 21 22 class PIAHelpWind : public PIWindow { 23 public : 24 PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd); 25 virtual ~PIAHelpWind(); 26 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL); 27 inline void AddHelpItem(const char * hitem) 28 { mNitem++; hitemlist->AppendItem(hitem, 1000+mNitem); } 29 protected : 30 PIStdImgApp* dap; 31 PIACmd* piac; 32 int mNitem; 33 PIList* hitemlist; 34 PIButton * mBut; 35 PILabel * mLab; 36 PIText* mTxt; 37 }; 38 39 /* --Methode-- */ 40 PIAHelpWind::PIAHelpWind(PIStdImgApp *par, PIACmd* piacmd) 41 : PIWindow((PIMsgHandler *)par, "Help-PIApp", PIWK_normal, 400, 300, 100, 350) 42 { 43 dap = par; 44 piac = piacmd; 45 mNitem = 0; 46 SetMsg(777); 47 48 int bsx, bsy; 49 int tsx, tsy; 50 int spx, spy; 51 PIApplicationPrefCompSize(bsx, bsy); 52 spx = bsx/6; spy = bsy/6; 53 tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy; 54 SetSize(tsx,tsy); 55 hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-2*spy, spx/2, spy); 56 hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 57 // hitemlist->SetBorderWidth(2); 58 mTxt = new PIText(this, "helptext", bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy); 59 mTxt->SetMutiLineMode(true); 60 mTxt->SetTextEditable(false); 61 mTxt->SetText(""); 62 mTxt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 63 mLab = new PILabel(this, "helpitem", bsx*4, bsy, bsx*2.5+2*spx, tsy-spy-bsy); 64 mLab->SetBorderWidth(1); 65 mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 66 mLab->SetLabel(""); 67 mBut = new PIButton(this, "Close", 700, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy); 68 mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 69 } 70 71 /* --Methode-- */ 72 PIAHelpWind::~PIAHelpWind() 73 { 74 delete hitemlist; 75 delete mTxt; 76 delete mLab; 77 delete mBut; 78 } 79 80 /* --Methode-- */ 81 void PIAHelpWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/) 82 { 83 PIMessage um = UserMsg(msg); 84 if (((um == 777) && (ModMsg(msg) == PIMsg_Close)) || (um == 700) ) { 85 Hide(); 86 return; 87 } 88 else if ( (um > 1000) && (sender == hitemlist)) { 89 string s = hitemlist->GetSelectionStr(); 90 mTxt->SetText(piac->GetUsage(s)); 91 mLab->SetLabel(s); 92 } 93 } 94 95 96 static PIACmd* curpiacmd = NULL; 36 97 /* --Methode-- */ 37 98 PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app) 38 99 { 39 if (omg) { mOmg= false; mObjMgr = omg; } 40 else { mObjMgr = new NamedObjMgr; mOmg = true; } 100 mObjMgr = omg; 41 101 mImgApp = app; 42 102 system("cp history.pic hisold.pic"); … … 44 104 trace = false; timing = false; 45 105 gltimer = NULL; 46 dynlink = NULL; 106 107 helpwin = new PIAHelpWind(app, this); 108 109 string kw = "piacmd"; 110 string usage; 111 usage = ">>> (piacmd) Interpreter's keywords : \n"; 112 usage += " timingon timingoff traceon traceoff \n"; 113 usage += " set unset listvar listcommands exec shell \n"; 114 usage += " > set varname 'string' # To set a variable, $varname \n"; 115 usage += " > unset varname # clear variable definition \n"; 116 usage += " > listvars # List of variable names and values \n"; 117 usage += " > listcommands # List of all known commands \n"; 118 usage += " > exec filename # Execute commands from file \n"; 119 usage += " > shell comand_string # Execute shell command \n"; 120 usage += " > help <command_name> # <command_name> usage info \n"; 121 usage += " > helpwindow # Displays help window \n"; 122 RegisterCommand(kw, usage, NULL); 123 124 basexec = new PIABaseExecutor(this, omg, app); 125 AddInterpreter(this); 126 curcmdi = this; 47 127 } 48 128 … … 50 130 PIACmd::~PIACmd() 51 131 { 52 if (mOmg) delete mObjMgr;53 132 hist.close(); 54 133 if (gltimer) { delete gltimer; gltimer = NULL; } 55 } 56 57 /* --Methode-- */ 58 int PIACmd::Exec(string& file) 59 { 60 char line_buff[512]; 61 FILE *fip; 62 63 if ( (fip = fopen(file.c_str(),"r")) == NULL ) { 64 cerr << "PIACmd::Exec() Error opening file " << file << endl; 65 hist << "##! PIACmd::Exec() Error opening file " << file << endl; 66 return(0); 67 } 68 69 hist << "### Executing commands from " << file << endl; 70 if (trace) { 71 mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta); 72 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta); 73 mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta); 74 } 75 76 while (fgets(line_buff,511,fip) != NULL) 77 { 78 if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta); 79 line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */ 80 string line(line_buff); 81 Do(line); 82 } 83 hist << "### End of Exec( " << file << " ) " << endl; 84 if (trace) { 85 mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta); 86 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta); 87 mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta); 88 } 89 90 return(0); 91 } 92 93 /* --Methode-- */ 94 int PIACmd::Do(string& s) 134 Modmap::iterator it; 135 for(it = modmap.begin(); it != modmap.end(); it++) { 136 string name = (*it).first + "_end"; 137 DlModuleInitEndFunction fend = (*it).second->GetFunction(name); 138 if (fend) fend(); 139 delete (*it).second; 140 } 141 delete helpwin; 142 if (curpiacmd == this) curpiacmd = NULL; 143 } 144 145 /* --Methode-- */ 146 PIACmd* PIACmd::GetInterpreter() 147 { 148 return(curpiacmd); 149 } 150 151 /* --Methode-- */ 152 string PIACmd::Name() 153 { 154 return("piacmd"); 155 } 156 157 /* --Methode-- */ 158 void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce) 159 { 160 // if (!ce) return; 161 cmdex cme; 162 cme.us = usage; 163 cme.cex = ce; 164 cmdexmap[keyw] = cme; 165 if (helpwin) helpwin->AddHelpItem(keyw.c_str()); 166 } 167 168 /* --Methode-- */ 169 void PIACmd::LoadModule(string& fnameso, string& name) 170 { 171 PDynLinkMgr * dynlink = new PDynLinkMgr(fnameso, false); 172 if (dynlink == NULL) { 173 cerr << "PIACmd/LoadModule_Error: Pb opening SO " << fnameso << endl; 174 return; 175 } 176 string fname = name + "_init"; 177 DlModuleInitEndFunction finit = dynlink->GetFunction(fname); 178 if (!finit) { 179 cerr << "PIACmd/LoadModule_Error: Pb linking " << fname << endl; 180 return; 181 } 182 cout << "PIACmd/LoadModule_Info: Initialisation module" << name 183 << " " << fname << "() ..." << endl; 184 finit(); 185 modmap[name] = dynlink; 186 return; 187 } 188 189 /* --Methode-- */ 190 void PIACmd::AddInterpreter(CmdInterpreter * cl) 191 { 192 if (!cl) return; 193 interpmap[cl->Name()] = cl; 194 } 195 196 /* --Methode-- */ 197 void PIACmd::SelInterpreter(string& name) 198 { 199 InterpMap::iterator it = interpmap.find(name); 200 if (it == interpmap.end()) return; 201 curcmdi = (*it).second; 202 } 203 204 205 // Pour le decoupage des commandes en lignes 206 typedef vector<string> cmdtok; 207 208 /* --Methode-- */ 209 int PIACmd::Interpret(string& s) 95 210 { 96 211 … … 101 216 102 217 if (s[0] == '#') { 103 cout << "PIACmd:: Do() Comment-Line:" << s << endl;218 cout << "PIACmd::Interpret() Comment-Line:" << s << endl; 104 219 return(0); 105 220 } … … 125 240 126 241 for(int k=0; k<tokens.size(); k++) { // On remplace les $varname par la valeur de la variable 127 if ((tokens[k])[0] != '$') continue;128 CmdVarList::iterator it = mVars.find(tokens[k].substr(1));129 if (it != mVars.end()) tokens[k] = (*it).second;130 }242 if ((tokens[k])[0] != '$') continue; 243 CmdVarList::iterator it = mVars.find(tokens[k].substr(1)); 244 if (it != mVars.end()) tokens[k] = (*it).second; 245 } 131 246 132 247 // cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl; … … 135 250 136 251 // >>>>>>>>>>> Commande d'interpreteur 137 if (kw == "help") { 138 cout << "\n PIACmd::Do() ----- Help : Liste des commandes ------------ \n"; 139 cout << "help shelp exec set listvars traceon traceoff \n"; 140 cout << "timingon timingoff shell \n"; 141 cout << "link call zone grwin gratt stacknext \n" ; 142 cout << "openppf saveall listobjs openfits savefits \n"; 143 cout << "print rename del delobjs \n"; 144 cout << "newh1d newh2d newprof newgfd func func2d \n" ; 145 cout << "disp surf nt2d nt3d gfd2d gfd3d \n" ; 146 cout << "plot2d plot3d projh1d projh2d projprof \n"; 147 cout << "fillvec fillnt fillgd1 fillgd2 fft fit fitpsf aper\n"; 148 cout << "*** Commande sans args -> liste d'arguments\n"; 149 cout << "*** dopt: DisplayOption = next/same/win/stack,color,... \n"; 150 cout << "*** $varname remplace par la valeur de la variable varname\n" << endl; 151 } 152 153 else if (kw == "shelp" ) { 154 cout << "\n PIACmd::Do() ------------- SHelp ------------ " << endl; 155 cout << "exec filename -- set varname string -- clr varname -- listvars \n"; 156 cout << "traceon/off -- timingon/off -- shell cmdline\n"; 157 cout << "link fnameso f1 [f2 f3] -- call userf [arg1 arg2 ...]\n"; 158 cout << "zone nx ny -- newwin nx ny -- gratt attributes_list -- stacknext \n"; 159 cout << "openppf file -- saveall file -- listobjs \n"; 160 cout << "openfits file -- savefits nomobj file \n"; 161 cout << "print nomobj -- rename nomobj nomnew -- del nomobj -- delobjs pattern (*,?) \n"; 162 cout << "newh1d nomh xmin xmax nbin -- newh2d nomh xmin xmax nbinx ymin ymax nbiny\n"; 163 cout << "newprof nomh xmin xmax nbin [ymin ymax] \n"; 164 cout << "newgfd nomgfd nvar nalloc [errx(0/1)]\n"; 165 cout << "func expfunc xmin xmax npt opt\n"; 166 cout << "func2d expfunc xmin xmax nptx ymin ymax npty opt\n"; 167 cout << "disp nomobj opt -- surf nomobj opt\n"; 168 cout << "nt2d nomobj varx vary errx erry opt\n"; 169 cout << "nt3d nomobj varx vary varz errx erry errz dopt\n"; 170 cout << "gfd2d nomobj numvarx erreur=(x y xy) opt\n"; 171 cout << "gfd3d nomobj numvarx numvary erreur=(x y z xy xz yz xyz) opt\n"; 172 cout << "plot2d nomobj expx expy [experrx experry] expcut dopt\n"; 173 cout << "plot3d nomobj expx expy expz expcut dopt\n"; 174 cout << "projh1d nomobj expx expwt expcut nomh1 dopt\n"; 175 cout << "projh2d nomobj expx expy expwt expcut nomh2 dopt\n"; 176 cout << "projprof nomobj expx expy expwt expcut nomprof dopt\n"; 177 cout << "fillnt nomobj expx expy expz expt expcut nomnt dopt\n"; 178 cout << "fillvec nomobj expx expcut nomvec dopt\n"; 179 cout << "fillgd1 nomobj expx expy experry expcut nomgfd\n"; 180 cout << "fillgd2 nomobj expx expy expz experrz expcut nomgfd\n"; 181 cout << "fft nomobj dopt\n"; 182 cout << "fit nomobj func [p:p1,.,pn s:s1,.,sn m:m1,.,mn M:M1,.,Mn I:i1,i2 o:... o:...]\n"; 183 cout << "fitpsf psf_typ [options_fit]\n"; 184 cout << "aper fond_typ [options_calcul]\n"; 185 } 252 if (kw == "helpwindow") ShowHelpWindow(); 253 else if (kw == "help") { 254 if (tokens.size() > 0) { 255 CmdExmap::iterator it = cmdexmap.find(tokens[0]); 256 if (it == cmdexmap.end()) cout << "Nothing known about " << tokens[0] << " ?? " << endl; 257 else cout << (*it).second.us << endl; 258 } 259 else { 260 cout << "\n -------- PIACmd::Interpret() ::::: Help ------------ \n"; 261 cout << ">>> Interpreter's keywords : \n"; 262 cout << " timingon timingoff traceon traceoff \n"; 263 cout << " set unset listvar listcommands exec shell \n"; 264 cout << " > set varname 'string' # To set a variable, $varname \n"; 265 cout << " > unset varname # clear variable definition \n"; 266 cout << " > listvars # List of variable names and values \n"; 267 cout << " > listcommands # List of all known commands \n"; 268 cout << " > exec filename # Execute commands from file \n"; 269 cout << " > shell comand_string # Execute shell command \n"; 270 cout << " > help <command_name> # <command_name> usage info \n"; 271 cout << " > helpwindow # Displays help window \n" << endl; 272 } 273 } 274 186 275 187 276 else if (kw == "set") { 188 if (tokens.size() < 2) { cout << "PIACmd:: Do() Usage: set varname string" << endl; return(0); }277 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); } 189 278 mVars[tokens[0]] = tokens[1]; 190 279 } 191 else if (kw == " clr") {192 if (tokens.size() < 1) { cout << "PIACmd:: Do() Usage: clrvarname" << endl; return(0); }280 else if (kw == "unset") { 281 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); } 193 282 CmdVarList::iterator it = mVars.find(tokens[0]); 194 283 if (it != mVars.end()) mVars.erase(it); 195 else cerr << "PIACmd:: Do() Pas de variable de nom" << tokens[0] << endl;284 else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl; 196 285 } 197 286 else if (kw == "listvars") { 198 cout << "PIACmd:: Do() Variable List , VarName = Value \n";287 cout << "PIACmd::Interpret() Variable List , VarName = Value \n"; 199 288 CmdVarList::iterator it; 200 289 for(it = mVars.begin(); it != mVars.end(); it++) … … 202 291 cout << endl; 203 292 } 204 else if (kw == "traceon") { cout << "PIACmd::Do() -> Trace ON mode " << endl; trace = true; } 205 else if (kw == "traceoff") { cout << "PIACmd::Do() -> Trace OFF mode " << endl; trace = false; } 293 else if (kw == "listvars") { 294 cout << "---- PIACmd::Interpret() Command keyword List ----- \n"; 295 CmdExmap::iterator it; 296 int kc = 0; 297 for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) { 298 cout << (*it).first << " "; 299 kc++; 300 if (kc >= 5) { cout << "\n"; kc = 0; } 301 } 302 cout << endl; 303 } 304 else if (kw == "traceon") { cout << "PIACmd::Interpret() -> Trace ON mode " << endl; trace = true; } 305 else if (kw == "traceoff") { cout << "PIACmd::Interpret() -> Trace OFF mode " << endl; trace = false; } 206 306 else if (kw == "timingon") { 207 cout << "PIACmd::Do() -> Timing ON mode " << endl; 208 if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true; } 307 cout << "PIACmd::Interpret() -> Timing ON mode " << endl; 308 if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true; 309 } 209 310 else if (kw == "timingoff") { 210 cout << "PIACmd::Do() -> Timing OFF mode " << endl; 211 if (gltimer) delete gltimer; gltimer = NULL; timing = false; } 311 cout << "PIACmd::Interpret() -> Timing OFF mode " << endl; 312 if (gltimer) delete gltimer; gltimer = NULL; timing = false; 313 } 212 314 else if (kw == "exec") { 213 if (tokens.size() < 1) { cout << "PIACmd:: Do() Usage: exec filename" << endl; return(0); }214 Exec (tokens[0]);315 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: exec filename" << endl; return(0); } 316 ExecFile(tokens[0]); 215 317 } 216 318 else if (kw == "shell") { 217 if (tokens.size() < 1) { cout << "PIACmd:: Do() Usage: shell cmdline" << endl; return(0); }319 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl; return(0); } 218 320 system(toks.c_str()); 219 321 } 220 221 // >>>>>>>>>>> Fenetre graphique , changement d'attributs graphiques 222 else if (kw == "zone") { 223 if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: zone nx ny" << endl; return(0); } 224 int nx, ny; 225 nx = ny = 1; 226 nx = atoi(tokens[0].c_str()); ny = atoi(tokens[1].c_str()); 227 mObjMgr->SetGraphicWinZone(nx, ny, false); 228 } 229 else if (kw == "newwin") { 230 if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: newwin nx ny" << endl; return(0); } 231 int nx, ny; 232 nx = ny = 1; 233 nx = atoi(tokens[0].c_str()); ny = atoi(tokens[1].c_str()); 234 mObjMgr->SetGraphicWinZone(nx, ny, true); 235 } 236 else if (kw == "gratt") { 237 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: gratt attributes_list (att=def->defaut)" << endl; return(0); } 238 mObjMgr->SetGraphicAttributes(tokens[0]); 239 } 240 else if (kw == "stacknext") mImgApp->StackWinNext(); 241 242 // >>>>>>>>>>> Link dynamique de fonctions C++ 243 else if (kw == "link" ) { 244 if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: link fnameso f1 [f2 f3]" << endl; return(0); } 245 string sph = ""; 246 for(int gg=0; gg<5; gg++) tokens.push_back(sph); 247 int rc = LinkUserFuncs(tokens[0], tokens[1], tokens[2], tokens[3]); 248 if (rc == 0) cout << "PIAcmd::Do(): Link from " << tokens[0] << " OK " << endl; 249 } 250 else if (kw == "call" ) { 251 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: call userf [arg1 arg2 ...]" << endl; return(0); } 252 UsFmap::iterator it = usfmap.find(tokens[0]); 253 if (it == usfmap.end()) { 254 cerr << "PIAcmd::Do() No User Function " << tokens[0] << endl; 255 return(0); 256 } 257 cout << "PIAcmd::Do() Call " << tokens[0] << "( ... )" << endl; 258 // on est oblige de faire un cast etant donne qu'on 259 // utilise donc des DlFunction (Reza 20/08/98) voir commentaire ds .h (pb g++) 260 DlUserProcFunction fuf = (DlUserProcFunction)(*it).second; 261 TRY { 262 tokens.erase(tokens.begin()); 263 fuf(tokens); 264 } CATCH(merr) { 265 fflush(stdout); 266 cout << endl; 267 cerr << endl; 268 string es = PeidaExc(merr); 269 cerr << "PIACmd::Do() Call UserFunc Exception :" << merr << es; 322 // Execution d'une commande enregistree 323 else { 324 CmdExmap::iterator it = cmdexmap.find(kw); 325 if (it == cmdexmap.end()) cout << "No such command : " << kw << " ! " << endl; 326 else { 327 if ((*it).second.cex) (*it).second.cex->Execute(kw, tokens); 328 else cout << "Dont know how to execute " << kw << " ? " << endl; 270 329 } 271 } 272 273 // >>>>>>>>>>> lecture/ecriture des objets, gestion des objets 274 else if (kw == "openfits" ) { 275 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: openfits file " << endl; return(0); } 276 else mObjMgr->ReadFits(tokens[0]); 277 } 278 else if (kw == "savefits" ) { 279 if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: savefits nomobj filename " << endl; return(0); } 280 else mObjMgr->SaveFits(tokens[0], tokens[1]); 281 } 282 else if (kw == "openppf" ) { 283 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: openppf file " << endl; return(0); } 284 mObjMgr->ReadAll(tokens[0]); 285 } 286 else if (kw == "saveall" ) { 287 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: saveall file " << endl; return(0); } 288 mObjMgr->SaveAll(tokens[0]); 289 } 290 else if (kw == "print" ) { 291 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: print nomobj " << endl; return(0); } 292 mObjMgr->PrintObj(tokens[0]); 293 } 294 else if (kw == "rename" ) { 295 if (tokens.size() < 2) { cout << "PIACmd::Do() Usage: rename nomobj nomnew" << endl; return(0); } 296 mObjMgr->RenameObj(tokens[0], tokens[1]); 297 } 298 else if (kw == "del" ) { 299 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: del nomobj " << endl; return(0); } 300 mObjMgr->DelObj(tokens[0]); 301 } 302 else if (kw == "delobjs" ) { 303 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: delobjs nomobjpattern (*,?) " << endl; return(0); } 304 mObjMgr->DelObjects(tokens[0]); 305 } 306 else if (kw == "listobjs") mObjMgr->ListObjs(); 307 308 // >>>>>>>>>>> Creation d'histos 1D-2D 309 else if (kw == "newh1d") { 310 if (tokens.size() < 4) { cout << "PIACmd::Do() Usage: newh1d nom xmin xmax nbin" << endl; return(0); } 311 int nbx; 312 float xmin, xmax; 313 nbx = 100; 314 xmin = 0.; xmax = 1.; 315 nbx = atoi(tokens[3].c_str()); 316 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str()); 317 Histo* h = new Histo(xmin, xmax, nbx); 318 mObjMgr->AddObj(h, tokens[0]); 319 } 320 else if (kw == "newh2d") { 321 if (tokens.size() < 7) { 322 cout << "PIACmd::Do() Usage:newh2d nomh xmin xmax nbinx ymin ymax nbiny" << endl; 323 return(0); 324 } 325 int nbx, nby; 326 float xmin, xmax; 327 float ymin, ymax; 328 nbx = nby = 50; 329 xmin = 0.; xmax = 1.; 330 ymin = 0.; ymax = 1.; 331 nbx = atoi(tokens[3].c_str()); 332 nby = atoi(tokens[6].c_str()); 333 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str()); 334 ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str()); 335 Histo2D* h = new Histo2D(xmin, xmax, nbx, ymin, ymax, nby); 336 mObjMgr->AddObj(h, tokens[0]); 337 } 338 else if (kw == "newprof") { 339 if (tokens.size() < 4) 340 { cout << "PIACmd::Do() Usage: newprof nom xmin xmax nbin [ymin ymax]" << endl; return(0); } 341 int nbx; 342 float xmin, xmax, ymin = 1., ymax = -1.; 343 if(tokens.size() > 5) 344 {ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str());} 345 nbx = 100; 346 xmin = 0.; xmax = 1.; 347 nbx = atoi(tokens[3].c_str()); 348 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str()); 349 HProf* h = new HProf(xmin, xmax, nbx, ymin, ymax); 350 mObjMgr->AddObj(h, tokens[0]); 351 } 352 else if (kw == "newgfd") { 353 if (tokens.size() < 3) 354 { cout << "PIACmd::Do() Usage: newgfd nvar nalloc [errx(0/1)]" << endl; return(0); } 355 int nvar, nalloc, errx=0; 356 if (tokens.size() > 3) 357 { errx = atoi(tokens[3].c_str()); if(errx>0) errx=1; else errx = 0;} 358 nvar = atoi(tokens[1].c_str()); nalloc = atoi(tokens[2].c_str()); 359 if(nvar>0 && nalloc>0) { 360 GeneralFitData* gfd = new GeneralFitData(nvar,nalloc,errx); 361 mObjMgr->AddObj(gfd, tokens[0]); 362 } 363 } 364 365 // >>>>>>>>>>> Affichage des objets 366 else if ( (kw == "disp") || (kw == "surf") ) { 367 if (tokens.size() < 1) { cout << "PIACmd::Do() Usage: disp nomobj opt" << endl; return(0); } 368 string opt = "n"; 369 if (tokens.size() > 1) opt = tokens[1]; 370 if (kw == "disp") mObjMgr->DisplayObj(tokens[0], opt); 371 else if (kw == "surf") mObjMgr->DisplaySurf3D(tokens[0], opt); 372 } 373 374 else if (kw == "nt2d") { 375 if (tokens.size() < 5) { cout << "PIACmd::Do() Usage: nt2d nomobj varx vary errx erry opt" << endl; return(0); } 376 string opt = "n"; 377 if (tokens.size() > 5) opt = tokens[5]; 378 string ph = ""; 379 mObjMgr->DisplayNT(tokens[0],tokens[1],tokens[2], ph, tokens[3], tokens[4], ph, opt); 380 } 381 else if (kw == "nt3d") { 382 if (tokens.size() < 7) { cout << "PIACmd::Do() Usage: nt3d nomobj varx vary varz errx erry errz opt" << endl; return(0); } 383 string opt = "n"; 384 if (tokens.size() > 7) opt = tokens[7]; 385 mObjMgr->DisplayNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6], opt); 386 } 387 388 else if (kw == "gfd2d") { 389 if(tokens.size()<2) 390 {cout<<"PIACmd::Do() Usage: gfd2d nomobj numvarx erreur=(x y xy) opt"<<endl; 391 return(0);} 392 string numvary = ""; 393 string err = ""; 394 string opt = "n"; 395 if(tokens.size()>2) err = tokens[2]; 396 if(tokens.size()>3) opt = tokens[3]; 397 mObjMgr->DisplayGFD(tokens[0],tokens[1],numvary,err,opt); 398 } 399 else if (kw == "gfd3d") { 400 if(tokens.size()<3) 401 {cout<<"PIACmd::Do() Usage: gfd3d nomobj numvarx numvary erreur=(x y z xy xz yz xyz) opt"<<endl; 402 return(0);} 403 string err = ""; 404 string opt = "n"; 405 if(tokens.size()>3) err = tokens[3]; 406 if(tokens.size()>4) opt = tokens[4]; 407 mObjMgr->DisplayGFD(tokens[0],tokens[1],tokens[2],err,opt); 408 } 409 410 // >>>>>>>>>>> Trace de fonctions 411 else if ( (kw == "func") ) { 412 if (tokens.size() < 4) { cout << "PIACmd::Do() Usage: func expr xmin xmax npt opt" << endl; return(0); } 413 string opt = "n"; 414 if (tokens.size() > 4) opt = tokens[4]; 415 int np; 416 float xmin, xmax; 417 np = 100; 418 xmin = 0.; xmax = 1.; 419 np = atoi(tokens[3].c_str()); 420 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str()); 421 mObjMgr->PlotFunc(tokens[0], xmin, xmax, np, opt); 422 } 423 else if ( (kw == "func2d") ) { 424 if (tokens.size() < 7) { 425 cout << "PIACmd::Do() Usage: func2d expr xmin xmax nptx ymin ymax npty opt" << endl; 426 return(0); 427 } 428 int npx, npy; 429 float xmin, xmax; 430 float ymin, ymax; 431 npx = npy = 50; 432 xmin = 0.; xmax = 1.; 433 ymin = 0.; ymax = 1.; 434 npx = atoi(tokens[3].c_str()); 435 npy = atoi(tokens[6].c_str()); 436 xmin = atof(tokens[1].c_str()); xmax = atof(tokens[2].c_str()); 437 ymin = atof(tokens[4].c_str()); ymax = atof(tokens[5].c_str()); 438 string opt = "n"; 439 if (tokens.size() > 7) opt = tokens[7]; 440 mObjMgr->PlotFunc2D(tokens[0], xmin, xmax, ymin, ymax, npx, npy, opt); 441 } 442 443 // >>>>>>>>>>> Trace d'expressions de N_Tuple, StarList, etc ... 444 else if (kw == "plot2d" ) { 445 if (tokens.size() < 4) { 446 cout << "PIACmd::Do() Usage: plot2d nomobj expx expy [experrx experry] expcut opt" << endl; 447 return(0); 448 } 449 string errx = ""; string erry = ""; string ecut = "1"; 450 string opt = "n"; 451 if (tokens.size() < 6) { // Plot sans les erreurs 452 ecut = tokens[3]; 453 if (tokens.size() > 4) opt = tokens[4]; 454 } 455 else { // Plot avec les erreurs 456 errx = tokens[3]; erry = tokens[4]; ecut = tokens[5]; 457 if (tokens.size() > 6) opt = tokens[6]; 458 } 459 mObjMgr->DisplayPoints2D(tokens[0],tokens[1],tokens[2],errx,erry,ecut,opt); 460 } 461 462 else if (kw == "plot3d" ) { 463 if (tokens.size() < 5) { 464 cout << "PIACmd::Do() Usage: plot3d nomobj expx expy expz expcut opt" << endl; 465 return(0); 466 } 467 string opt = "n"; 468 if (tokens.size() > 5) opt = tokens[5]; 469 mObjMgr->DisplayPoints3D(tokens[0],tokens[1],tokens[2],tokens[3], tokens[4], opt); 470 } 471 472 else if (kw == "projh1d" ) { 473 if (tokens.size() < 5) { 474 cout << "PIACmd::Do() Usage: projh1d nomobj expx expwt expcut nomh1 opt" << endl; 475 return(0); 476 } 477 string opt = "n"; 478 if (tokens.size() > 5) opt = tokens[5]; 479 mObjMgr->ProjectH1(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], opt); 480 } 481 482 else if (kw == "projh2d" ) { 483 if (tokens.size() < 6) { 484 cout << "PIACmd::Do() Usage: projh2 nomobj expx expy expwt expcut nomh2 opt" << endl; 485 return(0); 486 } 487 string opt = "n"; 488 if (tokens.size() > 6) opt = tokens[6]; 489 490 mObjMgr->ProjectH2(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], opt); 491 } 492 493 else if (kw == "projprof" ) { 494 if (tokens.size() < 6) { 495 cout << "PIACmd::Do() Usage: projprof nomobj expx expy expwt expcut nomprof opt" << endl; 496 return(0); 497 } 498 string opt = "n"; 499 if (tokens.size() > 6) opt = tokens[6]; 500 501 mObjMgr->ProjectHProf(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], opt); 502 } 503 504 else if (kw == "fillnt" ) { 505 if (tokens.size() < 7) { 506 cout << "PIACmd::Do() Usage: fillnt nomobj expx expy expz expt expcut nomnt" << endl; 507 return(0); 508 } 509 mObjMgr->FillNT(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5], tokens[6] ); 510 } 511 512 else if (kw == "fillvec" ) { 513 if (tokens.size() < 4) { 514 cout << "PIACmd::Do() Usage: fillvec nomobj expx expcut nomvec opt" << endl; 515 return(0); 516 } 517 string opt = "n"; 518 if (tokens.size() > 4) opt = tokens[4]; 519 mObjMgr->FillVect(tokens[0],tokens[1],tokens[2], tokens[3], opt); 520 } 521 522 else if (kw == "fillgd1" ) { 523 if (tokens.size() < 5) { 524 cout << "PIACmd::Do() Usage: fillgd1 nomobj expx expy experry expcut nomgfd" << endl; 525 return(0); 526 } 527 string nomgfd = ""; 528 if (tokens.size() > 5) nomgfd = tokens[5]; 529 string expy = ""; 530 mObjMgr->FillGFD(tokens[0],tokens[1], expy, tokens[2], tokens[3], tokens[4],nomgfd); 531 } 532 533 else if (kw == "fillgd2" ) { 534 if (tokens.size() < 6) { 535 cout << "PIACmd::Do() Usage: fillgd2 nomobj expx expy expz experrz expcut nomgfd" << endl; 536 return(0); 537 } 538 string nomgfd = ""; 539 if (tokens.size() > 6) nomgfd = tokens[6]; 540 mObjMgr->FillGFD(tokens[0],tokens[1],tokens[2], tokens[3], tokens[4], tokens[5],nomgfd); 541 } 542 543 // Calcul TF 544 else if (kw == "fft" ) { 545 if (tokens.size() < 1) { 546 cout << "PIACmd::Do() Usage: fft nomobj opt" << endl; 547 return(0); 548 } 549 string opt = "n"; 550 if (tokens.size() > 1) opt = tokens[1]; 551 mObjMgr->FFT(tokens[0], opt); 552 } 553 554 // Fit 1D sur objets 1D. Egalement Fit 2D sur objets 2D. 555 else if (kw == "fit") { 556 if (tokens.size() < 2) { 557 cout <<"PIACmd::Do() Usage:fit nomobj func \n" 558 <<" [p:p1,...,pn s:s1,...,sn m:m1,...,mn M:M1,...,Mn o:... o:...]\n"; 559 return(0); 560 } 561 string p=""; string s=""; string m=""; string M=""; string O=""; 562 if (tokens.size()>2) 563 for(int ip=2;ip<tokens.size();ip++) { 564 if(tokens[ip].length()<=2) continue; 565 const char *c = tokens[ip].c_str(); 566 if(c[1]!=':') continue; 567 if(c[0]=='p') p=c+2; 568 else if(c[0]=='s') s=c+2; 569 else if(c[0]=='m') m=c+2; 570 else if(c[0]=='M') M=c+2; 571 else if(c[0]=='o') {O += ","; O += c+2;} 572 } 573 mObjMgr->Fit12D(tokens[0],tokens[1],p,s,m,M,O); 574 } 575 576 #ifndef SANS_StarReco 577 // FITPSF sur image 578 else if (kw == "fitpsf" ) { 579 if (tokens.size() < 1) { 580 cout << "PIACmd::Do() Usage: fitpsf psf_typ [options_fit]" << endl; 581 return(0); 582 } 583 FitPSFImg(tokens); 584 } 585 586 // Photometrie d'ouvertue sur image 587 else if (kw == "aper" ) { 588 if (tokens.size() < 1) { 589 cout << "PIACmd::Do() Usage: aper fond_typ [opt_calcul opt_disp]" << endl; 590 return(0); 591 } 592 Photom_Ouv(tokens); 593 } 594 #endif 595 596 else { 597 cerr << "PIACmd::Do() Erreur - Commande " << kw << " inconuue ! " << endl; 598 return(-1); 599 } 330 } 331 600 332 if (timing) gltimer->Split(); 601 602 333 return(0); 603 334 } 604 335 605 336 606 607 /* --Methode-- */ 608 int PIACmd::LinkUserFuncs(string& fnameso, string& func1, string& func2, string& func3) 609 // string& func4, string& func5) 610 { 611 string cmd; 612 int rc; 613 614 if (dynlink) delete dynlink; dynlink = NULL; 615 usfmap.clear(); 616 617 dynlink = new PDynLinkMgr(fnameso, true); 618 if (dynlink == NULL) { 619 string sn = fnameso; 620 cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur ouverture SO " << sn << endl; 621 return(2); 622 } 623 624 int nok=0; 625 // on utilise donc des DlFunction (Reza 20/08/98) voir commentaire ds .h (pb g++) 626 // DlUserProcFunction f = NULL; 627 DlFunction f = NULL; 628 if ((func1.length() < 1) || (func1 == "-") || (func1 == ".") ) goto fin; 629 // f = (DlUserProcFunction) dlsym(dlhandle, func1.c_str()); 630 f = dynlink->GetFunction(func1); 631 if (f) { nok++; usfmap[func1] = f; } 632 else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func1 << endl; 633 634 if ((func2.length() < 1) || (func2 == "-") || (func2 == ".") ) goto fin; 635 // f = (DlUserProcFunction) dlsym(dlhandle, func2.c_str()); 636 f = dynlink->GetFunction(func2); 637 if (f) { nok++; usfmap[func2] = f; } 638 else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func2 << endl; 639 640 if ((func3.length() < 1) || (func3 == "-") || (func3 == ".") ) goto fin; 641 // f = (DlUserProcFunction) dlsym(dlhandle, func3.c_str()); 642 f = dynlink->GetFunction(func3); 643 if (f) { nok++; usfmap[func3] = f; } 644 else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func3 << endl; 645 646 /* Pb compile g++ 2.7.2 647 if ((func4.length() < 1) || (func4 == "-") || (func4 == ".") ) goto fin; 648 // f = (DlUserProcFunction) dlsym(dlhandle, func4.c_str()); 649 f = dynlink->GetFunction(func4); 650 if (f) { nok++; usfmap[func4] = f; } 651 else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func4 << endl; 652 653 if ((func5.length() < 1) || (func5 == "-") || (func5 == ".") ) goto fin; 654 // f = (DlUserProcFunction) dlsym(dlhandle, func5.c_str()); 655 f = dynlink->GetFunction(func5); 656 if (f) { nok++; usfmap[func5] = f; } 657 else cerr << "PIACmd/LinkUserFuncs_Erreur: Erreur linking " << func5 << endl; 658 */ 659 fin: 660 if (nok < 1) { if (dynlink) delete dynlink; dynlink = NULL; return(3); } 661 else return(0); 662 } 663 664 ///////////////////////////////////////////////////////////////////////// 665 ///////////////////////////////////////////////////////////////////////// 666 /////////////////////////////// Fonctions /////////////////////////////// 667 ///////////////////////////////////////////////////////////////////////// 668 ///////////////////////////////////////////////////////////////////////// 669 #ifndef SANS_StarReco 670 #include "psf.h" 671 #include "dynccd.h" 672 #include "pimgadapter.h" 673 #include "nbmath.h" 674 #include "nbtri.h" 675 676 /* Nouvelle-Fonction rz + cmv 15/10/98 */ 677 int FitPSFImg(cmdtok& tokens) 678 // Fit de PSF sur une Image. 679 //| tokens[0] = Type de PSF () 680 //| : G = fit gaussienne+fond (volume) 681 //| : Gi = fit gaussienne+fond integree (volume) 682 //| : d = fit DL de gaussienne+fond (volume) 683 //| : di = fit DL de gaussienne+fond integree (volume) 684 //| : D = fit DL de gaussienne+fond avec coeff variable p6 (volume) 685 //| : Di = fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 686 //| : M = fit Moffat+fond (expos=p6) (volume) 687 //| : Mi = fit Moffat+fond integree (expos=p6) (volume) 688 //| tokens[1] = options pour le fit ex: l1.0,G2.,R7.,m10.,M65000.,P3.,f,n,r,i,w10/450 689 //| : r = ecriture de l'image des residus (def=non) 690 //| : f = ecriture de l'image de de la PSF fitee (def=non) 691 //| : i = ecriture du pave initial selectionne pour le fit (def=non) 692 //| : n = ecriture de l'image du bruit (def=non) 693 //| : Gaa.bbb = gain en e-/ADU (def=1) 694 //| : Raa.bbb = readout noise en e- (def=0) 695 //| : maa.bbb = limite basse dynamique en ADU (def=-9.e19) 696 //| : Maa.bbb = limite haute dynamique en ADU (def=9.e19) 697 //| : Paa.bbb = valeur du parametre supplementaire pour 698 //| : la.a = print a=FitPSFImg, b=PSF.Fit PSF.IniFit 699 //| : wa/b = "a" est le facteur de zoom de la fenetre de representation 700 //| des resultats (def=6) et b sa taille maximale (def=500). 701 //| Return: 0 si Ok, <0 sinon. 702 { 703 // Decodage des arguments 704 if(tokens.size()<1) return(-1); 705 int typ_psf=PSF::psfGaussienne; 706 bool wres=false, wpsf=false, wpav=false, wnois=false; 707 float gain=1., readout=0., pixmin=-9.e19, pixmax=9.e19; 708 int zoom=6, wmax=500; 709 float par6=-1.; 710 int lp=1, lpg=0; 711 string dummy,dum; 712 713 if(tokens.size()>=2) { 714 dummy = "," + tokens[1]+ ","; 715 if(strstr(dummy.c_str(),",r,")) wres=true; 716 if(strstr(dummy.c_str(),",f,")) wpsf=true; 717 if(strstr(dummy.c_str(),",i")) wpav=true; 718 if(strstr(dummy.c_str(),",n")) wnois=true; 719 if(strstr(dummy.c_str(),",G")) { 720 size_t p = dummy.find(",G"); size_t q = dummy.find_first_of(',',p+1); 721 dum = dummy.substr(p,q-p); 722 if(dum.length()>2) sscanf(dum.c_str(),",G%f",&gain); 723 } 724 if(strstr(dummy.c_str(),",P")) { 725 size_t p = dummy.find(",P"); size_t q = dummy.find_first_of(',',p+1); 726 dum = dummy.substr(p,q-p); 727 if(dum.length()>2) sscanf(dum.c_str(),",P%f",&par6); 728 } 729 if(strstr(dummy.c_str(),",R")) { 730 size_t p = dummy.find(",R"); size_t q = dummy.find_first_of(',',p+1); 731 dum = dummy.substr(p,q-p); 732 if(dum.length()>2) sscanf(dum.c_str(),",R%f",&readout); 733 } 734 if(strstr(dummy.c_str(),",m")) { 735 size_t p = dummy.find(",m"); size_t q = dummy.find_first_of(',',p+1); 736 dum = dummy.substr(p,q-p); 737 if(dum.length()>2) sscanf(dum.c_str(),",m%f",&pixmin); 738 } 739 if(strstr(dummy.c_str(),",M")) { 740 size_t p = dummy.find(",M"); size_t q = dummy.find_first_of(',',p+1); 741 dum = dummy.substr(p,q-p); 742 if(dum.length()>2) sscanf(dum.c_str(),",M%f",&pixmax); 743 } 744 if(strstr(dummy.c_str(),",l")) { // niveau de print 745 size_t p = dummy.find(",l"); size_t q = dummy.find_first_of(',',p+1); 746 dum = dummy.substr(p,q-p); 747 float ab; 748 if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab); 749 if(ab<0) ab = 0.; 750 lp = (int) ab; lpg = (int) 10.*(ab-lp); 751 } 752 if(strstr(dummy.c_str(),",w")) { // niveau de print 753 size_t p = dummy.find(",w"); size_t q = dummy.find_first_of(',',p+1); 754 dum = dummy.substr(p,q-p); 755 if(dum.length()>2) sscanf(dum.c_str(),",w%d/%d",&zoom,&wmax); 756 } 757 } 758 759 dummy = "," + tokens[0]+ ","; 760 if(strstr(dummy.c_str(),",G,")) typ_psf=PSF::psfGaussienne; 761 else if(strstr(dummy.c_str(),",Gi,")) typ_psf=PSF::psfGaussInteg; 762 else if(strstr(dummy.c_str(),",d,") ) typ_psf=PSF::psfDelGaussienne; 763 else if(strstr(dummy.c_str(),",di,")) typ_psf=PSF::psfDelGaussinteg; 764 else if(strstr(dummy.c_str(),",D,") ) {typ_psf=PSF::psfDel1Gaussienne; if(par6<=0.) par6=1.;} 765 else if(strstr(dummy.c_str(),",Di,")) {typ_psf=PSF::psfDel1GaussInteg; if(par6<=0.) par6=1.;} 766 else if(strstr(dummy.c_str(),",M,") ) {typ_psf=PSF::psfMoffat; if(par6<=1.) par6=2.5;} 767 else if(strstr(dummy.c_str(),",Mi,")) {typ_psf=PSF::psfMoffInteg; if(par6<=1.) par6=2.5;} 768 769 if(gain<=0.) gain=1.; if(readout<0.) readout=0.; 770 if(zoom<1) zoom=1; if(zoom>10) zoom=10; // Il semble que le zoom soit limite a 10 !!! 771 if(wmax>500) wmax=500; 772 if(lp<0) lp=1; if(lpg<0) lpg=0; 773 774 // Wigdet,piimage et image courants 775 NamedObjMgr omg; 776 PIStdImgApp* app = omg.GetImgApp(); 777 if(app == NULL) 778 {cout<<"Pas de PIStdImgApp*"<<endl; return(-2);} 779 PIBaseWdg* curw= app->CurrentBaseWdg() ; 780 if(curw == NULL) 781 {cout<<"Pas de PIBaseWdg*"<<endl; return(-3);} 782 if(curw->kind() != PIImage::ClassId) 783 {cout<<"Current window not an Image"<<endl; return(-4);} 784 PIImage* curpimg = (PIImage*)curw; 785 if(curpimg == NULL) 786 {cout<<"Pas de PIImage*"<<endl; return(-5);} 787 P2DArrayAdapter* img = curpimg->Image(); 788 if(img == NULL) 789 {cout<<"Pas de Image*"<<endl; return(-6);} 790 string nom = "fitpsf_"; 791 792 // Definition du pave courant sur la piimage 793 int dx = curpimg->XSzPave(), dy = curpimg->YSzPave(); 794 int x0 = curpimg->XPave()-dx/2, y0 = curpimg->YPave()-dy/2; 795 if(x0<0) x0 = 0; if(y0<0) y0 = 0; 796 int x1 = x0+dx, y1 = y0+dy; 797 if(x1>img->XSize()) x1=img->XSize(); if(y1>img->YSize()) y1=img->YSize(); 798 dx = x1-x0; dy = y1-y0; 799 int dxy = (dx>dy)?dx:dy; 800 ImageR4* pav = new ImageR4(dx, dy); 801 {for(int j=0;j<dy;j++) for(int i=0;i<dx;i++) (*pav)(i,j)=(*img)(i+x0,j+y0);} 802 803 // Bruit sur le pave 804 DynCCD mdynccd(kPhotonNoise,pixmin,pixmax,gain,readout); 805 ImageR4 *nois = NoiseImage(pav, &mdynccd); 806 807 // Print 808 int w=2*zoom*dxy+25; if(w>wmax){w=wmax;zoom=(wmax-25)/(2*dxy);if(zoom<1)zoom=1;} 809 if(lp>1) 810 {cout<<"FitPSFImg: fun="<<tokens[0]<<","<<typ_psf 811 <<" Write res="<<wres<<" psf="<<wpsf<<" pav="<<wpav<<" nois="<<wnois 812 <<" Par6="<<par6<<" lp="<<lp<<","<<lpg<<endl; 813 mdynccd.Print(); 814 cout<<"... dx,y="<<dxy<<" zoom="<<zoom<<" w="<<w<<endl;} 815 816 // PSF et Fit 817 PSF mypsf(typ_psf,100.0); 818 int npar = mypsf.NParm(); 819 PSFStar mypsfstar(&mypsf); 820 if(npar>7) mypsfstar.Parm(6)=(double)par6; // Cas moffat et Dl gauss avec coeff var. 821 int rc = mypsfstar.IniFit(*pav,*nois,lpg); 822 if(rc != 0) 823 {cout<<"PIDemoApp::FitPSFImg(), Echec IniFit (rc="<<rc<<")"<<endl; 824 delete nois; delete pav; return(-10); } 825 rc = mypsfstar.Fit(*pav,*nois,lpg); 826 if(rc != 0) 827 {cout<<"PIDemoApp::FitPSFImg(), Echec Fit (rc="<<rc<<")"<<endl; 828 delete nois; delete pav; return(-11); } 829 if(lp) mypsfstar.Print(2); 830 float smax,axisrat,tiltdeg; 831 rc = paramga((float) mypsfstar.SigX(),(float) mypsfstar.SigY() 832 ,(float) mypsfstar.Rho(),&smax,&axisrat,&tiltdeg); 833 if(rc==0 && lp) 834 printf("... sa=%g sb=%g (%g) teta=%g\n",smax,smax*axisrat,axisrat,tiltdeg); 835 else printf("Erreur paramga \n"); 836 837 // Creation des pave resultats 838 ImageR4* res = new ImageR4(dx, dy); 839 ImageR4* psf = new ImageR4(dx, dy); 840 CopieImage(*res,*pav); *res -= mypsfstar; 841 *psf = 0.; *psf += mypsfstar; 842 843 // Si on demande d'ecrire au moins un des resultats (pav,nois,res,psf) => menage! 844 bool delobj = (wpav||wnois||wres||wpsf)?true:false; 845 846 // Display des resultats, fenetre 2x2 {{pav,nois},{res,psf}} 847 app->CreateGraphWin(2,2,w,w); app->SetZoomAtt(zoom); 848 dummy = nom+"pav"; dum = dummy+"*"; if(delobj) omg.DelObjects(dum); 849 if(wpav) { 850 // Si on veut garder l'objet 851 omg.AddObj(pav,dummy); 852 omg.DisplayObj(omg.LastObjName()); 853 } else { 854 // "true" pour tuer (delete) de l'objet ImageR4 lors de la destruction de PIImage 855 app->DispImage(new ImageAdapter<r_4>(pav,true),dummy,Disp_Next); 856 } 857 dummy = nom+"nois"; dum = dummy+"*"; if(delobj) omg.DelObjects(dum); 858 if(wnois) { 859 omg.AddObj(nois,dummy); 860 omg.DisplayObj(omg.LastObjName()); 861 } else { 862 app->DispImage(new ImageAdapter<r_4>(nois,true),dummy,Disp_Next); 863 } 864 dummy = nom+"res"; dum = dummy+"*"; if(delobj) omg.DelObjects(dum); 865 if(wres) { 866 omg.AddObj(res,dummy); 867 omg.DisplayObj(omg.LastObjName()); 868 } else { 869 app->DispImage(new ImageAdapter<r_4>(res,true),dummy,Disp_Next); 870 } 871 dummy = nom+"psf"; dum = dummy+"*"; if(delobj) omg.DelObjects(dum); 872 if(wpsf) { 873 omg.AddObj(psf,dummy); 874 omg.DisplayObj(omg.LastObjName()); 875 } else { 876 app->DispImage(new ImageAdapter<r_4>(psf,true),dummy,Disp_Next); 877 } 337 /* --Methode-- */ 338 int PIACmd::ExecFile(string& file) 339 { 340 char line_buff[512]; 341 FILE *fip; 342 343 if ( (fip = fopen(file.c_str(),"r")) == NULL ) { 344 cerr << "PIACmd::Exec() Error opening file " << file << endl; 345 hist << "##! PIACmd::Exec() Error opening file " << file << endl; 346 return(0); 347 } 348 349 hist << "### Executing commands from " << file << endl; 350 if (trace) { 351 mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta); 352 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta); 353 mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta); 354 } 355 356 while (fgets(line_buff,511,fip) != NULL) 357 { 358 if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta); 359 line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */ 360 string line(line_buff); 361 Interpret(line); 362 } 363 hist << "### End of Exec( " << file << " ) " << endl; 364 if (trace) { 365 mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta); 366 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta); 367 mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta); 368 } 878 369 879 370 return(0); 880 371 } 881 372 882 /* Nouvelle-Fonction cmv 16/10/98 */ 883 int Photom_Ouv(cmdtok& tokens) 884 // Photometrie d'ouverture sur une Image. 885 //| tokens[0] = Type de calcul du fond et du flux. 886 //| : b = fond calcule sur les pixels du bord du pave. 887 //| : a = fond sur les pixels autres que ceux servant au calcul du flux. 888 //| : faa.bbb = fond fixe a aa.bbb 889 //| defaut : "b" 890 //| tokens[1] = options pour le fit ex: l1 891 //| : ra = "a" rayon minimal de scan (def=0) 892 //| : ga = "a" taille de la fenetre glissante pour les extrapolations (def=4) 893 //| : la = "a" niveau de print 894 //| : c = la surface pour la photometrie est un carre (defaut=cercle) 895 //| : C = recentrage du pave sur le pixel le + brillant (defaut=non) 896 //| tokens[2] = options graphiques 897 //| Return: 0 si Ok, <0 sinon. 898 { 899 // Decodage des arguments 900 if(tokens.size()<1) return(-1); 901 int typ_fond=1, rmin=0, rmax, npt_gliss=4, lp=0; 902 float fondimpos=0., fondbord=0., fondautre; 903 bool cercle=true, centre=false; 904 string opt=""; 905 string dummy; string dum; 906 907 if(tokens.size()>=3) opt = tokens[2]; 908 if(tokens.size()>=2) { 909 dummy = "," + tokens[1]+ ","; 910 if(strstr(dummy.c_str(),",r")) { 911 size_t p = dummy.find(",r"); size_t q = dummy.find_first_of(',',p+1); 912 dum = dummy.substr(p,q-p); 913 if(dum.length()>2) sscanf(dum.c_str(),",r%d",&rmin); 914 } 915 if(strstr(dummy.c_str(),",g")) { 916 size_t p = dummy.find(",g"); size_t q = dummy.find_first_of(',',p+1); 917 dum = dummy.substr(p,q-p); 918 if(dum.length()>2) sscanf(dum.c_str(),",g%d",&npt_gliss); 919 } 920 if(strstr(dummy.c_str(),",l")) { 921 size_t p = dummy.find(",l"); size_t q = dummy.find_first_of(',',p+1); 922 dum = dummy.substr(p,q-p); 923 if(dum.length()>2) sscanf(dum.c_str(),",l%d",&lp); 924 } 925 if(strstr(dummy.c_str(),",c")) cercle = false; 926 if(strstr(dummy.c_str(),",C")) centre = true; 927 } 928 929 dummy = "," + tokens[0]+ ","; 930 if(strstr(dummy.c_str(),",b,")) typ_fond=1; 931 else if(strstr(dummy.c_str(),",a,")) typ_fond=2; 932 else if(strstr(dummy.c_str(),",f")) { 933 typ_fond=3; 934 size_t p = dummy.find(",f"); size_t q = dummy.find_first_of(',',p+1); 935 dum = dummy.substr(p,q-p); 936 if(dum.length()>2) sscanf(dum.c_str(),",f%f",&fondimpos); 937 } 938 939 if(rmin<0) rmin=0; if(npt_gliss<=0) npt_gliss=4; if(lp<0) lp=1; 940 941 // Wigdet,piimage et image courants 942 NamedObjMgr omg; 943 PIStdImgApp* app = omg.GetImgApp(); 944 if(app == NULL) 945 {cout<<"Pas de PIStdImgApp*"<<endl; return(-2);} 946 PIBaseWdg* curw= app->CurrentBaseWdg() ; 947 if(curw == NULL) 948 {cout<<"Pas de PIBaseWdg*"<<endl; return(-3);} 949 if(curw->kind() != PIImage::ClassId) 950 {cout<<"Current window not an Image"<<endl; return(-4);} 951 PIImage* curpimg = (PIImage*)curw; 952 if(curpimg == NULL) 953 {cout<<"Pas de PIImage*"<<endl; return(-5);} 954 P2DArrayAdapter* img = curpimg->Image(); 955 if(img == NULL) 956 {cout<<"Pas de Image*"<<endl; return(-6);} 957 string nom = "ouver_"; 958 959 // Definition du pave courant sur la piimage 960 int xc = curpimg->XPave(), yc = curpimg->YPave(); 961 int dx = curpimg->XSzPave(), dy = curpimg->YSzPave(); 962 int dxym = (dx<dy)?dx:dy; if(dxym%2==0) dxym++; rmax = dxym/2; 963 if(dxym<3||dxym>img->XSize()||dxym>img->YSize()) 964 {cout<<"Pave trop petit/grand: "<<dxym<<endl; return(-10);} 965 if(rmin>=rmax) 966 {cout<<"rayon mini="<<rmin<<">= rmax="<<rmax<<endl; return(-11);} 967 if(centre) { // Recentrage autour du pixel le + brillant? 968 int xcnew=-1, ycnew=-1; float pxnew=-1.e20,pxold=-1.e20,px; 969 for(int j=yc-rmax;j<=yc+rmax;j++) { 970 if(j<0 || j>=img->YSize()) continue; 971 for(int i=xc-rmax;i<=xc+rmax;i++) { 972 if(i<0 || i>=img->XSize()) continue; 973 px = (*img)(i,j); 974 if(i==xc && j==yc) pxold = px; 975 if((xcnew==-1 && ycnew==-1) || px>=pxnew) {xcnew=i; ycnew=j; pxnew=px;} 976 // cout<<"xcnew,ycnew,pxnew="<<xcnew<<" "<<ycnew<<" "<<pxnew<<endl; 977 } } 978 if(lp>1) cout<<"Re-centrage(x,y,px): old=("<<xc<<","<<yc<<","<<pxold<<")" 979 <<" -> new=("<<xcnew<<","<<ycnew<<","<<pxnew<<")"<<endl; 980 if(xcnew!=-1 && ycnew!=-1 && pxnew>pxold) {xc=xcnew; yc=ycnew;} 981 } 982 int x0=xc-rmax, y0=yc-rmax, x1=xc+rmax, y1=yc+rmax; 983 if(x0<0||y0<0||x1>=img->XSize()||y1>=img->YSize()) 984 {cout<<"Pave hors image"<<endl; return(-12);} 985 int ic = rmax, jc = rmax; 986 ImageR4* pav = new ImageR4(dxym, dxym); 987 {for(int j=-rmax;j<=rmax;j++) for(int i=-rmax;i<=rmax;i++) 988 (*pav)(ic+i,jc+j)=(*img)(xc+i,yc+j);} 989 990 // Print 991 if(lp>1) 992 cout<<"photom_ouv[cercle="<<cercle<<",typ="<<typ_fond<<"]: pav[" 993 <<dx<<","<<dy<<","<<dxym 994 <<"] xc,yc=["<<xc<<","<<yc<<"] ic,jc="<<ic<<","<<jc<<endl 995 <<" (fond="<<fondimpos<<") pxmil="<<(*pav)(ic,ic) 996 <<" -> Rph de "<<rmin<<" a "<<rmax<<endl; 997 998 // Ouverture des buffers et objets necessaires 999 float *p = new float[dxym*dxym]; 1000 r_4 xnt[4]; 1001 NTuple *ntfl=NULL, *ntex=NULL; 1002 {char* name[4]={"npx","flux","fond","mag"}; ntfl = new NTuple(4,name);} 1003 {char* name[3]={"k","a","f0"}; ntex = new NTuple(3,name);} 1004 1005 // Calcul du fond sur les pixels du bord du pave 1006 { 1007 int nf = 0; 1008 for(int i=0;i<dxym;i++) {p[nf]=(*pav)(i,0); nf++; p[nf]=(*pav)(i,dxym-1); nf++;} 1009 for(int j=1;j<dxym-1;j++) {p[nf]=(*pav)(0,j); nf++; p[nf]=(*pav)(dxym-1,j); nf++;} 1010 qsort(p,(size_t) nf,sizeof(float),qSort_Float); 1011 fondbord = (p[nf/2]+p[(nf-1)/2])/2.; 1012 if(lp>0) cout<<"Fond_Bord: "<<fondbord<<" (avec 1 px au bord="<<nf<<")"<<endl; 1013 } 1014 1015 // Photometrie d'ouverture variable. 1016 int rfin = -1; 1017 for(int r=rmin;r<=rmax;r++) { 1018 double sum=0.; int ns=0, nf=0; 1019 for(int i=0;i<dxym;i++) for(int j=0;j<dxym;j++) { 1020 double ray2 = (i-ic)*(i-ic)+(j-jc)*(j-jc)-0.1; 1021 if( (cercle && ray2<=r*r) || 1022 (!cercle && ic-r<=i && i<=ic+r && jc-r<=j && j<=jc+r) ) 1023 {sum += (*pav)(i,j); ns++;} 1024 else {p[nf] = (*pav)(i,j); nf++;} 1025 } 1026 if(typ_fond==2) { 1027 if(nf<2) continue; 1028 qsort(p,(size_t) nf,sizeof(float),qSort_Float); 1029 fondautre = (p[nf/2]+p[(nf-1)/2])/2.; 1030 } 1031 double fond=-1.e19; 1032 if(typ_fond==3) fond=fondimpos; else if(typ_fond==2) fond=fondautre; else fond=fondbord; 1033 rfin = r; 1034 xnt[0] = ns; 1035 xnt[1] = sum-fond*ns; 1036 xnt[2] = fond; 1037 xnt[3] = (xnt[1]>0.)? -2.5*log10((double)xnt[1]): -99.; 1038 if(lp>0) 1039 cout<<"Ouv[r="<<r<<",ns="<<xnt[0]<<",nf="<<nf<<"]: fd="<<xnt[2] 1040 <<" fl="<<xnt[1]<<" mag="<<xnt[3]<<endl; 1041 ntfl->Fill(xnt); 1042 } 1043 delete [] p; 1044 int nr = ntfl->NEntry(); 1045 if(lp>1) cout<<"Nombre de calculs de flux: "<<nr<<endl; 1046 if(nr<=0) 1047 {cout<<"Pas de flux calcules"<<endl; delete pav; delete ntfl; delete ntex; return(-13);} 1048 1049 cout<<"Ouv[rouv="<<rfin<<",npix="<<xnt[0]<<"]: fond="<<xnt[2] 1050 <<" flux="<<xnt[1]<<" mag="<<xnt[3]<<endl; 1051 1052 // Extrapolation: F_mes = F_vrai + npxflux*(Fd_vrai-Fd_mes) 1053 // On fit F_mes=f(npxflux) sur une fenetre glissante de npt_gliss pts. 1054 bool ex = false; 1055 if(nr>=npt_gliss) { 1056 ex = true; 1057 double *npix = new double[nr], *flux = new double[nr], *err = new double[nr]; 1058 for(int i=0;i<nr;i++) { ntfl->GetVec(i,xnt); npix[i]=xnt[0]; flux[i]=xnt[1]; err[i]=1.;} 1059 double a,b; int n; 1060 for(int k=0;k<=nr-npt_gliss;k++) { 1061 n = npt_gliss; FitLin(&npix[k],&flux[k],&err[k],&n,&b,&a); 1062 xnt[0]=k; xnt[1]=a; xnt[2]=b; ntex->Fill(xnt); 1063 if(lp>1) 1064 cout<<"Fit["<<k<<","<<k+npt_gliss-1<<"] f0="<<xnt[2]<<" pente="<<xnt[1]<<endl; 1065 } 1066 delete [] npix; delete [] flux; delete [] err; 1067 } 1068 1069 // Display des resultats, fenetre 2x2 {{flux%ns,fond%ns},{f0,pente}} 1070 if(ex) app->CreateGraphWin(2,2); else app->CreateGraphWin(1,2); 1071 dummy = nom+"*"; omg.DelObjects(dummy); 1072 1073 dummy=nom+"pav"; omg.AddObj(pav,dummy); 1074 1075 string xd=""; string yd=""; string zd,exd,eyd,ezd; 1076 dummy=nom+"flux"; omg.AddObj(ntfl,dummy); 1077 xd="npx"; yd="flux"; 1078 omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt); 1079 if(typ_fond==2) 1080 {xd="npx"; yd="fond"; omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt);} 1081 if(ex) { 1082 dummy=nom+"fit"; omg.AddObj(ntex,dummy); 1083 if(typ_fond!=2) 1084 {xd="a"; yd="f0"; omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt);} 1085 xd = "k"; yd = "f0"; 1086 omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt); 1087 xd = "k"; yd = "a"; 1088 omg.DisplayNT(omg.LastObjName(),xd,yd,zd,exd,eyd,ezd,opt); 1089 } 1090 1091 return(0); 1092 } 1093 #endif 373 374 static string* videstr = NULL; 375 /* --Methode-- */ 376 string& PIACmd::GetUsage(const string& kw) 377 { 378 CmdExmap::iterator it = cmdexmap.find(kw); 379 if (it == cmdexmap.end()) { 380 if (videstr == NULL) videstr = new string(""); 381 return(*videstr); 382 } 383 else return( (*it).second.us ); 384 } 385 386 /* --Methode-- */ 387 void PIACmd::ShowHelpWindow() 388 { 389 helpwin->Show(); 390 } -
trunk/SophyaPI/PIext/piacmd.h
r174 r293 7 7 #define PIACMD_H_SEEN 8 8 9 #include " defs.h"10 9 #include "machdefs.h" 10 #include <iostream.h> 11 11 #include <fstream.h> 12 12 #include <string> 13 #include <vector> 13 14 #include <map> 14 15 #if defined(__KCC__) 15 16 using std::string ; 17 #include <vector.h> 16 18 #include <map.h> 17 19 #endif 18 20 19 #include "pdlmgr.h"20 21 #include "ctimer.h"22 21 #include "dlftypes.h" 23 22 23 24 // Classe definissant l'interface pour un executeur de commande 25 class CmdExecutor { 26 public: 27 virtual ~CmdExecutor() {} ; 28 // keyw : Le mot cle associe , args: Arguments de la commande 29 virtual int Execute(string& keyw, vector<string>& args)=0; 30 }; 31 32 // Classe definissant l'interface pour un interpreteur de commande 33 class CmdInterpreter { 34 public: 35 virtual ~CmdInterpreter() {} ; 36 virtual string Name()=0; 37 virtual int Interpret(string& line)=0; 38 }; 39 40 41 42 // Forward declaration of some classes ... 24 43 class NamedObjMgr; 25 44 class PIStdImgApp; 45 class Timer; 46 class PDynLinkMgr; 47 class PIAHelpWind; 26 48 49 // --------------------------------------------------------------------- 50 // Classe Interpreteur de commande, gestionnaire de module chargeable, 51 // et de fonctions dynamiquement linke pour PIStdImgApp 52 // Permet de gerer plusieurs Interpreter differents 53 // --------------------------------------------------------------------- 27 54 28 class PIACmd {55 class PIACmd : public CmdInterpreter { 29 56 public: 30 PIACmd(NamedObjMgr* omg=NULL, PIStdImgApp* app=NULL); 31 ~PIACmd(); 32 int Exec(string& file); 33 int Do(string& line); 57 static PIACmd* GetInterpreter(); 34 58 35 // Link dynamique de fonction user 36 int LinkUserFuncs(string& fnameso, string& func1, string& func2, string& func3); 37 // string& func4, string& func5); compil avec g++ 2.7.2 59 PIACmd(NamedObjMgr* omg, PIStdImgApp* app); 60 virtual ~PIACmd(); 61 virtual string Name(); 62 63 virtual void RegisterCommand(string& keyw, string& usage, CmdExecutor * ce); 64 virtual void LoadModule(string& fnameso, string& name); 65 66 virtual void AddInterpreter(CmdInterpreter * cl); 67 virtual void SelInterpreter(string& name); 68 69 virtual int Interpret(string& line); 70 virtual int ExecFile(string& file); 71 72 virtual string& GetUsage(const string& kw); 73 virtual void ShowHelpWindow(); 74 75 inline CmdInterpreter* CurrentInterpreter() { return(curcmdi); } 76 inline CmdExecutor* BaseExecutor() { return(basexec); } 77 inline PIStdImgApp* GetImgApp() { return(mImgApp); } 78 79 protected: 38 80 NamedObjMgr* mObjMgr; 39 81 PIStdImgApp* mImgApp; 40 bool mOmg;41 82 83 CmdInterpreter* curcmdi; 84 CmdExecutor* basexec; 85 86 // Pour enregistrer la liste de commandes et leurs executeurs 87 struct cmdex {string us; CmdExecutor * cex; } ; 88 typedef map<string, cmdex, less<string> > CmdExmap; 89 CmdExmap cmdexmap; 90 91 // Pour garder la liste des modules 92 typedef map<string, PDynLinkMgr* , less<string> > Modmap; 93 Modmap modmap; 94 95 // Pour garder la liste des interpreteur 96 typedef map<string, CmdInterpreter*, less<string> > InterpMap; 97 InterpMap interpmap; 98 42 99 // Pour stocker les variables definies par l'interpreteur 43 typedef map<string, string, less<string> > CmdVarList; 44 100 typedef map<string, string, less<string> > CmdVarList; 45 101 CmdVarList mVars; // Liste des variables 46 102 ofstream hist; // History file … … 49 105 Timer* gltimer; // pour Display CPU Time 50 106 51 // g++ n'arrive pas a avaler ca (lignes trop longues) on utilise donc des DlFunction (Reza 20/08/98) 52 // typedef map<string, DlUserProcFunction, less<string> > UsFmap; 53 typedef map<string, DlFunction, less<string> > UsFmap; 54 PDynLinkMgr* dynlink; 55 UsFmap usfmap; 107 // Fenetre d'aide interactive 108 PIAHelpWind* helpwin; 56 109 57 110 }; 58 111 112 113 59 114 #endif -
trunk/SophyaPI/PIext/piinit.cc
r165 r293 1 #include " defs.h"1 #include "machdefs.h" 2 2 #include "piinit.h" 3 3 … … 6 6 7 7 PeidaInteractiveInitiator::PeidaInteractiveInitiator() 8 : Peida ImagesInitiator()8 : PeidaOutilsInitiator() 9 9 { 10 10 FgInit++; -
trunk/SophyaPI/PIext/piinit.h
r165 r293 2 2 #define PIINIT_H_SEEN 3 3 4 #include " imaginit.h"4 #include "outilsinit.h" 5 5 6 6 // Classe d'initialisation pour le module PI de PEIDA 7 7 8 class PeidaInteractiveInitiator : public Peida ImagesInitiator{8 class PeidaInteractiveInitiator : public PeidaOutilsInitiator { 9 9 private: 10 10 static int FgInit; -
trunk/SophyaPI/PIext/pisiadw.cc
r206 r293 1 #include "machdefs.h" 1 2 #include <stdlib.h> 2 3 #include <stdio.h> 3 4 #include <string.h> 4 #include "machine.h"5 5 6 6 #include "perrors.h" … … 149 149 mLab[0] = new PILabel(this, "filename", tsx-spx, bsy-spy, spx/2, spy/2); 150 150 mLab[0]->SetLabel(""); 151 mLab[0]->SetBinding(PIBK_elastic, PIBK_fixed, PIBK_elastic,PIBK_fixed);151 mLab[0]->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic,PIBK_elastic); 152 152 mLab[0]->SetBorderWidth(1); 153 153 -
trunk/SophyaPI/PIext/pisiadw.h
r165 r293 15 15 16 16 class PIStdImgApp; 17 18 19 20 17 21 18 -
trunk/SophyaPI/PIext/pistdimgapp.cc
r210 r293 1 #include "machdefs.h" 1 2 #include <stdlib.h> 2 3 #include <stdio.h> … … 10 11 #endif 11 12 12 #include "machine.h"13 13 14 14 #include "strutil.h" … … 30 30 31 31 32 // Il faudra virer ca (?) Reza 19/08/9833 // #include "parmst.h"34 // #define FLAG_MAINGLPARMPIA 135 // #include "glparmpia.h"36 32 static char ImgDir[256]; 37 33 static char WorkDir[256]; … … 49 45 // Les menus 50 46 m[0] = new PIMenu(Menubar(),"Fichier"); 47 m[0]->AppendItem("Help", 10100); 51 48 m[0]->AppendItem("Open-Fits", 10120); 52 49 m[0]->AppendItem("Open-PPF", 10130); … … 66 63 m[2]->AppendItem("Extract Pave", 10305); 67 64 m[2]->SetSensitivityMsg(10305, false); 65 m[2]->AppendItem("Cuts X,Y", 10306); 66 m[2]->SetSensitivityMsg(10306, false); 68 67 mc = new PIMenu(m[2], "StackTools"); 69 68 mc->AppendItem("DispNext", 10320); … … 100 99 m[5]->AppendCheckItem("Catch SigFPE/SEGV", 10603); 101 100 101 m[6] = new PIMenu(Menubar(),"Modules"); 102 102 103 AppendMenu(m[0]); 103 104 AppendMenu(m[1]); … … 106 107 AppendMenu(m[4]); 107 108 AppendMenu(m[5]); 109 AppendMenu(m[6]); 108 110 109 111 int scsx, scsy; … … 131 133 mCons->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_fixed); 132 134 mCons->AcceptCmd(true, 50); 135 redirecout = false; 133 136 // RedirectStdOutErr(true); pas par defaut 134 137 … … 151 154 152 155 pfc = new PIFileChooser(this,"FileChooser", 5000); 153 154 // mCutTC = new CutTools(this, this->MainWin());155 156 156 157 mObjmgrw = new ObjMgrWind(this); … … 200 201 201 202 delete mc; 202 for(i=0; i< 6; i++)203 for(i=0; i<7; i++) 203 204 if (m[i]) delete m[i]; 204 205 … … 242 243 if (smm == PIMsg_Active) 243 244 { 244 sndw = (PIWdg *)sender;245 sndw = dynamic_cast<PIWdg *>(sender); 245 246 switch(sndw->kind()) 246 247 { 247 248 case PIWindow::ClassId : 248 mCurWin = (PIWindow *)sender;249 mCurWin = dynamic_cast<PIWindow *>(sndw); 249 250 break; 250 251 251 252 case PIScDrawWdg::ClassId : 252 253 case PIDraw3DWdg::ClassId : 253 mCurWdg = (PIBaseWdg *)sender;254 mCurWdg = dynamic_cast<PIBaseWdg *>(sender); 254 255 // cerr << "*DBG11* ImgTools -> NonSensitive " << sndw->kind() << endl; 255 256 if (mFgCWImg) { 256 257 // cerr << "*DBG* ImgTools -> NonSensitive " << endl; 257 258 m[2]->SetSensitivityMsg(10305, false); 259 m[2]->SetSensitivityMsg(10306, false); 258 260 m[4]->SetSensitivityMsg(10515, false); 259 261 m[4]->SetSensitivityMsg(10516, false); … … 262 264 break; 263 265 case PIImage::ClassId : 264 mCurWdg = (PIBaseWdg *)sender;266 mCurWdg = dynamic_cast<PIBaseWdg *>(sender); 265 267 if (!mFgCWImg) { 266 268 // cerr << "*DBG* ImgTools -> Sensitive " << endl; 267 269 m[2]->SetSensitivityMsg(10305, true); 270 m[2]->SetSensitivityMsg(10306, true); 268 271 m[4]->SetSensitivityMsg(10515, true); 269 272 m[4]->SetSensitivityMsg(10516, true); … … 271 274 } 272 275 break; 276 /* 277 default : 278 mCurWdg = NULL; 279 if (mFgCWImg) { 280 m[2]->SetSensitivityMsg(10305, false); 281 m[2]->SetSensitivityMsg(10306, false); 282 m[4]->SetSensitivityMsg(10515, false); 283 m[4]->SetSensitivityMsg(10516, false); 284 mFgCWImg = false; 285 } 286 break; 287 */ 273 288 } 274 289 } … … 301 316 SetBusy(); 302 317 TRY { 303 CmdInterpreter()->Do(s);318 mCmd->Interpret(s); 304 319 } CATCH(merr) { 305 320 fflush(stdout); … … 448 463 if (title.length() <= 0) title = name; string t2=""; 449 464 scw->SetTitles(title, t2); 450 // scw->Refresh(); Pas necessaire Reza 19/08/98$CHECK$465 // scw->Refresh(); ? Pas necessaire Reza 19/08/98, 05/05/99 $CHECK$ 451 466 mCurWin = win; 452 467 mCurWdg = scw; … … 495 510 if (title.length() <= 0) title = name; string t2=""; 496 511 wd3->SetTitles(title, t2); 497 // wd3->Refresh(); Pas necessaire512 // wd3->Refresh(); ?Pas necessaire $CHECK$ 05/05/99 498 513 mCurWin = win; 499 514 mCurWdg = wd3; … … 522 537 mWList[mWId*10+1] = (PIWindow*)win; 523 538 win->SetAutoDelChilds(true); 524 win->Show();539 // win->Show(); 525 540 mGrW = win; 526 541 mGrIdx = 0; … … 540 555 mWList[mWId*10+2] = (PIWindow*)win; 541 556 win->SetAutoDelChilds(true); 542 win->Show();557 // win->Show(); 543 558 mStW = win; 544 559 m[2]->SetSensitivity("StackTools", true); … … 588 603 mWList[mWId*10] = rw; 589 604 rw->SetAutoDelChilds(true); 590 rw->Show();605 // rw->Show(); 591 606 px = py = 0; 592 607 flag = 0; … … 595 610 } 596 611 597 //rw->Show();612 rw->Show(); 598 613 mCurWin = rw; 599 614 return(rw); … … 713 728 RedirectErrStream(mCons); 714 729 m[5]->SetStateMsg(10602, true); 730 redirecout = true; 715 731 } 716 732 else { … … 718 734 RedirectErrStream(NULL); 719 735 m[5]->SetStateMsg(10602, false); 736 redirecout = false; 720 737 } 721 738 return; … … 745 762 switch(msg) 746 763 { 764 case 10100 : 765 mCmd->ShowHelpWindow(); 766 break; 767 747 768 case 10120 : 748 769 pfc->SetPath(ImgDir); … … 894 915 ObjMgr()->AddObj(pim, nom); 895 916 ObjMgr()->DisplayObj(nom, "w"); 917 break; 918 } 919 920 case 10306 : 921 { 922 PIImage* curpimg = NULL; 923 if (!mCurWdg) return; 924 if (mCurWdg->kind() != PIImage::ClassId) return; 925 curpimg = (PIImage*)mCurWdg; 926 if (curpimg == NULL) return; 927 curpimg->ShowCuts(true); 928 break; 896 929 } 897 930 -
trunk/SophyaPI/PIext/pistdimgapp.h
r203 r293 72 72 inline PIConsole* GetConsole() { return mCons; } 73 73 74 // inline CutTools* CutTC() { return mCutTC; } A reactiver plus tard ? Reza 08/98 74 inline PIMenu* SpecialMenu() { return m[5]; } 75 inline PIMenu* ModulesMenu() { return m[6]; } 75 76 76 77 inline ObjMgrWind* ObjMgrW() { return mObjmgrw; } … … 79 80 // Redirection ou Non de StdOut/StdErr 80 81 void RedirectStdOutErr(bool fg = true); 82 inline bool HasRedirectedStdOutErr() { return(redirecout); } 81 83 // Gestion des signaux 82 84 void CatchSignals(bool fg = true); … … 117 119 PIACmd* mCmd; 118 120 119 PIMenu* m[ 6];121 PIMenu* m[7]; 120 122 PIMenu* mc; 121 123 … … 126 128 PIFileChooser * pfc; 127 129 128 // CutTools* mCutTC; // mTCId = 3 A reactiver plus tard ? Reza 08/98129 // PIContainer* mTC; A reactiver plus tard ? Reza 08/98130 131 130 PIConsole* mCons; 131 bool redirecout; // true if stdout/err redirected to mCons; 132 132 133 133 WindMList mWList; -
trunk/SophyaPI/PIext/servnobjm.cc
r203 r293 32 32 33 33 // Si le module StarReco++ a ete compile (Pour les StarList, Transfo, etc ... 34 #if ndef SANS_StarReco34 #ifdef SANS_EVOLPLANCK 35 35 #include "stlist.h" 36 36 #include "star.h" … … 98 98 break; 99 99 100 #if ndef SANS_StarReco100 #ifdef SANS_EVOLPLANCK 101 101 case ClassId_StarList : 102 102 vardec = "double x,y,flux,fond; \n"; … … 222 222 break; 223 223 224 #if ndef SANS_StarReco224 #ifdef SANS_EVOLPLANCK 225 225 case ClassId_StarList : 226 226 { … … 306 306 int rc; 307 307 308 cmd = "rm " + fname;308 cmd = "rm -f " + fname; 309 309 rc = system(cmd.c_str()); 310 310 //DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc); … … 514 514 return("ZFidu"); 515 515 516 #if ndef SANS_StarReco516 #ifdef SANS_EVOLPLANCK 517 517 case ClassId_StarList : 518 518 return("StarList"); … … 585 585 return("Fidu"); 586 586 587 #if ndef SANS_StarReco587 #ifdef SANS_EVOLPLANCK 588 588 case ClassId_StarList : 589 589 return("Stl"); … … 678 678 GrAlines["thickdottedline"] = gi; 679 679 680 // Les fontes (a faire)680 // Les fontes 681 681 gi.a2 = PI_NotDefFontSize; 682 682 gi.a1 = PI_NotDefFontAtt; -
trunk/SophyaPI/PIext/servnobjm.h
r203 r293 7 7 #define SERVNOBJM_H_SEEN 8 8 9 #include " defs.h"9 #include "machdefs.h" 10 10 #include <string> 11 11
Note:
See TracChangeset
for help on using the changeset viewer.