| [1739] | 1 | #include "machdefs.h"
 | 
|---|
 | 2 | #include "toimanager.h"
 | 
|---|
 | 3 | #include "pexceptions.h"
 | 
|---|
 | 4 | #include "smoothtoi.h"
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 | 
 | 
|---|
 | 7 | ////////////////////////////////////////////////////////////////////////
 | 
|---|
 | 8 | // Calcul d'une valeur lissee
 | 
|---|
 | 9 | // |--lsm--|<sample>|--lsm--|
 | 
|---|
 | 10 | ////////////////////////////////////////////////////////////////////////
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | DataSmooth::DataSmooth(uint_4 lsm,uint_4 deg)
 | 
|---|
 | 13 |   : LSmooth(lsm), DegSmooth(deg)
 | 
|---|
 | 14 | {
 | 
|---|
 | 15 |  if(DegSmooth>2) DegSmooth=2;
 | 
|---|
 | 16 |  if(LSmooth<DegSmooth+1) LSmooth = DegSmooth+1;
 | 
|---|
 | 17 |  DoNotLookAt();
 | 
|---|
 | 18 |  SetFlagFailed();
 | 
|---|
 | 19 |  SetBuffUpd();
 | 
|---|
 | 20 |  MinSmoothLength();
 | 
|---|
 | 21 | }
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | DataSmooth::~DataSmooth()
 | 
|---|
 | 24 | {
 | 
|---|
 | 25 | }
 | 
|---|
 | 26 | 
 | 
|---|
| [1762] | 27 | void DataSmooth::Print(::ostream & os)
 | 
|---|
| [1739] | 28 | {
 | 
|---|
 | 29 |  os<<"DataSmooth::Print LSmooth="<<LSmooth
 | 
|---|
 | 30 |    <<" LSmoothMin="<<LSmoothMin
 | 
|---|
 | 31 |    <<" DegSmooth="<<DegSmooth<<endl
 | 
|---|
 | 32 |    <<" .... BuffUpdate="<<BuffUpdate
 | 
|---|
 | 33 |    <<" flgNotLookAt="<<flgNotLookAt
 | 
|---|
 | 34 |    <<" flgNotSmoothed="<<flgNotSmoothed<<endl;
 | 
|---|
 | 35 | }
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | void DataSmooth::init()
 | 
|---|
 | 38 | {
 | 
|---|
 | 39 |  cout << "DataSmooth::init" << endl;
 | 
|---|
 | 40 |  declareInput("DataIn");       // input index 0
 | 
|---|
 | 41 |  declareOutput("DataSmooth");     // output index 0
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 |  int_4 lbuff = 2*LSmooth +10;
 | 
|---|
 | 44 |  if(neededHistory<lbuff) setNeededHistory(lbuff);
 | 
|---|
 | 45 | }
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | void DataSmooth::run()
 | 
|---|
 | 48 | {
 | 
|---|
 | 49 | long snb = getMinIn();
 | 
|---|
 | 50 | long sne = getMaxIn();
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | if(snb>sne) {
 | 
|---|
 | 53 |   cout<<"DataSmooth::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
 | 
|---|
 | 54 |   throw ParmError("DataSmooth::run() - Bad sample interval");
 | 
|---|
 | 55 | }
 | 
|---|
 | 56 | if(!checkInputTOIIndex(0)) {
 | 
|---|
 | 57 |   cout<<"DataSmooth::run() - Input TOI (DataIn) not connected! "<<endl;
 | 
|---|
 | 58 |   throw ParmError("DataSmooth::run() Input TOI (DataIn) not connected!");
 | 
|---|
 | 59 | }
 | 
|---|
 | 60 | if(!checkOutputTOIIndex(0)) {
 | 
|---|
 | 61 |   cout<<"DataSmooth::run() - Output TOI (DataOut) not connected! "<<endl;
 | 
|---|
 | 62 |   throw ParmError("DataSmooth::run() Output TOI (DataOut) not connected!");
 | 
|---|
 | 63 | }
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 | //---------------------------------------------------------
 | 
|---|
 | 66 | try {
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 |  SLinParBuff slb0(LSmooth,BuffUpdate,0.,0.,true);
 | 
|---|
 | 69 |  SLinParBuff slb1(LSmooth,BuffUpdate,0.,0.,true);
 | 
|---|
 | 70 |  SLinParBuffMerger slbm;
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | cout<<"DataSmooth::run(): SampleNum de "<<snb<<" a "<<sne<<endl;
 | 
|---|
 | 73 | uint_4 notsmoothed=0;
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | // Initialisation
 | 
|---|
 | 76 | for(int_4 sn=snb;sn<snb+LSmooth && sn<=sne;sn++) {
 | 
|---|
 | 77 |   r_8 bolo; uint_8 fgbolo=0;
 | 
|---|
 | 78 |   getData(0,sn,bolo,fgbolo);
 | 
|---|
 | 79 |   if(!(fgbolo & flgNotLookAt)) slb1.Push((r_8)sn,bolo);
 | 
|---|
 | 80 | }
 | 
|---|
 | 81 | 
 | 
|---|
| [1764] | 82 | {for(int_4 sn=snb;sn<=sne;sn++) {
 | 
|---|
| [1739] | 83 | 
 | 
|---|
 | 84 |   r_8 bolo; uint_8 fgbolo=0;
 | 
|---|
 | 85 |   getData(0,sn,bolo,fgbolo);
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 |   //    <---lms---><i><---lms--->
 | 
|---|
 | 88 |   //              |             |
 | 
|---|
 | 89 |   //             ideb          ifin
 | 
|---|
 | 90 |   int_4 ideb=sn-1, ifin=sn+LSmooth;
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 |   if(ideb>=snb) {
 | 
|---|
 | 93 |     r_8 bol; uint_8 fgb=0;
 | 
|---|
 | 94 |     getData(0,ideb,bol,fgb);
 | 
|---|
 | 95 |     if(fgb&flgNotLookAt) slb0.Pop();
 | 
|---|
 | 96 |       else slb0.Push((r_8)ideb,bol);
 | 
|---|
 | 97 |   }
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 |   if(ifin<=sne) {
 | 
|---|
 | 100 |     r_8 bol; uint_8 fgb=0;
 | 
|---|
 | 101 |     getData(0,ifin,bol,fgb);
 | 
|---|
 | 102 |     if(fgb&flgNotLookAt) slb1.Pop();
 | 
|---|
 | 103 |       else slb1.Push((r_8)ifin,bol);
 | 
|---|
 | 104 |   } else slb1.Pop();
 | 
|---|
 | 105 | 
 | 
|---|
 | 106 |   slbm.Reset(); slbm.Add(slb0); slbm.Add(slb1);
 | 
|---|
 | 107 | 
 | 
|---|
 | 108 |   if(slbm.NPoints()>=LSmoothMin) {
 | 
|---|
 | 109 |     r_8 s=-1.,a0,a1=0.,a2=0.;
 | 
|---|
 | 110 |     if(DegSmooth==0)      s = slbm.Compute(a0);
 | 
|---|
 | 111 |     else if(DegSmooth==1) s = slbm.Compute(a0,a1);
 | 
|---|
 | 112 |     else if(DegSmooth==2) s = slbm.Compute(a0,a1,a2);
 | 
|---|
 | 113 |     if(s>=0.) {
 | 
|---|
 | 114 |       bolo -= a0 + (a1 + a2*sn)*sn;
 | 
|---|
 | 115 |     } else {
 | 
|---|
 | 116 |       fgbolo |= flgNotSmoothed;
 | 
|---|
 | 117 |       notsmoothed++;
 | 
|---|
 | 118 |     }
 | 
|---|
 | 119 |   } else {
 | 
|---|
 | 120 |     fgbolo |= flgNotSmoothed;
 | 
|---|
 | 121 |     notsmoothed++;
 | 
|---|
 | 122 |   }
 | 
|---|
 | 123 | 
 | 
|---|
 | 124 |   putData(0,sn,bolo,fgbolo);
 | 
|---|
| [1764] | 125 | }}
 | 
|---|
| [1739] | 126 | cout<<"DataSmooth::run(): Fin de boucle: notsmoothed="<<notsmoothed
 | 
|---|
 | 127 |     <<" / tot="<<sne-snb+1<<endl;
 | 
|---|
 | 128 | 
 | 
|---|
 | 129 | //---------------------------------------------------------
 | 
|---|
 | 130 | } catch (PException & exc) {
 | 
|---|
 | 131 |   cout<<"DataSmooth: Catched Exception "<<(string)typeid(exc).name()
 | 
|---|
 | 132 |       <<"\n .... Msg= "<<exc.Msg()<<endl;
 | 
|---|
 | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | return;                                                                            
 | 
|---|
 | 136 | }
 | 
|---|