Index: /issm/trunk/src/c/modules/GroundingLineMigrationx/CreateElementOnIceShelf.cpp
===================================================================
--- /issm/trunk/src/c/modules/GroundingLineMigrationx/CreateElementOnIceShelf.cpp	(revision 7286)
+++ /issm/trunk/src/c/modules/GroundingLineMigrationx/CreateElementOnIceShelf.cpp	(revision 7287)
@@ -22,4 +22,5 @@
 	for(i=0;i<elements->Size();i++){
 		element=(Element*)elements->GetObjectByOffset(i);
+		printf("%i\n",i);
 		VecSetValue(vec_element_on_iceshelf,element->Sid(),(int)element->IsOnShelf(),INSERT_VALUES);
 	}
Index: /issm/trunk/src/c/modules/GroundingLineMigrationx/CreateElementTouchingIceShelf.cpp
===================================================================
--- /issm/trunk/src/c/modules/GroundingLineMigrationx/CreateElementTouchingIceShelf.cpp	(revision 7286)
+++ /issm/trunk/src/c/modules/GroundingLineMigrationx/CreateElementTouchingIceShelf.cpp	(revision 7287)
@@ -22,5 +22,5 @@
 	for(i=0;i<elements->Size();i++){
 		element=(Element*)elements->GetObjectByOffset(i);
-		VecSetValue(vec_element_touching_iceshelf,element->Sid(),(int)element->IsNodeOnShelf(),INSERT_VALUES);
+		VecSetValue(vec_element_touching_iceshelf,element->Sid(),element->IsNodeOnShelf()?1.0:0.0,INSERT_VALUES);
 	}
 
Index: /issm/trunk/src/c/modules/GroundingLineMigrationx/GroundingLineMigrationx.cpp
===================================================================
--- /issm/trunk/src/c/modules/GroundingLineMigrationx/GroundingLineMigrationx.cpp	(revision 7286)
+++ /issm/trunk/src/c/modules/GroundingLineMigrationx/GroundingLineMigrationx.cpp	(revision 7287)
@@ -18,22 +18,29 @@
 	_printf_(VerboseModule(),"   Migrating grounding line\n");
 
-	/*Create  vector holding  all the elements that touch the ice shelf: */
-	element_touching_iceshelf=CreateElementTouchingIceShelf(elements);
+	/*Loop until no more nodes and elements  change from grounded to floating: */
+	nflipped=1; //arbitrary, get things started
+	while(nflipped){
 
-	/*Carry out grounding line migration for those elements: */
-	for(i=0;i<elements->Size();i++){
-		if (element_touching_iceshelf[i]){
+		/*reset counter: */
+		nflipped=0;
+
+		/*Create  vector holding  all the elements that touch the ice shelf, by any node: */
+		element_touching_iceshelf=CreateElementTouchingIceShelf(elements);
+
+		/*Carry out grounding line migration for those elements: */
+		for(i=0;i<elements->Size();i++){
 			element=(Element*)elements->GetObjectByOffset(i);
-			element->MigrateGroundingLine();
+			if(element_touching_iceshelf[element->Sid()]) element->MigrateGroundingLine();
 		}
+
+		/*Now, update shelf flags in nodes and elements: */
+		nflipped=UpdateShelfStatus(elements,nodes,parameters,element_touching_iceshelf);
+		_printf_(VerboseModule(),"      number of migrated nodes: %i\n",nflipped);
+
+		/*avoid memory leaks: */
+		xfree((void**)&element_touching_iceshelf);
 	}
-
-	/*Now, update shelf flags in nodes and elements. We could not do this before, 
-	 *because we would end up with discontinuous bed and surface otherwise: */
-	for(i=0;i<elements->Size();i++){
-		element=(Element*)elements->GetObjectByOffset(i);
-		element->UpdateShelfStatus();
-	}
-
+		
+	
 	/*free ressouces: */
 	xfree((void**)&element_touching_iceshelf);
Index: /issm/trunk/src/c/modules/GroundingLineMigrationx/GroundingLineMigrationxLocal.h
===================================================================
--- /issm/trunk/src/c/modules/GroundingLineMigrationx/GroundingLineMigrationxLocal.h	(revision 7286)
+++ /issm/trunk/src/c/modules/GroundingLineMigrationx/GroundingLineMigrationxLocal.h	(revision 7287)
@@ -12,4 +12,6 @@
 bool*   CreateElementOnGroundingLine(Elements* elements,double* element_on_iceshelf);
 double* CreateElementTouchingIceShelf(Elements* elements);
+int UpdateShelfStatus(Elements* elements,Nodes* nodes,Parameters* parameters);
+int UpdateShelfStatus(Elements* elements,Nodes* nodes,Parameters* parameters,double* element_touching_iceshelf);
 
 #endif  /* _GROUNDINGLINEMIGRATIONXLOCAL_H */
Index: /issm/trunk/src/c/modules/GroundingLineMigrationx/UpdateShelfStatus.cpp
===================================================================
--- /issm/trunk/src/c/modules/GroundingLineMigrationx/UpdateShelfStatus.cpp	(revision 7287)
+++ /issm/trunk/src/c/modules/GroundingLineMigrationx/UpdateShelfStatus.cpp	(revision 7287)
@@ -0,0 +1,51 @@
+/*!\file UpdateShelfStatus
+ * \brief: update elements and nodes shelf status. Plus return how many nodes have changed status. */
+ */
+
+#include "./GroundingLineMigrationxLocal.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../toolkits/toolkits.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+
+int UpdateShelfStatus(Elements* elements,Nodes* nodes,Parameters* parameters,double* element_touching_iceshelf){
+	
+	int i;
+	Element* element=NULL;
+	int analysis_type;
+	int numnods;
+	Vec vec_new_shelf_nodes=NULL;
+
+	/*output: */
+	int nflipped=0;
+
+	/*recover parameters: */
+	parameters->FindParam(&analysis_type,AnalysisTypeEnum);
+
+	/*First, initialize vec_new_shelf_nodes, which will track which nodes have changed status: */
+	numnods=nodes->NumberOfNodes(analysis_type);
+	vec_new_shelf_nodes=NewVec(numnods);
+
+	/*Ok, now go through  the elements that have gone through grounding line migration, 
+	 * and update their flags: */
+	for(i=0;i<elements->Size();i++){
+		element=(Element*)elements->GetObjectByOffset(i);
+		nflipped+=element->UpdateShelfStatus(vec_new_shelf_nodes);
+	}
+
+	/*Serialize vec_new_shelf_nodes: */
+	VecToMPISerial(&new_shelf_nodes,vec_new_shelf_nodes);
+
+	/*Now, go through ALL elements, and update the status of the nodes, to propagate what happened at the grounding line: */
+	/*Carry out grounding line migration for those elements: */
+	for(i=0;i<elements->Size();i++){
+		element=(Element*)elements->GetObjectByOffset(i);
+		element->UpdateShelfFlags(new_shelf_nodes);
+	}
+
+	/*Free ressources: */
+	VecFree(&vec_new_shelf_nodes);
+	xfree((void**)&new_shelf_nodes);
+
+	return nflipped;
+}
