Index: trunk/Poubelle/archTOI.old/archtoi.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archtoi.cc	(revision 357)
+++ trunk/Poubelle/archTOI.old/archtoi.cc	(revision 358)
@@ -11,4 +11,5 @@
 #include "toisvr.h"
 #include "archtoi.h"
+#include "asigps.h"
 
 using namespace std; 
@@ -159,4 +160,8 @@
     sscanf(arg.c_str(), "%lg", &t0);
     svr.SetPerEch(t0);
+  } else if (key == "#ASIGPS") {
+    ASIGPS* gps = new ASIGPS(arg);
+    gps->FitsDump("GPSDump.fits");
+    svr.UseAuxGPS(gps);
   } else if (key == "#END") {
     return false;
Index: trunk/Poubelle/archTOI.old/asigps.cc
===================================================================
--- trunk/Poubelle/archTOI.old/asigps.cc	(revision 358)
+++ trunk/Poubelle/archTOI.old/asigps.cc	(revision 358)
@@ -0,0 +1,51 @@
+#include "asigps.h"
+#include <fstream.h>
+
+ASIGPS::ASIGPS(string const& filename) {
+  readFile(filename);
+}
+
+void ASIGPS::readFile(string const& filename) {
+  ifstream f(filename.c_str());
+  while (f) {
+    char line[200];
+    f.getline(line,200);
+    if (!f) break;
+    char*p = line;
+    double mjd, lat, lon, alt;
+    if (*p != '3' && *p != '2') continue;
+    p++;
+    if (*p != 'D' && *p != 'd') continue;
+    p+=3;
+    if (strncmp(p,"99/jul/1",8)) continue;
+    p+=8;
+    if (*p == '7') mjd = 1376.5;
+    else if (*p == '8') mjd = 1377.5;
+    else continue;
+    p++;p++;
+    int h,m,s;
+    sscanf(p,"%2d:%2d:%2d",&h,&m,&s);
+    mjd += (h+m/60.+s/3600.)/24.;
+    p += 9;
+    if (*p == 'N') s = 1;
+    else if (*p == 'S') s = -1;
+    else continue;
+    p++;
+    int d,fm;
+    sscanf(p,"%2d.%2d,%3d",&d,&m,&fm);
+    lat = s*(d + m/60. + fm/60000.);
+    p+=10;
+    if (*p == 'E') s = 1;
+    else if (*p == 'W') s = -1;
+    else continue;
+    p++;
+    sscanf(p,"%3d.%2d,%3d",&d,&m,&fm);
+    lon = s*(d + m/60. + fm/60000.);
+    p+=11;
+    sscanf(p,"%5d",&d);
+    alt = d;
+    p+=5;
+    if (*p != 'm') continue;
+    AddValue(mjd, lat, lon, alt);
+  }
+}
Index: trunk/Poubelle/archTOI.old/asigps.h
===================================================================
--- trunk/Poubelle/archTOI.old/asigps.h	(revision 358)
+++ trunk/Poubelle/archTOI.old/asigps.h	(revision 358)
@@ -0,0 +1,20 @@
+#ifndef ASIGPS_H
+#define ASIGPS_H
+
+#include "auxinterpgps.h"
+#include <string>
+
+class ASIGPS : public AuxInterpGPS {
+public:
+  ASIGPS() {}
+  ASIGPS(string const& filename);
+  
+  void readFile(string const& filename);
+  
+  virtual AuxGPS* clone() {return new ASIGPS(*this);}
+
+protected:
+
+};
+
+#endif
Index: trunk/Poubelle/archTOI.old/auxgps.h
===================================================================
--- trunk/Poubelle/archTOI.old/auxgps.h	(revision 358)
+++ trunk/Poubelle/archTOI.old/auxgps.h	(revision 358)
@@ -0,0 +1,14 @@
+#ifndef AUXGPS_H
+#define AUXGPS_H
+
+class AuxGPS {
+public:
+  virtual ~AuxGPS() {}
+
+  virtual int getLocation(double mjd, double& lat, double& lon, double& alt)=0;
+  virtual AuxGPS* clone()=0;
+
+
+};
+
+#endif
Index: trunk/Poubelle/archTOI.old/auxinterpgps.cc
===================================================================
--- trunk/Poubelle/archTOI.old/auxinterpgps.cc	(revision 358)
+++ trunk/Poubelle/archTOI.old/auxinterpgps.cc	(revision 358)
@@ -0,0 +1,64 @@
+#include "auxinterpgps.h"
+#include "fitsio.h"
+#include "archtoi.h"
+
+AuxInterpGPS::AuxInterpGPS() {
+  ilastok = false;
+}
+
+void AuxInterpGPS::AddValue(double mjd, double lat, double lon, double alt) {
+  elems.insert(elem(mjd, lat, lon, alt));
+  ilastok = false;
+}
+
+void AuxInterpGPS::FindElem(double mjd) {
+  ilast = elems.lower_bound(elem(mjd,0,0,0));
+  ilastok = (ilast != elems.end());
+}
+
+
+int AuxInterpGPS::getLocation(double mjd, double& lat, double& lon, double& alt) {
+  if (!ilastok ||
+      (mjd <= (*ilast).mjd)) {
+    FindElem(mjd);
+  } else {
+    set<elem>::const_iterator i = ilast; i++;
+    if (mjd > (*i).mjd) FindElem(mjd);
+  }
+
+  if (!ilastok) return -1;
+  if (mjd <= (*ilast).mjd) return -1;
+  set<elem>::const_iterator i = ilast; i++;
+  if (mjd > (*i).mjd) return -1;
+  
+  double x = (mjd - (*ilast).mjd) / ((*i).mjd - (*ilast).mjd);
+  
+  lat = (*ilast).lat*(1-x) + (*i).lat*x;
+  lon = (*ilast).lon*(1-x) + (*i).lon*x;
+  alt = (*ilast).alt*(1-x) + (*i).alt*x;
+  
+  return 0;
+}
+
+void AuxInterpGPS::FitsDump(string const& filename) {
+  int fitsStatus=0;
+  fitsfile* fptr;
+  remove(filename.c_str());
+  fits_create_file(&fptr, filename.c_str(), &fitsStatus);
+  char* colnames[4] = {"MJD","LATITUDE","LONGITUDE","ALTITUDE"};
+  char* coltypes[4] = {"1D","1D","1D","1D"};
+  char* colunits[4] = {" ", " " , " ", " "};
+  fits_create_tbl(fptr, BINARY_TBL, 0, 4, colnames, coltypes, colunits, NULL, &fitsStatus);
+  fits_write_date(fptr, &fitsStatus);
+  fits_write_comment(fptr, "Generated with archtoi " ARCHTOI_VERS, &fitsStatus);
+  int fitsLine = 1;
+  for (set<elem>::iterator i = elems.begin(); i != elems.end(); i++,fitsLine++) {
+    fits_write_col_dbl(fptr, 1, fitsLine, 1, 1, &(*i).mjd, &fitsStatus);
+    fits_write_col_dbl(fptr, 2, fitsLine, 1, 1, &(*i).lat, &fitsStatus);
+    fits_write_col_dbl(fptr, 3, fitsLine, 1, 1, &(*i).lon, &fitsStatus);
+    fits_write_col_dbl(fptr, 4, fitsLine, 1, 1, &(*i).alt, &fitsStatus);
+  }
+
+  fits_close_file(fptr, &fitsStatus);
+  fits_report_error(stderr, fitsStatus);  /* print out any error messages */
+}
Index: trunk/Poubelle/archTOI.old/auxinterpgps.h
===================================================================
--- trunk/Poubelle/archTOI.old/auxinterpgps.h	(revision 358)
+++ trunk/Poubelle/archTOI.old/auxinterpgps.h	(revision 358)
@@ -0,0 +1,39 @@
+#ifndef AUXINTERPGPS_H
+#define AUXINTERPGPS_H
+
+#include "auxgps.h"
+#include <set>
+#include <string>
+
+using namespace std;
+
+class AuxInterpGPS : public AuxGPS {
+public:
+  AuxInterpGPS();
+  virtual int getLocation(double mjd, double& lat, double& lon, double& alt);
+  
+  void FitsDump(string const& filename);
+  virtual AuxGPS* clone() {return new AuxInterpGPS(*this);}
+
+protected:
+  virtual void AddValue(double mjd, double lat, double lon, double alt);
+  virtual void FindElem(double mjd);
+
+  struct elem {
+     elem() {}
+     elem(double m, double la, double lo, double a)
+      : mjd(m), lat(la), lon(lo), alt(a) {}
+     double mjd;
+     double lat;
+     double lon;
+     double alt;
+     bool operator == (elem const& x) const {return mjd == x.mjd;}
+     bool operator < (elem const& x) const {return mjd < x.mjd;}
+  };
+  
+  set<elem> elems;
+  set<elem>::const_iterator ilast;
+  bool ilastok;
+};
+
+#endif
Index: trunk/Poubelle/archTOI.old/toiiter.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toiiter.cc	(revision 357)
+++ trunk/Poubelle/archTOI.old/toiiter.cc	(revision 358)
@@ -38,4 +38,6 @@
  lastSample = -1;
  maxLookAhead = 10000;
+ 
+ auxGPS = NULL;
 
 }
@@ -72,4 +74,7 @@
   lastSample = x.lastSample;
   maxLookAhead = x.maxLookAhead;
+  
+  auxGPS = x.auxGPS; 
+  if (auxGPS) auxGPS = auxGPS->clone();
 }
 
@@ -78,4 +83,5 @@
   delete rawIter;
   delete[] interp;
+  delete auxGPS;
 }
 
@@ -311,5 +317,5 @@
   while (1) {
     if (!NextSample()) return false; // end of files
-    double t = tBlock0+(file->blockNum() * file->nEchBlock() + imes) * perEch/86400.;
+    double t = getMJD();
     if (t < tStart) continue;
     if (t > tEnd) return false;
@@ -378,8 +384,13 @@
 bool TOIIter::canGetValue(int column) {
    if (column < 0 || column >= infos.size()) return false;
+   TOIKind kind = infos[column].kind;
+   if (auxGPS && 
+       (kind == longitude || kind == latitude || kind == altitude)) {
+         double dummy;
+         return auxGPS->getLocation(getMJD(), dummy, dummy, dummy) == 0;
+   }
    if (rawIter) {
        return interp[column].canGet(lastSample);
    }
-   TOIKind kind = infos[column].kind;
    int index = infos[column].index;
    switch (kind) {
@@ -418,4 +429,13 @@
 double TOIIter::getValue(int column) {
    if (column < 0 || column >= infos.size()) return -1;
+   TOIKind kind = infos[column].kind;
+   if (auxGPS && 
+       (kind == longitude || kind == latitude || kind == altitude)) {
+         double lat,lon,alt;
+         if (auxGPS->getLocation(getMJD(), lat, lon, alt)) return -99999;
+         if (kind == longitude) return lon;
+         if (kind == latitude)  return lat;
+         if (kind == altitude)  return alt;         
+   }
    if (rawIter) {
      if (infos[column].interpolated)
@@ -424,20 +444,12 @@
        return interp[column].getEValue(lastSample);
    }
-   TOIKind kind = infos[column].kind;
    int index = infos[column].index;
    switch (kind) {
      case sampleNum:
-       return file->blockNum() * file->nEchBlock() + imes;
+       return getSampleIndex();
      case internalTime:
-       //return (file->blockNum() * file->nEchBlock() + imes) * file->perEchant();
-       return (file->blockNum() * file->nEchBlock() + imes) * perEch;
+       return getSampleIndex() * perEch;
      case mjd:
-      /* printf("mjd: %d %d %g %g %g\n",file->blockNum(),
-         (file->blockNum() * file->nEchBlock() + imes),
-         file->perEchant(),
-         (file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.,
-         tBlock0+(file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.); */
-       //return tBlock0+(file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.;
-       return tBlock0+(file->blockNum() * file->nEchBlock() + imes) * perEch/86400.;
+       return getMJD();
      case boloTens:
        return file->getMuVBolo(index, imes);
@@ -474,8 +486,12 @@
 bool   TOIIter::newValue(int column) {
    if (column < 0 || column >= infos.size()) return false;
+   TOIKind kind = infos[column].kind;
+   if (auxGPS && 
+       (kind == longitude || kind == latitude || kind == altitude)) {
+      return true;
+   }
    if (rawIter) {
        return interp[column].isNewValue(lastSample);
    }
-   TOIKind kind = infos[column].kind;
    switch (kind) {
      case sampleNum:
@@ -567,4 +583,9 @@
    }
 }
+
+double TOIIter::getMJD() {
+  int sample = getSampleIndex();
+  return tBlock0 + sample*perEch/86400.;
+}
  
 bool TOIIter::fetchAhead() { // Seulement si delegation
Index: trunk/Poubelle/archTOI.old/toiiter.h
===================================================================
--- trunk/Poubelle/archTOI.old/toiiter.h	(revision 357)
+++ trunk/Poubelle/archTOI.old/toiiter.h	(revision 358)
@@ -11,4 +11,5 @@
 #include <string>
 #include "archeopsfile.h"
+#include "auxgps.h"
 
 enum TOIKind {
@@ -61,4 +62,5 @@
    int    getBlockSampleIndex();        // numero d''echantillon dans dernier bloc bolo
    int    getSampleIndex();             // numero d''echantillon 
+   double getMJD();            
 
    block_type_param*         lastParam();  
@@ -125,4 +127,6 @@
    bool fetchAhead(); // avance d''une TOI en nourrissant les interpolateurs
    
+   AuxGPS* auxGPS;
+   
    private:
 };
Index: trunk/Poubelle/archTOI.old/toisvr.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toisvr.cc	(revision 357)
+++ trunk/Poubelle/archTOI.old/toisvr.cc	(revision 358)
@@ -15,4 +15,10 @@
   iter.files.insert(f);
 }
+
+void TOISvr::UseAuxGPS(AuxGPS* gps) {
+  if (iter.auxGPS) delete iter.auxGPS;
+  iter.auxGPS = gps;
+}
+
 
 void TOISvr::SetMJD0(double t0) {
Index: trunk/Poubelle/archTOI.old/toisvr.h
===================================================================
--- trunk/Poubelle/archTOI.old/toisvr.h	(revision 357)
+++ trunk/Poubelle/archTOI.old/toisvr.h	(revision 358)
@@ -7,4 +7,6 @@
 
 #include "toiiter.h"
+
+class AuxGPS;
 
 class TOISvr {
@@ -17,4 +19,5 @@
   void SetMJD0(double);
   void SetPerEch(double);
+  void UseAuxGPS(AuxGPS* gps);
   
   void SetTimeInterval(double tStart, double tEnd);
