Index: /issm/trunk-jpl/src/c/classes/IoModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/IoModel.cpp	(revision 23766)
+++ /issm/trunk-jpl/src/c/classes/IoModel.cpp	(revision 23767)
@@ -1,4 +1,4 @@
 /*! \file IoModel.cpp
- * \brief  file containing the methods that will help in processing the input data coming 
+ * \brief  file containing the methods that will help in processing the input data coming
  * into ISSM, from Matlab, or through a binary file opened for reading.
  */
@@ -151,6 +151,6 @@
 	this->numberofverticalfaces=-1;
 	this->numberofedges=-1;
-	this->numberofverticaledges=-1;	
-	this->numberofhorizontaledges=-1;	
+	this->numberofverticaledges=-1;
+	this->numberofhorizontaledges=-1;
 	this->facescols=-1;
 	this->elements=NULL;
@@ -182,6 +182,6 @@
 	this->solution_enum = solution_enum_in;
 
-	/*If we are running in AD mode, we need to start the trace and declare our independent variables now, 
-	 *and prevent them from being erased during successive calls to iomodel->FetchConstants, iomodel->FetchData and 
+	/*If we are running in AD mode, we need to start the trace and declare our independent variables now,
+	 *and prevent them from being erased during successive calls to iomodel->FetchConstants, iomodel->FetchData and
 	 iomodel->DeleteData:*/
 	this->StartTrace(trace);
@@ -342,5 +342,6 @@
 
 	bool        found;
-	int         record_enum,record_length,record_name_size;
+	int         record_enum,record_name_size;
+   long long   record_length;
 	char       *record_name = NULL;
 	const char *mddot = "md.";
@@ -392,5 +393,5 @@
 
 			/*Go to next Enum*/
-			if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
+			if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
 			fseek(fid,record_length,SEEK_CUR);
 			xDelete<char>(record_name);
@@ -467,5 +468,5 @@
 			this->FetchData(&types,NULL,NULL,"md.autodiff.independent_object_types");
 
-			/*create independent objects, and at the same time, fetch the corresponding independent variables, 
+			/*create independent objects, and at the same time, fetch the corresponding independent variables,
 			 *and declare them as such in ADOLC: */
 			for(int i=0;i<num_independent_objects;i++){
@@ -544,5 +545,5 @@
 	if(numstrings){
 		for(int i=0;i<numstrings;i++){
-			char* string=stringarray[i]; 
+			char* string=stringarray[i];
 			xDelete<char>(string);
 		}
@@ -557,5 +558,5 @@
 	char* record_name = NULL;
 	int   record_name_size;
-	int record_length;
+	long long record_length;
 	int record_code; //1 to 7 number
 
@@ -608,5 +609,5 @@
 
 			/* Read the record length and the data type code: */
-			if(fread(&record_length,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_length");
+			if(fread(&record_length,sizeof(long long),1,this->fid)!=1) _error_("Cound not read record_length");
 			if(fread(&record_code  ,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_code");
 
@@ -615,13 +616,13 @@
 
 			/*Tell other cpus the name of the data, then branch according to the data type: */
-			ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-			ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
-			ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm());  
+			ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+			ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
+			ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm());
 
 			switch(record_code){
-				case 1: 
+				case 1:
 					/*Read the boolean and broadcast it to other cpus:*/
 					if(fread(&booleanint,sizeof(int),1,this->fid)!=1) _error_("could not read boolean ");
-					ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+					ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 					/*create BoolParam: */
@@ -644,5 +645,5 @@
 
 					/*Broadcast to other cpus*/
-					ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+					ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 					/*create IntParam: */
@@ -664,5 +665,5 @@
 						if(!exists){
 							if(fread(&pscalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar ");
-							ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+							ISSM_MPI_Bcast(&pscalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 							scalar=pscalar;
 
@@ -672,8 +673,8 @@
 					  }
 					break;
-				case 4: 
+				case 4:
 					/*We have to read a string from disk. First read the dimensions of the string, then the string: */
 					if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string ");
-					ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+					ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 					if(string_size){
@@ -683,5 +684,5 @@
 						/*Read string, then broadcast: */
 						if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string ");
-						ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+						ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 					}
 					else{
@@ -724,8 +725,8 @@
 					xDelete<char>(string);
 					break;
-				case 5: 
-				case 6: 
-				case 7: 
-				case 8: 
+				case 5:
+				case 6:
+				case 7:
+				case 8:
 				case 10:
 					/*We are not interested in this record, too memory intensive. Skip it: */
@@ -734,8 +735,8 @@
 					fseek(fid,record_length,SEEK_CUR);
 					break;
-				case 9: 
+				case 9:
 					/*String Array*/
 					if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array");
-					ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+					ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 					/*Now allocate string array: */
 					if(numstrings){
@@ -747,10 +748,10 @@
 
 							if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
-							ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+							ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 							if(string_size){
 								string=xNew<char>((string_size+1));
 								string[string_size]='\0';
 								if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
-								ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+								ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 							}
 							else{
@@ -769,6 +770,6 @@
 					xDelete<char*>(strings);
 					break;
-				default: 
-					_error_("unknown record type:" << record_code); 
+				default:
+					_error_("unknown record type:" << record_code);
 					break;
 			}
@@ -786,10 +787,10 @@
 				_assert_(record_name_size);
 				record_name=xNew<char>((record_name_size+1)); record_name[record_name_size]='\0';
-				ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
-				ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm());  
+				ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
+				ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm());
 				switch(record_code){
-					case 1: 
+					case 1:
 						/*boolean. get it from cpu 0 */
-						ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+						ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 						/*create BoolParam: */
@@ -799,5 +800,5 @@
 					case 2:
 						/*integer. get it from cpu 0 */
-						ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+						ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 						/*create IntParam: */
@@ -825,6 +826,6 @@
 						  }
 						break;
-					case 4: 
-						ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+					case 4:
+						ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 						if(string_size){
 							string=xNew<char>((string_size+1));
@@ -832,5 +833,5 @@
 
 							/*Read string from cpu 0: */
-							ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+							ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 						}
 						else{
@@ -879,5 +880,5 @@
 					case 10: break; //do nothing. not interested in this type of data, which is memory intensive.
 					case 9:
-							  ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+							  ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 							  /*Now allocate string array: */
 							  if(numstrings){
@@ -888,9 +889,9 @@
 								  for(int i=0;i<numstrings;i++){
 
-									  ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+									  ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 									  if(string_size){
 										  string=xNew<char>((string_size+1));
 										  string[string_size]='\0';
-										  ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+										  ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 									  }
 									  else{
@@ -909,6 +910,6 @@
 							  xDelete<char*>(strings);
 							  break;
-					default: 
-							  _error_("unknown record type:" << record_code); 
+					default:
+							  _error_("unknown record type:" << record_code);
 							  break;
 				}
@@ -933,8 +934,8 @@
 
 	/*We have to read a boolean from disk. */
-	if(my_rank==0){  
+	if(my_rank==0){
 		if(fread(&booleanint,sizeof(int),1,fid)!=1) _error_("could not read boolean ");
 	}
-	ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&booleanint,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	/*cast to bool: */
@@ -959,9 +960,9 @@
 
 	/*We have to read a integer from disk. First read the dimensions of the integer, then the integer: */
-	if(my_rank==0){  
+	if(my_rank==0){
 		if(fread(&integer,sizeof(int),1,fid)!=1) _error_("could not read integer ");
 	}
 
-	ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	/*Assign output pointers: */
@@ -987,5 +988,5 @@
 		if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
 	}
-	ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 
 	/*Assign output pointers: */
@@ -1012,9 +1013,9 @@
 
 	/*We have to read a string from disk. First read the dimensions of the string, then the string: */
-	if(my_rank==0){  
+	if(my_rank==0){
 		if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
 	}
 
-	ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	/*Now allocate string: */
@@ -1024,8 +1025,8 @@
 
 		/*Read string on node 0, then broadcast: */
-		if(my_rank==0){  
+		if(my_rank==0){
 			if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
 		}
-		ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+		ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 	}
 	else{
@@ -1057,8 +1058,8 @@
 	/*Now fetch: */
 
-	if(my_rank==0){  
+	if(my_rank==0){
 		if(fread(&numstrings,sizeof(int),1,fid)!=1) _error_("could not read length of string array");
 	}
-	ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&numstrings,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	/*Now allocate string array: */
@@ -1070,15 +1071,15 @@
 		for(int i=0;i<numstrings;i++){
 
-			if(my_rank==0){  
+			if(my_rank==0){
 				if(fread(&string_size,sizeof(int),1,fid)!=1) _error_("could not read length of string ");
 			}
-			ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 			if(string_size){
 				string=xNew<char>((string_size+1));
 				string[string_size]='\0';
-				if(my_rank==0){  
+				if(my_rank==0){
 					if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
 				}
-				ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+				ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 			}
 			else{
@@ -1116,11 +1117,11 @@
 	/*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
 	/*numberofelements: */
-	if(my_rank==0){  
+	if(my_rank==0){
 		if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
 	}
 
-	ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-	if(my_rank==0){  
+	ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+
+	if(my_rank==0){
 		if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
 	}
@@ -1132,9 +1133,9 @@
 
 		/*Read matrix on node 0, then broadcast: */
-		if(my_rank==0){  
+		if(my_rank==0){
 			if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
 		}
 
-		ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+		ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 	}
 
@@ -1194,10 +1195,10 @@
 		if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
 	}
-	ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-	if(my_rank==0){  
+	ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+
+	if(my_rank==0){
 		if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
 	}
-	ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	/*Now allocate matrix: */
@@ -1207,8 +1208,8 @@
 			IssmPDouble offset,range;
 			if(my_rank==0) if(fread(&offset,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read offset");
-			ISSM_MPI_Bcast(&offset,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&offset,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 
 			if(my_rank==0) if(fread(&range,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read range");
-			ISSM_MPI_Bcast(&range,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&range,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 
 			*pmatrix=xNew<IssmDouble>(M*N);
@@ -1217,5 +1218,5 @@
 			uint8_t* rawmatrix=xNew<uint8_t>((M-1)*N);
 			if(my_rank==0) if(fread(rawmatrix,(M-1)*N*sizeof(char),1,fid)!=1) _error_("could not read matrix ");
-			ISSM_MPI_Bcast(rawmatrix,(M-1)*N,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(rawmatrix,(M-1)*N,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 
 			for(int i=0;i<(M-1)*N;++i) (*pmatrix)[i]=offset+range*reCast<IssmDouble>(rawmatrix[i])/255.;
@@ -1225,5 +1226,5 @@
 			IssmPDouble* timematrix=xNew<IssmPDouble>(N);
 			if(my_rank==0) if(fread(timematrix,N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read time in compressed matrix");
-			ISSM_MPI_Bcast(timematrix,N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(timematrix,N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 
 			for(int i=0;i<N;++i) (*pmatrix)[(M-1)*N+i]=timematrix[i];
@@ -1235,5 +1236,5 @@
 			matrix=xNew<IssmPDouble>(M*N);
 			if(my_rank==0) if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
-			ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 
 			*pmatrix=xNew<IssmDouble>(M*N);
@@ -1272,8 +1273,8 @@
 
 	/*Now fetch: */
-	if(my_rank==0){  
+	if(my_rank==0){
 		if(fread(&numrecords,sizeof(int),1,fid)!=1) _error_("could not read number of records in matrix array ");
 	}
-	ISSM_MPI_Bcast(&numrecords,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&numrecords,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	if(numrecords){
@@ -1293,13 +1294,13 @@
 		for(i=0;i<numrecords;i++){
 
-			if(my_rank==0){  
+			if(my_rank==0){
 				if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows in " << i << "th matrix of matrix array");
 			}
-			ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-			if(my_rank==0){  
+			ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+
+			if(my_rank==0){
 				if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns in " << i << "th matrix of matrix array");
 			}
-			ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 			/*Now allocate matrix: */
@@ -1308,9 +1309,9 @@
 
 				/*Read matrix on node 0, then broadcast: */
-				if(my_rank==0){  
+				if(my_rank==0){
 					if(fread(matrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
 				}
 
-				ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+				ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 				matrices[i]=xNew<IssmDouble>(M*N);
 				for (int j=0;j<M*N;++j) {matrices[i][j]=matrix[j];}
@@ -1338,6 +1339,6 @@
 	char* record_name = NULL;
 	int   record_name_size;
-	int   record_length;
-	int   record_code; 
+	long long record_length;
+	int   record_code;
 
 	/*records: */
@@ -1367,5 +1368,5 @@
 			/*Is this the record sought for? : */
 			if(strcmp(record_name,lastnonoption)==0){
-				if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
+				if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
 				fseek(fid,record_length,SEEK_CUR);
 				xDelete<char>(record_name);
@@ -1373,5 +1374,5 @@
 			}
 			else{
-				if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
+				if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
 				fseek(fid,record_length,SEEK_CUR);
 				xDelete<char>(record_name);
@@ -1416,5 +1417,5 @@
 
 			/* Read the record length and the data type code: */
-			if(fread(&record_length,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_length");
+			if(fread(&record_length,sizeof(long long),1,this->fid)!=1) _error_("Cound not read record_length");
 			if(fread(&record_code  ,sizeof(int),1,this->fid)!=1) _error_("Cound not read record_code");
 
@@ -1423,7 +1424,7 @@
 
 			/*Tell other cpus the name of the data, then branch according to the data type: */
-			ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-			ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
-			ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm());  
+			ISSM_MPI_Bcast(&record_name_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+			ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
+			ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm());
 
 			switch(record_code){
@@ -1431,5 +1432,5 @@
 					  {
 						if(fread(&scalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar ");
-						ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+						ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 						GenericOption<IssmDouble>* option = new GenericOption<IssmDouble>();
 						char* optionname=xNew<char>(strlen(record_name)-3+1);
@@ -1442,9 +1443,9 @@
 					  }
 					break;
-				case 4: 
+				case 4:
 					  {
 					/*We have to read a string from disk. First read the dimensions of the string, then the string: */
 					if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string ");
-					ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+					ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 					if(string_size){
@@ -1454,5 +1455,5 @@
 						/*Read string, then broadcast: */
 						if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string ");
-						ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+						ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 					}
 					else{
@@ -1473,6 +1474,6 @@
 					  }
 					break;
-				default: 
-					_error_("record type not supported:" << record_code); 
+				default:
+					_error_("record type not supported:" << record_code);
 					break;
 			}
@@ -1490,11 +1491,11 @@
 				_assert_(record_name_size);
 				record_name=xNew<char>((record_name_size+1)); record_name[record_name_size]='\0';
-				ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
-				ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_INT,0,IssmComm::GetComm());  
+				ISSM_MPI_Bcast(record_name,record_name_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
+				ISSM_MPI_Bcast(&record_length,1,ISSM_MPI_LONG_LONG_INT,0,IssmComm::GetComm());
 				switch(record_code){
 					case 3:
 						  {
 							if(fread(&scalar,sizeof(IssmPDouble),1,this->fid)!=1) _error_("could not read scalar ");
-							ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+							ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 							char* optionname=xNew<char>(strlen(record_name)-3+1);
 							xMemCpy(optionname,&record_name[3],strlen(record_name)-3+1);
@@ -1507,9 +1508,9 @@
 						  }
 						break;
-					case 4: 
+					case 4:
 						  {
 						/*We have to read a string from disk. First read the dimensions of the string, then the string: */
 						if(fread(&string_size,sizeof(int),1,this->fid)!=1) _error_("could not read length of string ");
-						ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+						ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 						if(string_size){
@@ -1519,5 +1520,5 @@
 							/*Read string, then broadcast: */
 							if(fread(string,string_size*sizeof(char),1,this->fid)!=1)_error_(" could not read string ");
-							ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+							ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 						}
 						else{
@@ -1537,6 +1538,6 @@
 						  }
 						break;
-					default: 
-						_error_("record type not supported:" << record_code); 
+					default:
+						_error_("record type not supported:" << record_code);
 						break;
 				}
@@ -1625,5 +1626,5 @@
 	for(int i=0;i<elements->Size();i++){
 		Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
-		if(!doublearray) element->AddInput(input_enum,&default_value,P0Enum); 
+		if(!doublearray) element->AddInput(input_enum,&default_value,P0Enum);
 		else             element->InputCreate(doublearray,this,M,N,vector_layout,input_enum,code);//we need i to index into elements.
 	}
@@ -1684,5 +1685,5 @@
 				element->InputUpdateFromConstant(scalar,input_enum);
 			}
-			break; 
+			break;
 		case 5: //boolean vector
 			this->FetchData(&doublearray,&M,&N,vector_name); //we still have a doublearray, because it might include times in transient mode
@@ -1743,5 +1744,5 @@
 		if(fread(&pscalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
 
-		/*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!. If we 
+		/*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!. If we
 		 *have been supplied an X vector, use it instead of what we just read: */
 		#if defined(_HAVE_CODIPACK_)
@@ -1765,5 +1766,5 @@
 	}
 
-	ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
 	this->AddConstantIndependent(new IoConstant(scalar,constant_name));
 
@@ -1796,13 +1797,13 @@
 	/*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
 	/*numberofelements: */
-	if(my_rank==0){  
+	if(my_rank==0){
 		if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
 	}
-	ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-	if(my_rank==0){  
+	ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+
+	if(my_rank==0){
 		if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
 	}
-	ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	/*Now allocate matrix: */
@@ -1818,5 +1819,5 @@
 
 		/*Read matrix on node 0, then broadcast: */
-		if(my_rank==0){  
+		if(my_rank==0){
 			if(fread(buffer,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
 
@@ -1849,5 +1850,5 @@
 			#endif
 		}
-		ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
+		ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
 
 		xDelete<IssmPDouble>(buffer);
@@ -1856,5 +1857,5 @@
 
 	// FIXME codi is that at all relevant to CoDiPack or can we simply assume the same?
-	
+
 	/*Add to data as independent*/
 	this->AddDataIndependent(new IoData(matrix,code,layout,M,N,data_name));
@@ -1893,5 +1894,5 @@
 			if(my_rank==0){
 				/*check we are indeed finding a string, not something else: */
-				if(codes[i]!=4)_error_("expecting a string for \""<<data_name<<"\"");
+				if(codes[i]!=4)_error_("expecting a string for \""<<data_name<<"\" but code is "<<codes[i]<<" not 4");
 
 				/*We have to read a string from disk. First read the dimensions of the string, then the string: */
@@ -1900,5 +1901,5 @@
 			}
 
-			ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&string_size,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 			/*Now allocate string: */
@@ -1911,5 +1912,5 @@
 					if(fread(string,string_size*sizeof(char),1,fid)!=1)_error_(" could not read string ");
 				}
-				ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm()); 
+				ISSM_MPI_Bcast(string,string_size,ISSM_MPI_CHAR,0,IssmComm::GetComm());
 			}
 			else{
@@ -1962,9 +1963,9 @@
 				/*We have to read a integer from disk. First read the dimensions of the integer, then the integer: */
 				fsetpos(fid,file_positions+i);
-				if(my_rank==0){  
+				if(my_rank==0){
 					if(fread(&integer,sizeof(int),1,fid)!=1) _error_("could not read integer ");
 				}
 			}
-			ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&integer,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 			/*Assign: */
@@ -2015,9 +2016,9 @@
 				/*We have to read a double from disk: */
 				fsetpos(fid,file_positions+i);
-				if(my_rank==0){  
+				if(my_rank==0){
 					if(fread(&scalar,sizeof(IssmPDouble),1,fid)!=1) _error_("could not read scalar ");
 				}
 			}
-			ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 
 			/*Assign: */
@@ -2077,10 +2078,10 @@
 				if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
 			}
-			ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-			if(my_rank==0){  
+			ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+
+			if(my_rank==0){
 				if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
 			}
-			ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 			/*Now allocate matrix: */
@@ -2089,11 +2090,11 @@
 
 				/*Read matrix on node 0, then broadcast: */
-				if(my_rank==0){  
+				if(my_rank==0){
 					if(fread(pmatrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
 				}
-				ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+				ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 
 				//if(this->independents[data_enum]){ FIXME
-				//	/*this data has already been checked out! So cancel all that we've done here, and return 
+				//	/*this data has already been checked out! So cancel all that we've done here, and return
 				//	 * the data[data_enum] directly: */
 				//	matrix=this->data[data_enum];
@@ -2179,10 +2180,10 @@
 				if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
 			}
-			ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-			if(my_rank==0){  
+			ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+
+			if(my_rank==0){
 				if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
 			}
-			ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+			ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 			/*Now allocate matrix: */
@@ -2192,11 +2193,11 @@
 
 				/*Read matrix on node 0, then broadcast: */
-				if(my_rank==0){  
+				if(my_rank==0){
 					if(fread(pmatrix,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
 				}
-				ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 
+				ISSM_MPI_Bcast(pmatrix,M*N,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
 
 				//if(this->independents[data_enum]){ FIXME
-				//	/*this data has already been checked out! So cancel all that we've done here, and return 
+				//	/*this data has already been checked out! So cancel all that we've done here, and return
 				//	 * the data[data_enum] directly: */
 				//	matrix=this->data[data_enum];
@@ -2382,5 +2383,5 @@
 	char* record_name = NULL;
 	int   record_name_size;
-	int     record_length;
+	long long  record_length;
 	int     record_code;           //1 to 7 number
 	int     vector_type;           //1 to 7 number
@@ -2395,5 +2396,5 @@
 	_assert_(strncmp(data_name,mddot,3)==0);
 
-	/*Go find in the binary file, the data we want to fetch and count the number of 
+	/*Go find in the binary file, the data we want to fetch and count the number of
 	 * instances it appears: */
 	if(my_rank==0){
@@ -2430,5 +2431,5 @@
 
 			/*Read the record length, and use it to skip the record: */
-			if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
+			if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
 			fseek(fid,record_length,SEEK_CUR);
 			xDelete<char>(record_name);
@@ -2442,5 +2443,5 @@
 		}
 
-		/*Reset FILE* position to the beginning of the file, and start again, this time saving the data information 
+		/*Reset FILE* position to the beginning of the file, and start again, this time saving the data information
 		 * as we find it: */
 		counter=0;
@@ -2474,5 +2475,5 @@
 			if(strcmp(record_name,data_name)==0){
 				/*Ok, we have found the correct string. Pass the record length, and read data type code: */
-				fseek(fid,sizeof(int),SEEK_CUR);
+				fseek(fid,sizeof(long long),SEEK_CUR);
 				if(fread(&record_code,sizeof(int),1,fid)!=1) _error_("Could not read record_code");
 
@@ -2486,7 +2487,7 @@
 
 				/*backup and skip over the record, as we have more work to do: */
-				if(5<=record_code && record_code<=7) fseek(fid,-sizeof(int),SEEK_CUR);
-				fseek(fid,-sizeof(int),SEEK_CUR);
-				fseek(fid,-sizeof(int),SEEK_CUR);
+				if(5<=record_code && record_code<=7) fseek(fid,-sizeof(int),SEEK_CUR); /*rewind for nodal or elementary type*/
+				fseek(fid,-sizeof(int),SEEK_CUR);/*rewind for data code*/
+				fseek(fid,-sizeof(long long),SEEK_CUR);/*rewind for record length*/
 
 				/*increment counter: */
@@ -2495,5 +2496,5 @@
 
 			/*Read the record length, and use it to skip this record, as it has already been processed: */
-			if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
+			if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
 			/*skip: */
 			fseek(fid,record_length,SEEK_CUR);
@@ -2503,5 +2504,5 @@
 
 	/*Broadcast data: */
-	ISSM_MPI_Bcast(&num_instances,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&num_instances,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	/*Assign output pointers:*/
@@ -2525,5 +2526,5 @@
 	char* record_name = NULL;
 	int   record_name_size;
-	int record_length;
+	long long record_length;
 	int record_code;       //1 to 7 number
 	int vector_type   = 0; //nodal or elementary
@@ -2571,7 +2572,6 @@
 			if(strcmp(record_name,data_name)==0){
 				/*Ok, we have found the correct string. Pass the record length, and read data type code: */
-				fseek(fid,sizeof(int),SEEK_CUR);
+				fseek(fid,sizeof(long long),SEEK_CUR);
 				if(fread(&record_code,sizeof(int),1,fid)!=1) _error_("Could not read record_code");
-
 				/*if record_code points to a vector, get its type (nodal or elementary): */
 				if((5<=record_code && record_code<=7) || record_code==10){
@@ -2584,5 +2584,5 @@
 			else{
 				/*This is not the correct string, read the record length, and use it to skip this record: */
-				if(fread(&record_length,sizeof(int),1,fid)!=1) _error_("Could not read record_length");
+				if(fread(&record_length,sizeof(long long),1,fid)!=1) _error_("Could not read record_length");
 				/*skip: */
 				fseek(fid,record_length,SEEK_CUR);
@@ -2591,10 +2591,10 @@
 		}
 	}
-	ISSM_MPI_Bcast(&found,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&found,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 	if(!found)_error_("could not find data with name \"" << data_name << "\" in binary file");
 
 	/*Broadcast code and vector type: */
-	ISSM_MPI_Bcast(&record_code,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-	ISSM_MPI_Bcast(&vector_type,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+	ISSM_MPI_Bcast(&record_code,1,ISSM_MPI_INT,0,IssmComm::GetComm());
+	ISSM_MPI_Bcast(&vector_type,1,ISSM_MPI_INT,0,IssmComm::GetComm());
 
 	/*Assign output pointers:*/
Index: /issm/trunk-jpl/src/m/solve/WriteData.m
===================================================================
--- /issm/trunk-jpl/src/m/solve/WriteData.m	(revision 23766)
+++ /issm/trunk-jpl/src/m/solve/WriteData.m	(revision 23767)
@@ -47,6 +47,6 @@
 
 %Step 1: write the name to identify this record uniquely
-fwrite(fid,numel(name),'int'); 
-fwrite(fid,name,'char'); 
+fwrite(fid,numel(name),'int');
+fwrite(fid,name,'char');
 
 %Step 2: write the data itself.
@@ -55,8 +55,8 @@
 
 	%first write length of record
-	fwrite(fid,4+4,'int');  %1 bool (disguised as an int)+code
-
-	%write data code: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	fwrite(fid,4+4,'int64');  %1 bool (disguised as an int)+code
+
+	%write data code:
+	fwrite(fid,FormatToCode(format),'int');
 
 	%now write integer
@@ -67,11 +67,11 @@
 
 	%first write length of record
-	fwrite(fid,4+4,'int');  %1 integer + code
-
-	%write data code: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	fwrite(fid,4+4,'int64');  %1 integer + code
+
+	%write data code:
+	fwrite(fid,FormatToCode(format),'int');
 
 	%now write integer
-	fwrite(fid,data,'int'); 
+	fwrite(fid,data,'int');
 	% }}}
 elseif strcmpi(format,'Double'), % {{{
@@ -79,22 +79,22 @@
 
 	%first write length of record
-	fwrite(fid,8+4,'int');  %1 double+code
-
-	%write data code: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	fwrite(fid,8+4,'int64');  %1 double+code
+
+	%write data code:
+	fwrite(fid,FormatToCode(format),'int');
 
 	%now write double
-	fwrite(fid,data,'double'); 
+	fwrite(fid,data,'double');
 	% }}}
 elseif strcmpi(format,'String'), % {{{
 	%first write length of record
-	fwrite(fid,length(data)+4+4,'int');  %string + string size + code
-
-	%write data code: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	fwrite(fid,length(data)+4+4,'int64');  %string + string size + code
+
+	%write data code:
+	fwrite(fid,FormatToCode(format),'int');
 
 	%now write string
-	fwrite(fid,length(data),'int'); 
-	fwrite(fid,data,'char'); 
+	fwrite(fid,length(data),'int');
+	fwrite(fid,data,'char');
 	% }}}
 elseif strcmpi(format,'BooleanMat'), % {{{
@@ -108,13 +108,13 @@
 
 	%first write length of record
-	fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int');  %2 integers (32 bits) + the double matrix + code + matrix type
-
-	%write data code and matrix type: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int64');  %2 integers (32 bits) + the double matrix + code + matrix type
+
+	%write data code and matrix type:
+	fwrite(fid,FormatToCode(format),'int');
 	fwrite(fid,mattype,'int');
 
 	%now write matrix
-	fwrite(fid,s(1),'int'); 
-	fwrite(fid,s(2),'int'); 
+	fwrite(fid,s(1),'int');
+	fwrite(fid,s(2),'int');
 	if s(1)*s(2),
 		fwrite(fid,data','double'); %get to the "c" convention, hence the transpose
@@ -131,13 +131,13 @@
 
 	%first write length of record
-	fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int');  %2 integers (32 bits) + the double matrix + code + matrix type
-
-	%write data code and matrix type: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	fwrite(fid,4+4+8*s(1)*s(2)+4+4,'int64');  %2 integers (32 bits) + the double matrix + code + matrix type
+
+	%write data code and matrix type:
+	fwrite(fid,FormatToCode(format),'int');
 	fwrite(fid,mattype,'int');
 
 	%now write matrix
-	fwrite(fid,s(1),'int'); 
-	fwrite(fid,s(2),'int'); 
+	fwrite(fid,s(1),'int');
+	fwrite(fid,s(2),'int');
 	if s(1)*s(2),
 		fwrite(fid,data','double'); %get to the "c" convention, hence the transpose
@@ -155,14 +155,14 @@
 	%first write length of record
 	recordlength=4+4+8*s(1)*s(2)+4+4; %2 integers (32 bits) + the double matrix + code + matrix type
-	if recordlength>2^31; error(['field ' name ' cannot be marshalled because it is larger than 2^31 bytes!']); end
-	fwrite(fid,recordlength,'int');
-
-	%write data code and matrix type: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	if recordlength>2^63; error(['field ' name ' cannot be marshalled because it is larger than 2^63 bytes!']); end
+	fwrite(fid,recordlength,'int64');
+
+	%write data code and matrix type:
+	fwrite(fid,FormatToCode(format),'int');
 	fwrite(fid,mattype,'int');
 
 	%now write matrix
-	fwrite(fid,s(1),'int'); 
-	fwrite(fid,s(2),'int'); 
+	fwrite(fid,s(1),'int');
+	fwrite(fid,s(2),'int');
 	if s(1)*s(2),
 		fwrite(fid,data','double'); %get to the "c" convention, hence the transpose
@@ -180,14 +180,14 @@
 	%first write length of record
 	recordlength=4+4+8+8+1*(s(1)-1)*s(2)+8*s(2)+4+4; %2 integers (32 bits) + the matrix + code + matrix type
-	if recordlength>2^31; error(['field ' name ' cannot be marshalled because it is larger than 2^31 bytes!']); end
-	fwrite(fid,recordlength,'int');
-
-	%write data code and matrix type: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	if recordlength>2^63; error(['field ' name ' cannot be marshalled because it is larger than 2^63 bytes!']); end
+	fwrite(fid,recordlength,'int64');
+
+	%write data code and matrix type:
+	fwrite(fid,FormatToCode(format),'int');
 	fwrite(fid,mattype,'int');
 
 	%write matrix size
-	fwrite(fid,s(1),'int'); 
-	fwrite(fid,s(2),'int'); 
+	fwrite(fid,s(1),'int');
+	fwrite(fid,s(2),'int');
 
 	if s(1)*s(2),
@@ -205,5 +205,5 @@
 
 		%Write last row as double (time)
-		fwrite(fid,data(end,:),'double'); 
+		fwrite(fid,data(end,:),'double');
 	else
 
@@ -227,18 +227,18 @@
 
 	%write length of record
-	fwrite(fid,recordlength,'int'); 
-
-	%write data code: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	fwrite(fid,recordlength,'int64');
+
+	%write data code:
+	fwrite(fid,FormatToCode(format),'int');
 
 	%write data, first number of records
-	fwrite(fid,numrecords,'int'); 
-
-	%write each matrix: 
+	fwrite(fid,numrecords,'int');
+
+	%write each matrix:
 	for i=1:numrecords,
 		matrix=data{i};
 		s=size(matrix);
-		fwrite(fid,s(1),'int'); 
-		fwrite(fid,s(2),'int'); 
+		fwrite(fid,s(1),'int');
+		fwrite(fid,s(2),'int');
 		fwrite(fid,matrix','double');
 	end
@@ -246,5 +246,5 @@
 elseif strcmpi(format,'StringArray'), % {{{
 
-	%first get length of string array: 
+	%first get length of string array:
 	num=numel(data);
 	if isnumeric(data) & num==1 & isnan(data),
@@ -252,5 +252,5 @@
 	end
 
-	%now get length of record: 
+	%now get length of record:
 	recordlength=4+4; %for length of array + code
 	for i=1:num,
@@ -260,17 +260,17 @@
 
 	%write length of record
-	fwrite(fid,recordlength,'int'); 
-
-	%write data code: 
-	fwrite(fid,FormatToCode(format),'int'); 
+	fwrite(fid,recordlength,'int64');
+
+	%write data code:
+	fwrite(fid,FormatToCode(format),'int');
 
 	%now write length of string array
-	fwrite(fid,num,'int'); 
+	fwrite(fid,num,'int');
 
 	%now write the strings
 	for i=1:num,
 		string=data{i};
-		fwrite(fid,length(string),'int'); 
-		fwrite(fid,string,'char'); 
+		fwrite(fid,length(string),'int');
+		fwrite(fid,string,'char');
 	end
 	% }}}
@@ -281,14 +281,14 @@
 
 function code=FormatToCode(format) % {{{
-%This routine takes the format string, and hardcodes it into an integer, which 
-%is passed along the record, in order to identify the nature of the dataset being 
+%This routine takes the format string, and hardcodes it into an integer, which
+%is passed along the record, in order to identify the nature of the dataset being
 %sent.
 	if     strcmpi(format,'Boolean'),
 		code=1;
-	elseif strcmpi(format,'Integer'), 
+	elseif strcmpi(format,'Integer'),
 		code=2;
-	elseif strcmpi(format,'Double'), 
+	elseif strcmpi(format,'Double'),
 		code=3;
-	elseif strcmpi(format,'String'), 
+	elseif strcmpi(format,'String'),
 		code=4;
 	elseif strcmpi(format,'BooleanMat'),
@@ -298,5 +298,5 @@
 	elseif strcmpi(format,'DoubleMat'),
 		code=7;
-	elseif strcmpi(format,'MatArray'), 
+	elseif strcmpi(format,'MatArray'),
 		code=8;
 	elseif strcmpi(format,'StringArray'),
@@ -304,5 +304,5 @@
 	elseif strcmpi(format,'CompressedMat'),
 		code=10;
-	else 
+	else
 		error('FormatToCode error message: data type not supported yet!');
 	end
