Index: /issm/trunk-jpl/src/c/shared/Bamg/HeapSort.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/Bamg/HeapSort.h	(revision 22555)
+++ /issm/trunk-jpl/src/c/shared/Bamg/HeapSort.h	(revision 22556)
@@ -60,5 +60,6 @@
 	c--; //the array must starts at 1 and not 0 
 	order = new int[n];
-	for(i=0;i<n;i++) order[i]=i+1;
+	for(i=0;i<n;i++) order[i]=i;
+	order--;
 
 	/*Sorting algorithm*/
@@ -81,6 +82,12 @@
 			if  (j>r) {c[i]=crit;order[i]=pos;break;}
 			if ((j<r) && (c[j] < c[j+1]))j++;
-			if (crit < c[j]) {c[i]=c[j];order[i]=order[j];}
-			else{c[i]=crit;order[i]=pos;break;}
+			if (crit < c[j]){
+				c[i]=c[j];
+				order[i]=order[j];
+			}
+			else{
+				c[i]=crit;order[i]=pos;
+				break;
+			}
 		}
 	}
