Index: trunk/Poubelle/archTOI.old/starmatcher.cc
===================================================================
--- trunk/Poubelle/archTOI.old/starmatcher.cc	(revision 581)
+++ trunk/Poubelle/archTOI.old/starmatcher.cc	(revision 612)
@@ -11,4 +11,6 @@
 
 #define STARDUMP
+
+#define TEchan TFin
 
 #include <math.h>
@@ -271,5 +273,6 @@
       
         double da = azim-az; if (da>360) da -= 360;
-        if (da < -0.6 || da > 0.4) continue;
+       // if (da < -0.6 || da > 0.4) continue; // appropriate for TEchan
+        if (da < -0.7 || da > 0.3) continue; // appropriate for TFin
         double elv0 = elv - GondolaGeom::sstPixelHeight * lastStar.NoDiode;
         if (fabs(elv0-GondolaGeom::elevSST0) > 0.25) continue; // Might be too strong
@@ -568,19 +571,37 @@
 int StarMatcher::getPendulInfo(double sampleNum, pendulInfo& info) {
 
+  static double lastSN = -1;
+  static pendulInfo lastPendul;
+  
+  if (sampleNum == lastSN) {
+    info = lastPendul;
+    return 0;
+  }
+
   PolFitClip2 fitPendul(30,2);
 
   map<double, pendulInfo>::iterator i = pendulInfos.lower_bound(sampleNum);
   if (i == pendulInfos.begin() && (*i).second.SN >= sampleNum) return -1;
-  if (i == pendulInfos.end()   && (*i).second.SN <= sampleNum) return -1;
-  
-  if ((*i).second.SN > sampleNum) i--;
+  if (i == pendulInfos.end()) return -1;
+  map<double, pendulInfo>::iterator last = pendulInfos.end();
+  if (last == pendulInfos.begin()) return -1;
+  last--;
+  if (i == last   && (*i).second.SN <= sampleNum) return -1;
+  
+  if ((*i).second.SN > sampleNum) i--; // i just before us...
+  
+  //$CHECK$ reject if too large a gap...
+  if (sampleNum - (*i).second.SN > 1000) return -1;
+  last = i; last++;
+  if ((*last).second.SN - sampleNum > 1000) return -1;
 
   int nn=0;
   double aziprev=0, azicur=0, azi0=0;
   for (map<double, pendulInfo>::iterator ii=i; ii != pendulInfos.begin(); ii--) {
-    nn++;
     pendulInfo inf1 = (*ii).second;
+    if (fabs(inf1.SN - sampleNum) > 1000) continue;
     aziprev = azicur;
     azicur = inf1.azPendul;
+    nn++;
     if (nn==1) azi0 = azicur;
     if (nn>1 && azicur - aziprev > 180)  azicur -= 360;
@@ -593,8 +614,9 @@
   if (i != pendulInfos.end()) i++;
   for (map<double, pendulInfo>::iterator ii=i; ii != pendulInfos.end(); ii++) {
-    nn++;
     pendulInfo inf1 = (*ii).second;
+    if (fabs(inf1.SN - sampleNum) > 1000) continue;
     aziprev = azicur;
     azicur = inf1.azPendul;
+    nn++;
     if (nn>1 && azicur - aziprev > 180)  azicur -= 360;
     if (nn>1 && azicur - aziprev < -180) azicur += 360;
@@ -610,101 +632,10 @@
   if (info.azPendul <   0) info.azPendul += 360;
   info.angPendul  = fitPendul.valueY(sampleNum);
+  
+  lastSN = sampleNum;
+  lastPendul = info;
+
   return 0;
 }
-
-#if 0
-
-int StarMatcher::getPendulInfo(double sampleNum, pendulInfo& info) {
-  static double* sn    = ::vector(1, 100);
-  static double* aziP  = ::vector(1, 100);
-  static double* ampP  = ::vector(1, 100);
-  static double* sig   = ::vector(1, 100);
-  static double* aAzi  = ::vector(1, 3);
-  static double* aAmp  = ::vector(1, 3);
-  static int*   ia    = ::ivector(1,3);
-  static double** cov  = ::matrix(1,3,1,3);
-  int ndata = 0;
-  map<double, pendulInfo>::iterator i = pendulInfos.lower_bound(sampleNum);
-  if (i == pendulInfos.begin() && (*i).second.SN >= sampleNum) return -1;
-  if (i == pendulInfos.end()   && (*i).second.SN <= sampleNum) return -1;
-  
-  if ((*i).second.SN > sampleNum) i--;
-
-  int nn=0;
-  for (map<double, pendulInfo>::iterator ii=i; ii != pendulInfos.begin(); ii--) {
-    nn++;
-    ndata++;
-    pendulInfo inf1 = (*ii).second;
-    sn[ndata]   = inf1.SN;
-    ampP[ndata] = inf1.angPendul;
-    aziP[ndata] = inf1.azPendul;
-    int prev = ndata-1;
-    if (ndata>1 && aziP[ndata] - aziP[prev] > 180)  aziP[ndata] -= 360;
-    if (ndata>1 && aziP[ndata] - aziP[prev] < -180) aziP[ndata] += 360;
-    sig[ndata]  = 1;
-    if (nn>=50) break;
-  }
-  
-  nn=0;
-  if (i != pendulInfos.end()) i++;
-  for (map<double, pendulInfo>::iterator ii=i; ii != pendulInfos.end(); ii++) {
-    nn++;
-    ndata++;
-    pendulInfo inf1 = (*ii).second;
-    sn[ndata]   = inf1.SN;
-    ampP[ndata] = inf1.angPendul;
-    aziP[ndata] = inf1.azPendul;
-    int prev = ndata-1;
-    if (nn==1) prev=1;
-    if (ndata>1 && aziP[ndata] - aziP[prev] > 180)  aziP[ndata] -= 360;
-    if (ndata>1 && aziP[ndata] - aziP[prev] < -180) aziP[ndata] += 360;
-    sig[ndata]  = 1;
-    if (nn>=50) break;
-  }
-  
-  if (ndata < 3) return -1;
-  
-  ia[1] = ia[2] = ia[3] = 1;
-  double chi2;
-  try {
-    lfit(sn, aziP,  sig, ndata, aAzi, ia, 3, cov, &chi2, polfunc);
-    lfit(sn, ampP,  sig, ndata, aAmp, ia, 3, cov, &chi2, polfunc);
-  } catch(string st) {
-    return -1;
-  }
-
-  info.SN = sampleNum;
-  info.azPendul   = polval(sampleNum, aAzi, 3);
-  if (info.azPendul > 360) info.azPendul -= 360;
-  if (info.azPendul <   0) info.azPendul += 360;
-  info.angPendul  = polval(sampleNum, aAmp, 3);
-  return 0;
-}
-
-#endif
-
-#if 0
-
-int StarMatcher::getPendulInfo(double sampleNum, pendulInfo& info) {
-  map<double, pendulInfo>::iterator i = pendulInfos.lower_bound(sampleNum);
-  if (i == pendulInfos.begin() && (*i).second.SN >= sampleNum) return -1;
-  if (i == pendulInfos.end()   && (*i).second.SN <= sampleNum) return -1;
-  
-  if ((*i).second.SN > sampleNum) i--;
-  pendulInfo inf1 = (*i).second;
-  i++;
-  pendulInfo inf2 = (*i).second;
-  
-  info.SN = sampleNum;
-  if (inf2.azPendul - inf1.azPendul > 180)  inf2.azPendul -= 360;
-  if (inf2.azPendul - inf1.azPendul < -180) inf2.azPendul += 360;
-  info.azPendul  = inf1.azPendul  + (inf2.azPendul  -  inf1.azPendul) * (sampleNum - inf1.SN) / (inf2.SN - inf1.SN);
-  if (info.azPendul<0)    info.azPendul += 360;
-  if (info.azPendul>360)  info.azPendul += 360;
-  info.angPendul = inf1.angPendul + (inf2.angPendul - inf1.angPendul) * (sampleNum - inf1.SN) / (inf2.SN - inf1.SN);
-  return 0;
-}
-
-#endif
 
 
