Index: /BAORadio/AmasNancay/trunk/analyse.cc
===================================================================
--- /BAORadio/AmasNancay/trunk/analyse.cc	(revision 594)
+++ /BAORadio/AmasNancay/trunk/analyse.cc	(revision 595)
@@ -52,4 +52,31 @@
 //----------------------------------------------------------
 //Utility fonctions
+class median_of_empty_list_exception:public std::exception{
+    virtual const char* what() const throw() {
+    return "Attempt to take the median of an empty list of numbers.  "
+      "The median of an empty list is undefined.";
+  }
+};
+template<class RandAccessIter>
+double median(RandAccessIter begin, RandAccessIter end) 
+  throw(median_of_empty_list_exception){
+  if(begin == end){ throw median_of_empty_list_exception(); }
+  std::size_t size = end - begin;
+  std::size_t middleIdx = size/2;
+  RandAccessIter target = begin + middleIdx;
+  std::nth_element(begin, target, end);
+    
+  if(size % 2 != 0){ //Odd number of elements
+    return *target;
+  }else{            //Even number of elements
+    double a = *target;
+    RandAccessIter targetNeighbor= target-1;
+    std::nth_element(begin, targetNeighbor, end);
+    return (a+*targetNeighbor)/2.0;
+  }
+}
+
+//-------------
+
 // Function for deleting pointers in map.
 template<class A, class B>
@@ -789,5 +816,5 @@
   //Process to get sucessively
   //Raw Spectra, 
-  //The pocesses are separated to allow intermediate save of results
+  //The processes are separated to allow intermediate save of results
 
   map< pair<string, sa_size_t>, TMatrix<r_4> > spectreCollect;
@@ -884,5 +911,5 @@
   if(nCycles>0) diffMeanOnOff/=nCycles;
 
-  //exctract channels and do the mean
+  //extract channels and do the mean
   TVector<r_4> meanOfChan(NUMBER_OF_FREQ); //implicitly init to 0
   for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh) {
@@ -935,5 +962,5 @@
 	  MeanSigma(reducedRow,mean,sigma);
 	  if (debuglev_>9) {
-	    cout << "mean/signa " << mean << "/" << sigma << endl;
+	    cout << "mean/sigma " << mean << "/" << sigma << endl;
 	  }
 	  reducedMeanDiffOnOff(iCh,iSlice) = mean;
@@ -1712,8 +1739,9 @@
 	for (int i=0;i<2;i++) {
 	  if (!upIntState[i].empty()) {
-	    std::nth_element(upIntState[i].begin(),
-			     upIntState[i].begin()+upIntState[i].size()/2,
-			     upIntState[i].end());
-	    meanUpper += *(upIntState[i].begin()+upIntState[i].size()/2);
+// 	    std::nth_element(upIntState[i].begin(),
+// 			     upIntState[i].begin()+upIntState[i].size()/2,
+// 			     upIntState[i].end());
+// 	    meanUpper += *(upIntState[i].begin()+upIntState[i].size()/2);
+	    meanUpper += median(upIntState[i].begin(),upIntState[i].end());
 	    nval++;
 	  } 
Index: /BAORadio/AmasNancay/trunk/anarawonoffmaker.sh
===================================================================
--- /BAORadio/AmasNancay/trunk/anarawonoffmaker.sh	(revision 594)
+++ /BAORadio/AmasNancay/trunk/anarawonoffmaker.sh	(revision 595)
@@ -253,9 +253,9 @@
   $RM -f ${tmppublicpath}/getscafiles.finished
   ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
-  while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
-      $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
-      date +%T
-      sleep 30
-  done
+#  while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
+#      $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
+#      date +%T
+#      sleep 30
+#  done
   $RM ${tmppublicpath}/getscafiles.finished
   $ECHO "DEBUG (${scriptName}): END"
Index: /BAORadio/AmasNancay/trunk/etude_gain.pic
===================================================================
--- /BAORadio/AmasNancay/trunk/etude_gain.pic	(revision 594)
+++ /BAORadio/AmasNancay/trunk/etude_gain.pic	(revision 595)
@@ -1,6 +1,8 @@
-set toppath "/sps/baoradio/AmasNancay/JEC"
+set user "AST"
+set toppath "/sps/baoradio/AmasNancay/${user}"
 set source "Abell85"
 set srclower "abell85"
-set date   "20110507"
+set date   "20110812"
+set saveplot "1"
 
 ####################################################
@@ -18,4 +20,8 @@
 settitle "Gain $source ${date} Ch 0 (blue) Ch 1 (red)"
 setaxelabels "Freq. (MHz)" "I (a.u)"
+if ( $saveplot == "1" ) then
+  echo "saving plot"
+  w2eps ${toppath}/${source}/eps/gain/gain_${date}_${srclower}.eps
+endif
 
 ####################################################
@@ -24,10 +30,20 @@
 newwin 1 1
 graphicatt "xylimits=0,25,0,0.006"
+del gainmoni gainmoni0 gainmoni1
 
 openppf ${toppath}/${source}/${date}${srclower}/gain_monitor_${date}_${srclower}.ppf
 #attention les "monitor" ont ete utilise a une epoque ou il n'y avait pas de
 #reordering...
-plot2d monitor n val n>0 "black cpts nsta notit"
+ls
+#plot2d monitor n val n>0 "black cpts nsta notit"
 plot2d gainmoni n val n>0 "black cpts nsta notit"
 plot2d gainmoni0 n val n>0 "same blue cpts nsta notit"
 plot2d gainmoni1 n val n>0 "same red cpts nsta notit"
+settitle "Gain monitor $source ${date} Ch 0 (blue) Ch 1 (red)"
+if ( $saveplot == "1" ) then
+#  w2eps ${toppath}/${source}/eps/gain/gain_monitor_${date}_${srclower}.eps
+endif
+
+del g0 g1 gainmoni gainmoni0 gainmoni1
+del gain_${date}_${srclower}
+ls
Index: /BAORadio/AmasNancay/trunk/makefile
===================================================================
--- /BAORadio/AmasNancay/trunk/makefile	(revision 594)
+++ /BAORadio/AmasNancay/trunk/makefile	(revision 595)
@@ -7,10 +7,10 @@
 PKGOLIST =
 
-EXELIST = $(EXE)analyse $(EXE)mergeAnaFiles
+EXELIST = $(EXE)analyse $(EXE)mergeAnaFiles $(EXE)anaTools
 
-EXEOLIST = $(EXE)analyse.o $(EXE)mergeAnaFiles.o
+EXEOLIST = $(EXE)analyse.o $(EXE)mergeAnaFiles.o $(EXE)anaTools.o
 
 
-all : analyse mergeAnaFiles
+all : analyse mergeAnaFiles anaTools
 
 clean :
@@ -37,3 +37,12 @@
 $(OBJ)mergeAnaFiles.o : mergeAnaFiles.cc
 	$(CXXCOMPILE) -c  -o $(OBJ)mergeAnaFiles.o mergeAnaFiles.cc
- 
+
+anaTools : $(EXE)anaTools
+	echo '---anaTools made'
+
+$(EXE)anaTools : $(OBJ)anaTools.o
+	$(CXXLINK) -o $(EXE)anaTools $(OBJ)anaTools.o  $(SOPHYAALLSLBLIST)
+
+$(OBJ)anaTools.o : anaTools.cc
+	$(CXXCOMPILE) -c  -o $(OBJ)anaTools.o anaTools.cc
+
Index: /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc
===================================================================
--- /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc	(revision 594)
+++ /BAORadio/AmasNancay/trunk/mergeAnaFiles.cc	(revision 595)
@@ -90,23 +90,23 @@
       "The median of an empty list is undefined.";
   }
-  };
-  template<class RandAccessIter>
-    double median(RandAccessIter begin, RandAccessIter end) 
-    throw(median_of_empty_list_exception){
-    if(begin == end){ throw median_of_empty_list_exception(); }
-    std::size_t size = end - begin;
-    std::size_t middleIdx = size/2;
-    RandAccessIter target = begin + middleIdx;
-    std::nth_element(begin, target, end);
-    
-    if(size % 2 != 0){ //Odd number of elements
-      return *target;
-    }else{            //Even number of elements
-      double a = *target;
-      RandAccessIter targetNeighbor= target-1;
-      std::nth_element(begin, targetNeighbor, end);
-      return (a+*targetNeighbor)/2.0;
-    }
-  }
+};
+template<class RandAccessIter>
+double median(RandAccessIter begin, RandAccessIter end) 
+  throw(median_of_empty_list_exception){
+  if(begin == end){ throw median_of_empty_list_exception(); }
+  std::size_t size = end - begin;
+  std::size_t middleIdx = size/2;
+  RandAccessIter target = begin + middleIdx;
+  std::nth_element(begin, target, end);
+    
+  if(size % 2 != 0){ //Odd number of elements
+    return *target;
+  }else{            //Even number of elements
+    double a = *target;
+    RandAccessIter targetNeighbor= target-1;
+    std::nth_element(begin, targetNeighbor, end);
+    return (a+*targetNeighbor)/2.0;
+  }
+}
 
 //-------------
Index: /BAORadio/AmasNancay/trunk/proc_specmfib.sh
===================================================================
--- /BAORadio/AmasNancay/trunk/proc_specmfib.sh	(revision 594)
+++ /BAORadio/AmasNancay/trunk/proc_specmfib.sh	(revision 595)
@@ -347,5 +347,5 @@
       $ECHO "process signal files for CALIBRATION ON phases"
       ingain="-gain gain_${dateSelected}_${srclower}.fits"
-      freqfilter=""
+      freqfilter="-freqfilter -"
       nwinmean="1"
       tspwin="1024"
@@ -361,5 +361,5 @@
       $ECHO "process signal files for CALIBRATION OFF phases"
       ingain="-gain gain_${dateSelected}_${srclower}.fits"
-      freqfilter=""
+      freqfilter="-freqfilter -"
       nwinmean="1"
       tspwin="1024"
Index: /BAORadio/AmasNancay/trunk/statuscalib.sh
===================================================================
--- /BAORadio/AmasNancay/trunk/statuscalib.sh	(revision 594)
+++ /BAORadio/AmasNancay/trunk/statuscalib.sh	(revision 595)
@@ -86,9 +86,9 @@
 	   done
 	else
-	    $ECHO "${sourceDate} : No Calibration done for Off Diectory"
+	    $ECHO "${sourceDate} : No Calibration done for Off Directory"
 	fi
 #end of Off exist
     else
-	$ECHO "${sourceDate} : No Off Diectory"
+	$ECHO "${sourceDate} : No Off Directory"
     fi
 #
@@ -120,9 +120,9 @@
 	   done
 	else
-	    $ECHO "${sourceDate} : No Calibration done for On Diectory"
+	    $ECHO "${sourceDate} : No Calibration done for On Directory"
 	fi
 #end of On exist
     else
-	$ECHO "${sourceDate} : No On Diectory"
+	$ECHO "${sourceDate} : No On Directory"
     fi
 #end of loop on dates
Index: /BAORadio/AmasNancay/trunk/submit2ge-anarawonoffmaker.sh
===================================================================
--- /BAORadio/AmasNancay/trunk/submit2ge-anarawonoffmaker.sh	(revision 594)
+++ /BAORadio/AmasNancay/trunk/submit2ge-anarawonoffmaker.sh	(revision 595)
@@ -20,5 +20,5 @@
       -h)
 	echo >&2 \
-	    "usage: $0 -src souce -date YYYYMMDD [-freq freq in MHz (default ${freqBAOCalib})] [-sim to trig simulation mode]"
+	    "usage: $0 -src source -date YYYYMMDD [-freq freq in MHz (default ${freqBAOCalib})] [-sim to trig simulation mode]"
 	exit 1;;
 	*)  break;;	# terminate while loop
Index: /BAORadio/AmasNancay/trunk/submit2ge-procspecmfib.sh
===================================================================
--- /BAORadio/AmasNancay/trunk/submit2ge-procspecmfib.sh	(revision 594)
+++ /BAORadio/AmasNancay/trunk/submit2ge-procspecmfib.sh	(revision 595)
@@ -52,5 +52,5 @@
 	-h)
 	echo >&2 \
-	    "usage: $0 -src souce -date YYYYMMDD -type type [-fcycle firstCycle] [-lcycle lastCycle] [-sim to trig simulation mode]"
+	    "usage: $0 -src source -date YYYYMMDD -type type [-fcycle firstCycle] [-lcycle lastCycle] [-sim to trig simulation mode]"
 	exit 1;;
 	*)  break;;	# terminate while loop
