Index: /issm/trunk-jpl/src/c/classes/IoModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/IoModel.cpp	(revision 16512)
+++ /issm/trunk-jpl/src/c/classes/IoModel.cpp	(revision 16513)
@@ -134,9 +134,8 @@
 void  IoModel::CheckEnumSync(void){
 
-	int my_rank;
-	int record_enum = 0;
+	int record_enum,record_length;
 
 	/*recover my_rank:*/
-	my_rank=IssmComm::GetRank();
+	int my_rank=IssmComm::GetRank();
 
 	/*Check that some fields have been allocated*/
@@ -171,4 +170,47 @@
 				_error_("Enums not consistent (See error message above)");
 			}
+		}
+
+		/*Get last enum*/
+		bool found     = false;
+		int  last_enum = 0;
+
+		/*First set FILE* position to the beginning of the file: */
+		fseek(fid,0,SEEK_SET);
+		for(;;){
+			/*Have we reached the end of file ?*/
+			if(fread(&record_enum,sizeof(int),1,fid)==0){
+				break;
+			}
+
+			/*Have we found the last Enum ?*/
+			if(record_enum==MaximumNumberOfDefinitionsEnum+1){
+				found = true;
+				break;
+			}
+
+			/*Check that record_enum is an enum*/
+			if(record_enum>=0 && record_enum<=MaximumNumberOfDefinitionsEnum){
+				if(record_enum>0) last_enum = record_enum;
+			}
+
+			/*Go to next Enum*/
+			if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
+			fseek(fid,record_length,SEEK_CUR);
+		}
+		if(!found){
+			_printf0_("\n");
+			_printf0_("=========================================================================\n");
+			_printf0_(" Marshalled file is corrupted                                            \n");
+			_printf0_("                                                                         \n");
+			_printf0_("   * If you are running an old model, send it to the ISSM developers     \n");
+			_printf0_("     so that a check is added before marshall                            \n");
+			_printf0_("   * Last Enum found: " << EnumToStringx(last_enum)<<"Enum ("<<last_enum<<")\n");
+			_printf0_("     the corresponding model field has probably been marshalled          \n");
+			_printf0_("     incorrectly                                                         \n");
+			_printf0_("                                                                         \n");
+			_printf0_("=========================================================================\n");
+			_printf0_("\n");
+			_error_("Binary file corrupted (See error message above)");
 		}
 	}
