Index: /issm/trunk-jpl/src/c/shared/Bamg/HeapSort.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/Bamg/HeapSort.h	(revision 15071)
+++ /issm/trunk-jpl/src/c/shared/Bamg/HeapSort.h	(revision 15072)
@@ -4,25 +4,38 @@
 /*Sort a list of size n*/
 template<class T> inline void  HeapSort(T *c,long n){ /*{{{*/
-	int l,j,r,i;
+
+	/*Intermediaries*/
+	int i,j,l,r;
 	T   crit;
-	c--;                    //the array must starts at 1 and not 0 
-	if(n<=1) return;        //return if size <=1
-	l=n/2+1;                //initialize l and r
+
+	/*return if size <=1*/
+	if(n<=1) return;
+
+	/*Initialize variables*/
+	l=n/2+1; 
 	r=n;
+	c--; //the array must starts at 1 and not 0 
+
+	/*Sorting algorithm*/
 	for(;;){
 		if(l<=1){
-			crit  =c[r];
-			c[r--]=c[1];
-			if (r==1){c[1]=crit; return;}
+			crit   = c[r];
+			c[r--] = c[1];
+			if(r==1){
+				c[1]=crit; 
+				return;
+			}
 		}
-		else  crit = c[--l]; 
+		else{
+			crit = c[--l]; 
+		}
 		j=l;
 		for(;;){
-			i=j;
-			j=2*j;
-			if  (j>r) {c[i]=crit;break;}
+			i = j;
+			j = 2*j;
+			if  (j>r){c[i]=crit;break;}
 			if ((j<r) && (c[j] < c[j+1])) j++;//c[j+1]> c[j] -> take j+1 instead of j (larger value)
-			if (crit < c[j]) c[i]=c[j];       //c[j]  > crit -> stock this large value in i(<j)
-			else{c[i]=crit;break;}            //c[j]  < crit -> stock crit in i (<j)
+			if (crit < c[j]) c[i]=c[j];       //c[j]  > crit -> put this large value in i(<j)
+			else{c[i]=crit;break;}            //c[j]  < crit -> put crit in i (<j)
 		}
 	}
@@ -32,14 +45,22 @@
 /*Sort a list of size n and returns ordering*/
 template<class T> inline void  HeapSort(int** porder,T* c,int n){ /*{{{*/
-	int  l,j,r,i;
+
+	/*Intermediaries*/
+	int  i,j,l,r;
 	T    crit;
 	int  pos;
-	int* order = new int[n];
+	int* order = NULL;
+
+	/*return if size <=1*/
+	if(n<=1) return;
+
+	/*Initialize variables*/
+	l=n/2+1; 
+	r=n;
+	c--; //the array must starts at 1 and not 0 
+	order = new int[n];
 	for(i=0;i<n;i++) order[i]=i+1;
-	c--;                    //the array must starts at 1 and not 0 
-	order--;
-	if(n<=1) return;        //return if size <=1
-	l=n/2+1;                //initialize l and r
-	r=n;
+
+	/*Sorting algorithm*/
 	for(;;){
 		if(l<=1){
