Index: /issm/trunk/src/c/objects/Bamg/QuadTree.cpp
===================================================================
--- /issm/trunk/src/c/objects/Bamg/QuadTree.cpp	(revision 5265)
+++ /issm/trunk/src/c/objects/Bamg/QuadTree.cpp	(revision 5266)
@@ -241,5 +241,5 @@
 		Icoor1                ii[MaxDeep];
 		Icoor1                jj[MaxDeep];
-		register int          level  = 0;
+		register int          level;
 		register long         n0;
 		register QuadTreeBox *b;
@@ -279,5 +279,5 @@
 			i0 += I_IJ(k,hb2); // i orign of QuadTreeBox (macro)
 			j0 += J_IJ(k,hb2); // j orign of QuadTreeBox 
-			hb = hb2; 
+			hb = hb2;          // size of the box (in Int)
 		}
 
@@ -307,5 +307,5 @@
 		//initialize pb pi ii and jj
 		pb[0]=b;                  //pointer toward the box b
-		pi[0]=b->nbitems>0? (int)b->nbitems:4;//number of vertices in the box
+		pi[0]=b->nbitems>0? (int)b->nbitems:4;//number of boxes in b
 		ii[0]=i0;                 // i coordinate of the box
 		jj[0]=j0;                 // j coordinate of the box
@@ -314,37 +314,39 @@
 		h=hb;
 
-		/*loop, until level=0*/
+		/*loop, until level=0 (main quadtree box)*/
+		level=0;
 		do {
-			//get current box
+
+			/*get current box*/
 			b= pb[level];
 
-			//Loop over the vertices in current box (if not empty!)
+			/*Loop over the items in current box (if not empty!)*/
 			while (pi[level]--){
 
-				//k = number of vertices in the box if there are vertices
-				//k = 4 if the current box is pointing toward 4 other boxes
-				register int k=pi[level];
-
-				//if the current subbox is holding vertices,
-				if (b->nbitems>0){ // BamgVertex QuadTreeBox not empty
-					I2 i2 =  b->v[k]->i;
+				/*k = number of items in the box*/
+				int k=pi[level];
+
+				/*if the current subbox is holding vertices*/
+				if (b->nbitems>0){
+					I2 i2=b->v[k]->i;
 					h0 = NORM(iplus,i2.x,jplus,i2.y);
-					if (h0 <h){
-						h = h0;
-						nearest_v = b->v[k];
+					if (h0<h){
+						h=h0;
+						nearest_v=b->v[k];
 					}
 				}
-
+				/*else: current box b is pointing toward 4 boxes (There must be a vertex at some point)*/
 				else{
-					register QuadTreeBox* b0=b;
+					QuadTreeBox* b0=b;
 
 					//if the next box exists:
-					if ((b=b->b[k])){
-						//shifted righ by one bit: hb2=01000000 -> 00100000
+					if (b=b->b[k]){
+
+						/*Get size (hb) and coordinates of the current sub-box*/
 						hb>>=1;
-						register Icoor1 iii = ii[level]+I_IJ(k,hb);
-						register Icoor1 jjj = jj[level]+J_IJ(k,hb);
-
-						//if the current point is in b,go to next box
+						Icoor1 iii = ii[level]+I_IJ(k,hb);
+						Icoor1 jjj = jj[level]+J_IJ(k,hb);
+
+						/*if the current point (iplus,jplus) is in b,go to next box*/
 						if (INTER_SEG(iii,iii+hb,iplus-h,iplus+h) && INTER_SEG(jjj,jjj+hb,jplus-h,jplus+h)){
 							pb[++level]=  b;
@@ -361,6 +363,8 @@
 						}
 					}
-					//Go backwards
-					else b=b0;
+					/*Go backwards*/
+					else{
+						b=b0;
+					}
 				}
 			}
@@ -371,6 +375,7 @@
 		} while (level--);
 
-		//return nearest_v, nearest vertex
+		/*return nearest_v, nearest vertex*/
 		return nearest_v;
+
 	}
 	/*}}}1*/
@@ -535,10 +540,8 @@
 		do {    
 			b= pb[l];
-			while (pi[l]--)
-			  { 	      
+			while (pi[l]--){ 	      
 				register int k = pi[l];
 
-				if (b->nbitems>0) // BamgVertex QuadTreeBox none empty
-				  { 
+				if (b->nbitems>0){ // BamgVertex QuadTreeBox none empty
 					I2 i2 =  b->v[k]->i;
 					if ( ABS(i-i2.x) <hx && ABS(j-i2.y) <hy )
@@ -548,18 +551,15 @@
 						if( (dd= LengthInterpole(Mx(XY), b->v[k]->m(XY)))  < seuil ){
 							return b->v[k]; 
-						  }
+						}
 					  }
-				  }
-				else // Pointer QuadTreeBox 
-				  { 
+				}
+				else{ // Pointer QuadTreeBox 
 					register QuadTreeBox *b0=b;
-					if ((b=b->b[k]))
-					  {
+					if ((b=b->b[k])){
 						hb >>=1 ; // div by 2
 						register long iii = ii[l]+I_IJ(k,hb);
 						register long jjj = jj[l]+J_IJ(k,hb);
 
-						if  (INTER_SEG(iii,iii+hb,i-hx,i+hx) && INTER_SEG(jjj,jjj+hb,j-hy,j+hy)) 
-						  {
+						if  (INTER_SEG(iii,iii+hb,i-hx,i+hx) && INTER_SEG(jjj,jjj+hb,j-hy,j+hy)){
 							pb[++l]=  b;
 							pi[l]= b->nbitems>0 ?(int)  b->nbitems : 4  ;
@@ -567,12 +567,15 @@
 							jj[l]= jjj;
 
-						  }
-						else
-						 b=b0, hb <<=1 ;
-					  }
-					else
-					 b=b0;
-				  }
-			  }
+						}
+						else{
+							b=b0;
+							hb <<=1 ;
+						}
+					}
+					else{
+						b=b0;
+					}
+				}
+			}
 			hb <<= 1; // mul by 2 
 		} while (l--);
