Index: /trunk/ArchTOIPipe/Kernel/Makefile.in
===================================================================
--- /trunk/ArchTOIPipe/Kernel/Makefile.in	(revision 1691)
+++ /trunk/ArchTOIPipe/Kernel/Makefile.in	(revision 1692)
@@ -100,10 +100,10 @@
 
 %.d: $(srcdir)/%.cc
-	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I.  $< \
+	$(SHELL) -ec '@gcc@ -MM $(CPPFLAGS) -I.  $< \
 		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
 		[ -s $@ ] || rm -f $@'
 
 %.d: $(srcdir)/%.c
-	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I. $< \
+	$(SHELL) -ec '@gcc@ -MM $(CPPFLAGS) -I. $< \
 		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
 		[ -s $@ ] || rm -f $@'
Index: /trunk/ArchTOIPipe/Kernel/asciitoiwtr.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/asciitoiwtr.cc	(revision 1691)
+++ /trunk/ArchTOIPipe/Kernel/asciitoiwtr.cc	(revision 1692)
@@ -19,4 +19,5 @@
   declareInput(name);
   fwinputs.push_back(toi);
+  toi->addConsumer(this);
 }
 
Index: /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1691)
+++ /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1692)
@@ -33,4 +33,5 @@
   nCols++;
   if (withFlag) nCols++;
+  toi->addConsumer(this);
 }
 
@@ -129,4 +130,5 @@
 	}
       }
+      wontNeedBefore(sn);
       fits_lock();
       //      if ((sn%2000 == 0) || (sn<snb+5)) 
Index: /trunk/ArchTOIPipe/Kernel/toi.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toi.h	(revision 1691)
+++ /trunk/ArchTOIPipe/Kernel/toi.h	(revision 1692)
@@ -98,5 +98,7 @@
 
   virtual void          setProducer(TOIProcessor* prod);
+public: // for toiprocessors redefining addInput. Change ?
   virtual void          addConsumer(TOIProcessor* prod);
+protected:
   friend class          TOIProcessor;
       
Index: /trunk/ArchTOIPipe/Kernel/toisegment.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toisegment.cc	(revision 1691)
+++ /trunk/ArchTOIPipe/Kernel/toisegment.cc	(revision 1692)
@@ -5,4 +5,13 @@
 #endif
 
+static pthread_mutex_t cout_mutex = PTHREAD_MUTEX_INITIALIZER;
+static void cout_lock() {pthread_mutex_lock(&cout_mutex);}
+static void cout_unlock() {pthread_mutex_unlock(&cout_mutex);}
+#define LOG(_xxx_) \
+cout_lock(); \
+_xxx_; \
+cout_unlock();
+
+
 /******************************/
 /******* TOISegmented *********/
@@ -21,4 +30,10 @@
 TOISegmented::~TOISegmented() {
   delete master;
+}
+
+
+void TOISegmented::addConsumer(TOIProcessor* p) {
+  TOI::addConsumer(p);
+  master->nConsumers = consumers.size();
 }
 
@@ -82,5 +97,5 @@
 }
 
-void TOISegmented::doPutData(int i, double value, uint_8 flag=0) {
+void TOISegmented::doPutData(int i, double value, uint_8 flag) {
   cout << "TOISegmented::doPutData unimplemented" << endl;
   throw PError("TOISegmented::doPutData unimplemented");
@@ -164,14 +179,11 @@
   segmentSize = m->segmentSize;
   firstNeeded = -1;
-  pthread_mutex_init(&mutex, NULL);
-  pthread_cond_init(&condv, NULL);
+  waiting = false;
 }
 
 TOISegmented::BufferView::~BufferView() {
-  pthread_mutex_destroy(&mutex);
-  pthread_cond_destroy(&condv);
-}
-
-double TOISegmented::BufferView::getData(int sn) { /* Single-thread */
+}
+
+double TOISegmented::BufferView::getData(int sn) { /* Single-thread, reader thread*/
   ensure(sn);
   int seg = (sn-sn0)/segmentSize;
@@ -179,5 +191,5 @@
 }
 
-uint_8 TOISegmented::BufferView::getFlag(int sn) { /* Single-thread */
+uint_8 TOISegmented::BufferView::getFlag(int sn) { /* Single-thread, reader thread */
   ensure(sn);
   int seg = (sn-sn0)/segmentSize;
@@ -185,38 +197,38 @@
 }
 
-void  TOISegmented::BufferView::ensure(int sn) { /* Single-thread */
+void  TOISegmented::BufferView::ensure(int sn) { /* Single-thread, reader thread */
   if (sn < sn0) {
-    throw RangeCheckError("requested sample before first");
-  }
-
-  if (sn >= sn0 + segmentSize*segments.size()) {
-    cout << "BufferView : read fault for " << sn << endl;
+    LOG(cout << "TOISegmented::BufferView::ensure requested sample before first" << endl);
+    LOG(cout << "sn " << sn << " sn0 " << sn0 << endl);
+    abort();
+  }
+
+  if (sn0 < 0 ||
+      sn >= sn0 + segmentSize*segments.size()) {
+    LOG(cout << "BufferView " << hex << this << dec << ": read fault for " << sn << endl)
     sync();
-    while (sn >= sn0 + segmentSize*segments.size()) {
+    while (sn0<0 || sn >= sn0 + segmentSize*segments.size()) {
       wait();
-      cout << "BufferView : waiting for " << sn << endl;
+      LOG(cout << "BufferView " << hex << this << dec << ": waiting for " << sn << endl)
       sync();
     }
-    cout << "BufferView : resuming for " << sn << endl;    
-  }
-}
-
-void TOISegmented::BufferView::sync() { /* Single-thread */
+    LOG(cout << "BufferView " << hex << this << dec << ": resuming for " << sn 
+	<< " now data for " << sn0 << " - " << sn0 + segmentSize*segments.size() 
+	<< " in " << segments.size() << " segments " << endl)
+  }
+}
+
+void TOISegmented::BufferView::sync() { /* Single-thread, reader thread */
   master->updateView(this); // update me !
 }
 
-void TOISegmented::BufferView::wait() { /* From reader thread */
-  pthread_mutex_lock(&mutex);
-  master->addToWaitList(this); // needing wake-up call
-  pthread_cond_wait(&condv, &mutex);
-  pthread_mutex_unlock(&mutex);
-}
-
-void TOISegmented::BufferView::signal() { /* From masterview, writer thread */
-  pthread_mutex_lock(&mutex);
-  pthread_cond_signal(&condv); // only one thread can be sleeping
-  master->removeFromWaitList(this);
-  pthread_mutex_unlock(&mutex);  
-}
+void TOISegmented::BufferView::wait() { /* reader thread */
+  pthread_mutex_lock(&(master->read_wait_mutex));
+  waiting = true;
+  pthread_cond_wait(&(master->read_wait_condv), &(master->read_wait_mutex)); 
+  waiting = false;
+  pthread_mutex_unlock(&(master->read_wait_mutex));
+}
+
 
 void TOISegmented::BufferView::wontNeedBefore(int sn) { /* reader thread */
@@ -236,8 +248,10 @@
   segmentSize    = bufsz;
   sn0            = -1;
+  nConsumers = 0;
   
   pthread_mutex_init(&views_mutex, NULL);
-  pthread_mutex_init(&write_mutex, NULL);
-  pthread_cond_init(&condv, NULL);
+  pthread_mutex_init(&read_wait_mutex, NULL);
+  pthread_cond_init(&write_wait_condv, NULL);
+  pthread_cond_init(&read_wait_condv, NULL);
   pthread_key_create(&buffer_key, BufferDestroy);
 
@@ -247,6 +261,7 @@
 TOISegmented::MasterView::~MasterView() {
   pthread_mutex_destroy(&views_mutex);
-  pthread_mutex_destroy(&write_mutex);
-  pthread_cond_destroy(&condv);
+  pthread_mutex_destroy(&read_wait_mutex);
+  pthread_cond_destroy(&write_wait_condv);
+  pthread_cond_destroy(&read_wait_condv);
   pthread_key_delete(buffer_key);
 
@@ -256,11 +271,14 @@
 }
 
-void TOISegmented::MasterView::putData(int sn, double data, uint_8 flags) {
-  if (sn0<0) sn0=sn;
+void TOISegmented::MasterView::putData(int sn, double data, uint_8 flags) { /* writer thread */
+  if (sn0<0) {
+    LOG(cout << "***MasterView::putData sn0<0" << endl)
+    sn0=sn;
+  }
   // can fit in current segment ?
   if (!(currentSegment != NULL &&
 	sn >= currentSegment->sn0 &&
 	sn < currentSegment->sn0 + currentSegment->bufferSize)) {
-    cout << "MasterView::putData, need extend for " << sn << endl;
+    LOG(cout << "MasterView::putData, need extend for " << sn << endl)
     nextSegment();
   }
@@ -268,26 +286,10 @@
 }
 
-double TOISegmented::MasterView::getData(int sn) {
-  return getView()->getData(sn);
-}
-
-uint_8 TOISegmented::MasterView::getFlag(int sn) {
+double TOISegmented::MasterView::getData(int sn) { /* reader thread */
+  return getView()->getData(sn); /* thread-specific */
+}
+
+uint_8 TOISegmented::MasterView::getFlag(int sn) { /* reader thread */
   return getView()->getFlag(sn);
-}
-
-void TOISegmented::MasterView::addToWaitList(BufferView* bv) { /* reader thread */
-  // A view needs to wait for new data.
-
-
-  pthread_mutex_lock(&views_mutex);
-  waitingBuffers.insert(bv);
-  pthread_mutex_unlock(&views_mutex);
-  checkDeadLock();
-}
-
-void TOISegmented::MasterView::removeFromWaitList(BufferView* bv) { /* reader thread */
-  pthread_mutex_lock(&views_mutex);
-  waitingBuffers.erase(bv);
-  pthread_mutex_unlock(&views_mutex);  
 }
 
@@ -295,6 +297,6 @@
   BufferView* bv = (BufferView*) pthread_getspecific(buffer_key);
   if (bv == NULL) {
-    cout << "creating new view" << endl;
     bv = createView();
+    LOG(cout << "creating new view " << hex << bv << dec << endl)
     pthread_setspecific(buffer_key, bv);
   }
@@ -302,19 +304,15 @@
 }
 
-void TOISegmented::MasterView::signalWaitingViews() { /* any thread */
-  pthread_mutex_lock(&views_mutex);
-  set<BufferView*> copyset = waitingBuffers;
-  pthread_mutex_unlock(&views_mutex);
-
-  for (set<BufferView*>::iterator i=copyset.begin();
-       i != copyset.end(); i++) {
-    (*i)->signal();
-  }
-}
-
-void TOISegmented::MasterView::signal() { /* reader thread */
-  pthread_mutex_lock(&write_mutex);
-  pthread_cond_signal(&condv); // only one thread can be sleeping
-  pthread_mutex_unlock(&write_mutex);  
+void TOISegmented::MasterView::signalWaitingViews() { /* any thread */ /* views locked */
+  pthread_mutex_lock(&read_wait_mutex);
+  pthread_cond_broadcast(&read_wait_condv);
+  pthread_mutex_unlock(&read_wait_mutex);
+}
+
+void TOISegmented::MasterView::signalWrite() { /* reader thread */ /* views locked */
+  if (waitingOnWrite) {
+    LOG(cout << "MasterView : signal for wait on write" << endl)
+    pthread_cond_signal(&write_wait_condv); // only one thread can be sleeping
+  }
 }
 
@@ -326,13 +324,12 @@
   // The current segment, if any, is now committed. A new
   // blank buffer is allocated, if any.
-
-  cout << "MasterView::nextSegment " 
-       << segments.size()+1 << "/" << maxSegments << endl;
+  pthread_mutex_lock(&views_mutex);
+
+  LOG(cout << "MasterView::nextSegment " 
+      << segments.size()+1 << "/" << maxSegments << endl)
 
   if (currentSegment != NULL) {
     currentSegment->status = BufferSegment::COMMITTED;
-    pthread_mutex_lock(&views_mutex);
     segments.push_back(currentSegment);
-    pthread_mutex_unlock(&views_mutex);
   }
 
@@ -344,19 +341,20 @@
   currentSegment = new BufferSegment(segmentSize);
   signalWaitingViews(); // they can ask to be updated !!
-}
-
-void TOISegmented::MasterView::waitForCleaning() { /* writer thread */
-  cout << "MasterView : write wait for clean for " << sn0 << endl;
-  pthread_mutex_lock(&write_mutex);
+  pthread_mutex_unlock(&views_mutex);
+}
+
+void TOISegmented::MasterView::waitForCleaning() { /* writer thread */ /* views locked */
+  LOG(cout << "MasterView : write wait for clean for " << sn0 << endl)
   waitingOnWrite = true;
   checkDeadLock();
-  pthread_cond_wait(&condv, &write_mutex);
-  pthread_mutex_unlock(&write_mutex);
-  cout << "MasterView : wait done" << endl;
+  pthread_cond_wait(&write_wait_condv, &views_mutex);
+  LOG(cout << "MasterView : wait done" << endl)
 }
 
 TOISegmented::BufferView* TOISegmented::MasterView::createView() { /* reader thread */
   BufferView* bv =  new BufferView(this);
+  pthread_mutex_lock(&views_mutex);
   allViews.insert(bv);
+  pthread_mutex_unlock(&views_mutex);
   updateView(bv);
   return bv;
@@ -379,25 +377,33 @@
   // nous.
   
-  int firstNeeded = MAXINT;
-  for (set<BufferView*>::iterator i = allViews.begin();
-       i != allViews.end(); i++) {
-    if ((*i)->firstNeeded < firstNeeded) firstNeeded = (*i)->firstNeeded;
-  }
-
-  cout << "firstNeeded = " << firstNeeded << endl;
-
-  vector<BufferSegment*>::iterator j = segments.begin();
-  bool clean = false;
-  for (vector<BufferSegment*>::iterator i = segments.begin();
-       i != segments.end(); i++) { 
-    if (((*i)->sn0+(*i)->bufferSize <= firstNeeded) && ((*i)->getRefCount() == 0)) {
-      clean = true;
-      j = i;
-    } else {}
+  // A condition que tous les consumers se soient fait connaitre...
+
+  if (nConsumers == allViews.size()) {
+    int firstNeeded = MAXINT;
+    for (set<BufferView*>::iterator i = allViews.begin();
+	 i != allViews.end(); i++) {
+      if ((*i)->firstNeeded < firstNeeded) firstNeeded = (*i)->firstNeeded;
+    }
+    
+    LOG(cout << "MasterView : firstNeeded = " << firstNeeded << endl);
+      
+    vector<BufferSegment*>::iterator j = segments.begin();
+    bool clean = false;
+    for (vector<BufferSegment*>::iterator i = segments.begin();
+	 i != segments.end(); i++) { 
+      if (((*i)->sn0+(*i)->bufferSize <= firstNeeded) && ((*i)->getRefCount() == 0)) {
+	clean = true;
+	j = i;
+      } 
+    }
     if (clean) {
       segments.erase(segments.begin(),j);
       sn0 = (*segments.begin())->sn0;
-    }
-  } 
+      LOG(cout << "MasterView : purged until " << sn0 << endl);
+    }
+  } else {
+    LOG(cout << "MasterView : not yet all consumer thread known "<< allViews.size()
+	<< "/" << nConsumers  << endl);
+  }
 
   for (vector<BufferSegment*>::iterator i = segments.begin();
@@ -416,18 +422,19 @@
   }
 
-  if (bv->sn0 > oldBegin && waitingOnWrite) {
-    signal();
-  }
-
-  cout << "sync " << sn0 << " - " << newEnd << endl;
-
+  if (bv->sn0 > oldBegin) { // nettoyage de fait, reveiller le writer thread si besoin
+    signalWrite();
+  }
+
+  LOG(cout << "sync for " << hex << bv << dec << " : "
+      << oldBegin << " - " << oldEnd << "  -->  "
+      << bv->sn0 << " - " << newEnd << endl);
+  
+  if (newEnd > oldEnd) { // Nouveautes, reveiller les reader threads si besoin
+    signalWaitingViews();
+  }
   pthread_mutex_unlock(&views_mutex);
-
-  if (newEnd > oldEnd) {
-    signalWaitingViews();
-  }
-}
-
-void TOISegmented::MasterView::checkDeadLock() {
+}
+
+void TOISegmented::MasterView::checkDeadLock() { /* views locked */
    // There is a possible deadlock if no view can free old segments
   // and we are waiting for write.
@@ -437,12 +444,15 @@
   // while we are asleep
 
-  if (!waitingOnWrite) return; // no problem, there is an active writer
+  pthread_mutex_lock(&read_wait_mutex);
+  if (!waitingOnWrite) {
+    pthread_mutex_unlock(&read_wait_mutex);
+    return; // no problem, there is an active writer
+  }
 
   // Is any sleeping view needing our first segment ?
 
-  pthread_mutex_lock(&views_mutex);
-  for (set<BufferView*>::iterator i=waitingBuffers.begin();
-       i != waitingBuffers.end(); i++) {
-    if ((*i)->firstNeeded < sn0+segmentSize) {
+  for (set<BufferView*>::iterator i=allViews.begin();
+       i != allViews.end(); i++) {
+    if ((*i)->waiting && (*i)->firstNeeded < sn0+segmentSize) {
       cout << "**** DEADLOCK detected ****" << endl;
       cout << "We are waiting on write (buffer is full)"<< endl;
@@ -452,5 +462,5 @@
     }
   }
-  pthread_mutex_unlock(&views_mutex);
+  pthread_mutex_unlock(&read_wait_mutex);
 }
 
Index: /trunk/ArchTOIPipe/Kernel/toisegment.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toisegment.h	(revision 1691)
+++ /trunk/ArchTOIPipe/Kernel/toisegment.h	(revision 1692)
@@ -27,4 +27,5 @@
   virtual void          wontNeedBefore(int i);
   virtual void          putDone();
+  virtual void          addConsumer(TOIProcessor*);
 
   // Methodes ignorees car on reimplemente les methodes de base
@@ -109,11 +110,9 @@
 
   protected:
-    void addToWaitList(BufferView* bv);
-    void removeFromWaitList(BufferView* bv);
-
 
     friend class BufferView;
+    friend class TOISegmented;
     void signalWaitingViews(); // views are waiting on read
-    void signal(); // we are waiting on write
+    void signalWrite();        // we are waiting on write
     void nextSegment();
     void waitForCleaning();
@@ -127,14 +126,16 @@
     int sn0;                         // First sn in first segment
     vector<BufferSegment*> segments; // Committed segments
+    int nConsumers;
     
     pthread_mutex_t  views_mutex; // lock for master buffer list access
-    pthread_mutex_t  write_mutex; // for write waiting
-    pthread_cond_t   condv; // waiting for cleaning (on writer thread)
+    pthread_cond_t   write_wait_condv; // waiting for cleaning (on writer thread)
     pthread_key_t    buffer_key; // thread-specific buffer view
     static void BufferDestroy(void *);
 
+    pthread_mutex_t  read_wait_mutex;
+    pthread_cond_t   read_wait_condv;
+
     bool   waitingOnWrite; // wait on writer thread
 
-    set<BufferView*>  waitingBuffers;
     set<BufferView*>  allViews;
 
@@ -158,5 +159,6 @@
     void sync();  // recupere les nouveaux segments, resync avec master
     void ensure(int sn);
-    void signal();
+
+    bool waiting;
 
     friend class MasterView;
@@ -166,6 +168,4 @@
     int segmentSize;
     int firstNeeded;
-    pthread_mutex_t  mutex; // lock pour attente de segments
-    pthread_cond_t   condv; // attente de segments (en lecture)
   };  
 
Index: /trunk/ArchTOIPipe/ProcWSophya/Makefile.in
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/Makefile.in	(revision 1691)
+++ /trunk/ArchTOIPipe/ProcWSophya/Makefile.in	(revision 1692)
@@ -99,10 +99,10 @@
 
 %.d: $(srcdir)/%.cc
-	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I. $< \
+	$(SHELL) -ec '@gcc@ -MM $(CPPFLAGS) -I. $< \
 		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
 		[ -s $@ ] || rm -f $@'
 
 %.d: $(srcdir)/%.c
-	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I. $< \
+	$(SHELL) -ec '@gcc@ -MM $(CPPFLAGS) -I. $< \
 		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
 		[ -s $@ ] || rm -f $@'
Index: /trunk/ArchTOIPipe/Processors/Makefile.in
===================================================================
--- /trunk/ArchTOIPipe/Processors/Makefile.in	(revision 1691)
+++ /trunk/ArchTOIPipe/Processors/Makefile.in	(revision 1692)
@@ -99,10 +99,10 @@
 
 %.d: $(srcdir)/%.cc
-	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I. $< \
+	$(SHELL) -ec '@gcc@ -MM $(CPPFLAGS) -I. $< \
 		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
 		[ -s $@ ] || rm -f $@'
 
 %.d: $(srcdir)/%.c
-	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I. $< \
+	$(SHELL) -ec '@gcc@ -MM $(CPPFLAGS) -I. $< \
 		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
 		[ -s $@ ] || rm -f $@'
Index: /trunk/ArchTOIPipe/TestPipes/Makefile.in
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/Makefile.in	(revision 1691)
+++ /trunk/ArchTOIPipe/TestPipes/Makefile.in	(revision 1692)
@@ -96,10 +96,10 @@
 
 %.d: $(srcdir)/%.cc
-	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I. $< \
+	$(SHELL) -ec '@gcc@ -MM $(CPPFLAGS) -I. $< \
 		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
 		[ -s $@ ] || rm -f $@'
 
 %.d: $(srcdir)/%.c
-	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I. $< \
+	$(SHELL) -ec '@gcc@ -MM $(CPPFLAGS) -I. $< \
 		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
 		[ -s $@ ] || rm -f $@'
Index: /trunk/ArchTOIPipe/configure
===================================================================
--- /trunk/ArchTOIPipe/configure	(revision 1691)
+++ /trunk/ArchTOIPipe/configure	(revision 1692)
@@ -911,6 +911,13 @@
 
 
+if test $GCC = "yes"; then
+  gcc=$CC
+else
+  gcc=gcc
+fi
+
+
 echo $ac_n "checking size of short""... $ac_c" 1>&6
-echo "configure:915: checking size of short" >&5
+echo "configure:922: checking size of short" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_short'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -920,5 +927,5 @@
 else
   cat > conftest.$ac_ext <<EOF
-#line 923 "configure"
+#line 930 "configure"
 #include "confdefs.h"
 #include <stdio.h>
@@ -931,5 +938,5 @@
 }
 EOF
-if { (eval echo configure:934: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:941: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_short=`cat conftestval`
@@ -951,5 +958,5 @@
 
 echo $ac_n "checking size of int""... $ac_c" 1>&6
-echo "configure:954: checking size of int" >&5
+echo "configure:961: checking size of int" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -959,5 +966,5 @@
 else
   cat > conftest.$ac_ext <<EOF
-#line 962 "configure"
+#line 969 "configure"
 #include "confdefs.h"
 #include <stdio.h>
@@ -970,5 +977,5 @@
 }
 EOF
-if { (eval echo configure:973: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:980: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_int=`cat conftestval`
@@ -990,5 +997,5 @@
 
 echo $ac_n "checking size of long""... $ac_c" 1>&6
-echo "configure:993: checking size of long" >&5
+echo "configure:1000: checking size of long" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_long'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -998,5 +1005,5 @@
 else
   cat > conftest.$ac_ext <<EOF
-#line 1001 "configure"
+#line 1008 "configure"
 #include "confdefs.h"
 #include <stdio.h>
@@ -1009,5 +1016,5 @@
 }
 EOF
-if { (eval echo configure:1012: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1019: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_long=`cat conftestval`
@@ -1029,5 +1036,5 @@
 
 echo $ac_n "checking size of long long""... $ac_c" 1>&6
-echo "configure:1032: checking size of long long" >&5
+echo "configure:1039: checking size of long long" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_long_long'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1037,5 +1044,5 @@
 else
   cat > conftest.$ac_ext <<EOF
-#line 1040 "configure"
+#line 1047 "configure"
 #include "confdefs.h"
 #include <stdio.h>
@@ -1048,5 +1055,5 @@
 }
 EOF
-if { (eval echo configure:1051: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1058: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_long_long=`cat conftestval`
@@ -1068,5 +1075,5 @@
 
 echo $ac_n "checking size of float""... $ac_c" 1>&6
-echo "configure:1071: checking size of float" >&5
+echo "configure:1078: checking size of float" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_float'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1076,5 +1083,5 @@
 else
   cat > conftest.$ac_ext <<EOF
-#line 1079 "configure"
+#line 1086 "configure"
 #include "confdefs.h"
 #include <stdio.h>
@@ -1087,5 +1094,5 @@
 }
 EOF
-if { (eval echo configure:1090: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1097: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_float=`cat conftestval`
@@ -1107,5 +1114,5 @@
 
 echo $ac_n "checking size of double""... $ac_c" 1>&6
-echo "configure:1110: checking size of double" >&5
+echo "configure:1117: checking size of double" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_double'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1115,5 +1122,5 @@
 else
   cat > conftest.$ac_ext <<EOF
-#line 1118 "configure"
+#line 1125 "configure"
 #include "confdefs.h"
 #include <stdio.h>
@@ -1126,5 +1133,5 @@
 }
 EOF
-if { (eval echo configure:1129: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1136: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_double=`cat conftestval`
@@ -1146,5 +1153,5 @@
 
 echo $ac_n "checking size of long double""... $ac_c" 1>&6
-echo "configure:1149: checking size of long double" >&5
+echo "configure:1156: checking size of long double" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_long_double'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1154,5 +1161,5 @@
 else
   cat > conftest.$ac_ext <<EOF
-#line 1157 "configure"
+#line 1164 "configure"
 #include "confdefs.h"
 #include <stdio.h>
@@ -1165,5 +1172,5 @@
 }
 EOF
-if { (eval echo configure:1168: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1175: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_long_double=`cat conftestval`
@@ -1187,5 +1194,5 @@
 
 echo $ac_n "checking "for cfitsio lib"""... $ac_c" 1>&6
-echo "configure:1190: checking "for cfitsio lib"" >&5
+echo "configure:1197: checking "for cfitsio lib"" >&5
 MACHDIR=`uname`-$CXX
 if test -f $ARCHBASEREP/$MACHDIR/Libs/libcfitsio.a; then
@@ -1212,5 +1219,5 @@
 
 echo $ac_n "checking "for cfitsio includes"""... $ac_c" 1>&6
-echo "configure:1215: checking "for cfitsio includes"" >&5
+echo "configure:1222: checking "for cfitsio includes"" >&5
 if test -f $CFITSIODIR/fitsio.h; then
   cfitsincdir='-I$(CFITSIODIR)'
@@ -1224,5 +1231,5 @@
 
 echo $ac_n "checking for sin in -lm""... $ac_c" 1>&6
-echo "configure:1227: checking for sin in -lm" >&5
+echo "configure:1234: checking for sin in -lm" >&5
 ac_lib_var=`echo m'_'sin | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
@@ -1232,5 +1239,5 @@
 LIBS="-lm  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1235 "configure"
+#line 1242 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
@@ -1243,5 +1250,5 @@
 ; return 0; }
 EOF
-if { (eval echo configure:1246: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1253: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
@@ -1272,5 +1279,5 @@
 
 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:1275: checking how to run the C preprocessor" >&5
+echo "configure:1282: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
@@ -1287,5 +1294,5 @@
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 1290 "configure"
+#line 1297 "configure"
 #include "confdefs.h"
 #include <assert.h>
@@ -1293,5 +1300,5 @@
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1296: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1303: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
@@ -1304,5 +1311,5 @@
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 1307 "configure"
+#line 1314 "configure"
 #include "confdefs.h"
 #include <assert.h>
@@ -1310,5 +1317,5 @@
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1313: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1320: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
@@ -1321,5 +1328,5 @@
   CPP="${CC-cc} -nologo -E"
   cat > conftest.$ac_ext <<EOF
-#line 1324 "configure"
+#line 1331 "configure"
 #include "confdefs.h"
 #include <assert.h>
@@ -1327,5 +1334,5 @@
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1330: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1337: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
@@ -1352,10 +1359,10 @@
 
 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:1355: checking for ANSI C header files" >&5
+echo "configure:1362: checking for ANSI C header files" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1360 "configure"
+#line 1367 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
@@ -1365,5 +1372,5 @@
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1368: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1375: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
@@ -1382,5 +1389,5 @@
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1385 "configure"
+#line 1392 "configure"
 #include "confdefs.h"
 #include <string.h>
@@ -1400,5 +1407,5 @@
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1403 "configure"
+#line 1410 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
@@ -1421,5 +1428,5 @@
 else
   cat > conftest.$ac_ext <<EOF
-#line 1424 "configure"
+#line 1431 "configure"
 #include "confdefs.h"
 #include <ctype.h>
@@ -1432,5 +1439,5 @@
 
 EOF
-if { (eval echo configure:1435: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1442: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   :
@@ -1459,15 +1466,15 @@
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1462: checking for $ac_hdr" >&5
+echo "configure:1469: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1467 "configure"
+#line 1474 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1472: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1479: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
@@ -1636,4 +1643,5 @@
 s%@CC@%$CC%g
 s%@CXX@%$CXX%g
+s%@gcc@%$gcc%g
 s%@cfitslibdir@%$cfitslibdir%g
 s%@cfitsincdir@%$cfitsincdir%g
Index: /trunk/ArchTOIPipe/configure.in
===================================================================
--- /trunk/ArchTOIPipe/configure.in	(revision 1691)
+++ /trunk/ArchTOIPipe/configure.in	(revision 1692)
@@ -18,4 +18,11 @@
 AC_PROG_CC
 AC_PROG_CXX
+
+if test $GCC = "yes"; then
+  gcc=$CC
+else
+  gcc=gcc
+fi
+AC_SUBST(gcc)
 
 AC_CHECK_SIZEOF(short)
Index: /trunk/ArchTOIPipe/fan_copy
===================================================================
--- /trunk/ArchTOIPipe/fan_copy	(revision 1691)
+++ /trunk/ArchTOIPipe/fan_copy	(revision 1692)
@@ -8,3 +8,4 @@
    cp -p $f $d/$f
   end
+  cp -p Makefile.in_$d $d/Makefile.in
 end
