Index: /issm/trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 19238)
+++ /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 19239)
@@ -624,14 +624,16 @@
 	/*Create buffer to hold marshalled femmodel: */
 	this->Marshall(NULL,&femmodel_size,MARSHALLING_SIZE);
-	femmodel_buffer=xNew<char>(femmodel_size); 
+	femmodel_buffer=xNew<char>(femmodel_size+1); 
+	femmodel_buffer_ini=femmodel_buffer;
+	std::cout << "Model size: " << femmodel_size << "\n";
+	std::cout << "Buffer: " << &femmodel_buffer << "\n";
 
 	/*Keep track of initial position of femmodel_buffer: */
-	femmodel_buffer_ini=femmodel_buffer;
+	//std::cout << "Buffer_ini: " << femmodel_buffer_ini << "\n";
 	
 	/*Marshall:*/
-	this->Marshall(&femmodel_buffer,NULL,MARSHALLING_FORWARD);
-
-	/*Reset position of buffer: */
-	femmodel_buffer=femmodel_buffer_ini;
+	this->Marshall(&femmodel_buffer_ini,NULL,MARSHALLING_FORWARD);
+
+	std::cout << "Buffer_new: " << &femmodel_buffer << "\n";
 
 	/*write buffer: */
@@ -662,5 +664,8 @@
 	restartfid=pfopen(restartfilename,"r",false);
 
-	if(restartfid==NULL)return; //could not find the file, so no restart possible.
+	if(restartfid==NULL){
+		xDelete<char>(restartfilename);
+		return; //could not find the file, so no restart possible.
+	}
 
 	/*Figure out size of buffer to be read: */
@@ -673,9 +678,12 @@
 
 	/*Read buffer from file: */
-	fread_return=fread(femmodel_buffer,femmodel_size,1,restartfid); if(fread_return!=1)_error_("error reading the buffer from marshalled file!");
+	fread_return=fread(femmodel_buffer,femmodel_size,sizeof(char),restartfid); if(fread_return!=1)_error_("error reading the buffer from marshalled file!");
 	femmodel_buffer_ini=femmodel_buffer; //keep track of the initial position, so as to free later.
 
 	/*Create new FemModel by demarshalling the buffer: */
 	this->Marshall(&femmodel_buffer,NULL,MARSHALLING_BACKWARD);
+
+	/*Reset position of buffer: */
+	femmodel_buffer=femmodel_buffer_ini;
 
 	/*Done, close file :*/
@@ -690,6 +698,9 @@
 void FemModel::Marshall(char** pmarshalled_data, int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
 
-	if(marshall_direction==MARSHALLING_BACKWARD){
-		delete profiler; profiler=new Profiler;
+	int       i;
+	int       analysis_type;
+
+	if(false && marshall_direction==MARSHALLING_BACKWARD){
+		delete profiler; profiler=new Profiler();
 		delete elements; elements=new Elements();
 		delete nodes; nodes=new Nodes();
@@ -703,19 +714,43 @@
 	}
 
+	char ** ptemp=pmarshalled_data;
+
 	MARSHALLING_ENUM(FemModelEnum);
 
 	MARSHALLING(solution_type);
+	if(marshall_direction!=MARSHALLING_SIZE){
+	std::cout << "Buffer_2: " << pmarshalled_data << "\n";
+	std::cout << "Buffer_old: " << ptemp << "\n";
+	}
 	MARSHALLING(analysis_counter);
-	MARSHALLING_DYNAMIC(analysis_type_list,int,analysis_counter);
-
-	profiler->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
-	elements->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
-	nodes->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
-	vertices->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
-	constraints->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+	MARSHALLING(nummodels);
+	MARSHALLING_DYNAMIC(analysis_type_list,int,nummodels);
+
+/*	profiler->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	loads->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	materials->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	parameters->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+	constraints->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	results->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+	nodes->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+	vertices->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+	elements->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+
+	if(marshall_direction==MARSHALLING_BACKWARD){
+		//reset hooks for elements, loads and nodes:
+		elements->ResetHooks();
+		loads->ResetHooks();
+		materials->ResetHooks();
+
+		//do the post-processing of the datasets to get an FemModel that can actually run analyses:
+		for(i=0;i<nummodels;i++){
+			analysis_type=analysis_type_list[i];
+			SetCurrentConfiguration(analysis_type);
+			if(i==0) VerticesDofx(vertices,parameters); //only call once, we only have one set of vertices
+			SpcNodesx(nodes,constraints,parameters,analysis_type);
+			NodesDofx(nodes,parameters,analysis_type);
+			ConfigureObjectsx(elements,loads,nodes,vertices,materials,parameters);
+		}
+	}*/
 
 }
Index: /issm/trunk-jpl/src/c/classes/Profiler.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Profiler.cpp	(revision 19238)
+++ /issm/trunk-jpl/src/c/classes/Profiler.cpp	(revision 19239)
@@ -74,14 +74,7 @@
 	MARSHALLING_ENUM(ProfilerEnum);
 
-	if(marshall_direction==MARSHALLING_BACKWARD){
-		this->time=new Parameters();
-		this->flops=new Parameters();
-		this->memory=new Parameters();
-	}
-	
 	time->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	flops->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
 	memory->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
-
 
 }
Index: /issm/trunk-jpl/src/c/datastructures/DataSet.cpp
===================================================================
--- /issm/trunk-jpl/src/c/datastructures/DataSet.cpp	(revision 19238)
+++ /issm/trunk-jpl/src/c/datastructures/DataSet.cpp	(revision 19239)
@@ -90,9 +90,13 @@
 	
 	vector<Object*>::iterator obj;
+	int obj_size=0;
 	int obj_enum;
 	int i;
 
 	if(marshall_direction==MARSHALLING_FORWARD || marshall_direction==MARSHALLING_SIZE){
-		numsorted=objects.size();
+		obj_size=objects.size();
+	}
+	else{
+		clear();
 	}
 
@@ -102,9 +106,15 @@
 	MARSHALLING(presorted);
 	MARSHALLING(numsorted);
-	MARSHALLING_DYNAMIC(sorted_ids,int,numsorted);
-	MARSHALLING_DYNAMIC(id_offsets,int,numsorted);
 
 	/*Now branch according to direction of marshalling: */
 	if(marshall_direction==MARSHALLING_FORWARD || marshall_direction==MARSHALLING_SIZE){
+		if(!(this->sorted && numsorted>0 && this->id_offsets)){
+			sorted_ids=NULL;
+			id_offsets=NULL;
+		  }
+		MARSHALLING_DYNAMIC(sorted_ids,int,numsorted);
+		MARSHALLING_DYNAMIC(id_offsets,int,numsorted);
+		MARSHALLING(obj_size);
+
 		/*Go through our objects, and marshall them into the buffer: */
 		for ( obj=this->objects.begin() ; obj < this->objects.end(); obj++ ){
@@ -113,9 +123,19 @@
 	}
 	else{
+
+		MARSHALLING_DYNAMIC(sorted_ids,int,numsorted);
+		MARSHALLING_DYNAMIC(id_offsets,int,numsorted);
+		if (!(this->sorted && numsorted>0)){
+		 sorted_ids=NULL;
+		 sorted_ids=NULL;
+		}
+
+		MARSHALLING(obj_size);
+
 		/*This is the heart of the demashalling method. We have a buffer coming
 		 in, and we are supposed to create a dataset out of it. No such thing
 		 as class orientation for buffers, we need to key off the enum of each
 		 object stored in the buffer. */
-		for(i=0;i<this->numsorted;i++){
+		for(i=0;i<obj_size;i++){
 
 			/*Recover enum of object first: */
@@ -127,8 +147,9 @@
 			 *stored in the buffer: */
 			if(obj_enum==NodeEnum){
-					Node* node=NULL;
-					node=new Node();
-					node->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
-					this->AddObject(node);
+				Node* node=NULL;
+				node=new Node();
+				node->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
+				this->AddObject(node);
+				break;
 			}
 			else if(obj_enum==VertexEnum){
@@ -153,5 +174,5 @@
 				break;
 			}
-			else _error_("could not recognize enum type: " << obj_enum); 
+			else _error_("could not recognize enum type: " << obj_enum << ": " << EnumToStringx(obj_enum) ); 
 		}
 	}
Index: /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h	(revision 19238)
+++ /issm/trunk-jpl/src/c/shared/io/Marshalling/Marshalling.h	(revision 19239)
@@ -59,14 +59,14 @@
 
 
-#define MARSHALLING_DYNAMIC(FIELD,TYPE,SIZE) \
+#define MARSHALLING_DYNAMIC(FIELDD,TYPE,SIZE) \
 	\
 	{\
 		bool field_null=true;\
-		if (FIELD)field_null=false;\
+		if (FIELDD)field_null=false;\
 		MARSHALLING(field_null);\
 		\
 		if(!field_null){\
 			if(marshall_direction==MARSHALLING_FORWARD){\
-					memcpy(*pmarshalled_data,FIELD,SIZE*sizeof(TYPE));\
+					memcpy(*pmarshalled_data,FIELDD,SIZE*sizeof(TYPE));\
 					*pmarshalled_data+=SIZE*sizeof(TYPE);\
 			}\
@@ -75,6 +75,6 @@
 			}\
 			else if(marshall_direction==MARSHALLING_BACKWARD){\
-				FIELD=xNew<TYPE>(SIZE);\
-				memcpy(FIELD,*pmarshalled_data,SIZE*sizeof(TYPE));\
+				FIELDD=xNew<TYPE>(SIZE);\
+				memcpy(FIELDD,*pmarshalled_data,SIZE*sizeof(TYPE));\
 				*pmarshalled_data+=SIZE*sizeof(TYPE);\
 			}\
