Index: /issm/trunk/src/c/Container/Parameters.cpp
===================================================================
--- /issm/trunk/src/c/Container/Parameters.cpp	(revision 4872)
+++ /issm/trunk/src/c/Container/Parameters.cpp	(revision 4873)
@@ -309,4 +309,30 @@
 }
 /*}}}*/
+/*FUNCTION Parameters::FindParam(FILE** pfid,int enum_type){{{1*/
+int   Parameters::FindParam(FILE** pfid,int enum_type){
+
+	/*Go through a dataset, and find a Param* object 
+	 *which parameter name is "name" : */
+
+	vector<Object*>::iterator object;
+	Param* param=NULL;
+
+	int found=0;
+
+	for ( object=objects.begin() ; object < objects.end(); object++ ){
+
+		/*Ok, this object is a parameter, recover it and ask which name it has: */
+		param=(Param*)(*object);
+
+		if(param->EnumType()==enum_type){
+			/*Ok, this is the one! Recover the value of this parameter: */
+			param->GetParameterValue(pfid);
+			found=1;
+			break;
+		}
+	}
+	return found;
+}
+/*}}}*/
 
 /*FUNCTION Parameters::SetParam(bool boolean,int enum_type);{{{1*/
@@ -418,4 +444,16 @@
 }
 /*}}}*/
+/*FUNCTION Parameters::SetParam(FILE* fid,int enum_type);{{{1*/
+void   Parameters::SetParam(FILE* fid,int enum_type){
+
+	Param* param=NULL;
+
+	/*first, figure out if the param has already been created: */
+	param=(Param*)this->FindParamObject(enum_type);
+
+	if(param) param->SetValue(fid); //already exists, just set it.
+	else this->AddObject(new FileParam(enum_type,fid)); //just add the new parameter.
+}
+/*}}}*/
 
 /*FUNCTION Parameters::FindParamObject{{{1*/
Index: /issm/trunk/src/c/Container/Parameters.h
===================================================================
--- /issm/trunk/src/c/Container/Parameters.h	(revision 4872)
+++ /issm/trunk/src/c/Container/Parameters.h	(revision 4873)
@@ -36,4 +36,5 @@
 		int   FindParam(Vec* pvec,int enum_type);
 		int   FindParam(Mat* pmat,int enum_type);
+		int   FindParam(FILE** pfid,int enum_type);
 		
 		void  SetParam(bool boolean,int enum_type);
@@ -46,4 +47,5 @@
 		void  SetParam(Vec vec,int enum_type);
 		void  SetParam(Mat mat,int enum_type);
+		void  SetParam(FILE* fid,int enum_type);
 
 		Object* FindParamObject(int enum_type);
Index: /issm/trunk/src/c/EnumDefinitions/EnumAsString.cpp
===================================================================
--- /issm/trunk/src/c/EnumDefinitions/EnumAsString.cpp	(revision 4872)
+++ /issm/trunk/src/c/EnumDefinitions/EnumAsString.cpp	(revision 4873)
@@ -121,4 +121,5 @@
 		case DoubleVecParamEnum : return "DoubleVecParam";
 		case IntParamEnum : return "IntParam";
+		case FileParamEnum : return "FileParam";
 		case PetscMatParamEnum : return "PetscMatParam";
 		case PetscVecParamEnum : return "PetscVecParam";
@@ -291,5 +292,5 @@
 		case NumberOfVerticesEnum : return "NumberOfVertices";
 		case OptScalEnum : return "OptScal";
-		case OutputFileNameEnum : return "OutputFileName";
+		case OutputFilePointerEnum : return "OutputFilePointer";
 		case ParameterOutputEnum : return "ParameterOutput";
 		case PenaltyMeltingEnum : return "PenaltyMelting";
Index: /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.h
===================================================================
--- /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.h	(revision 4872)
+++ /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.h	(revision 4873)
@@ -139,4 +139,5 @@
 	DoubleVecParamEnum,
 	IntParamEnum,
+	FileParamEnum,
 	PetscMatParamEnum,
 	PetscVecParamEnum,
@@ -328,5 +329,5 @@
 	NumberOfVerticesEnum,
 	OptScalEnum,
-	OutputFileNameEnum,
+	OutputFilePointerEnum,
 	ParameterOutputEnum,
 	PenaltyMeltingEnum,
Index: /issm/trunk/src/c/EnumDefinitions/StringAsEnum.cpp
===================================================================
--- /issm/trunk/src/c/EnumDefinitions/StringAsEnum.cpp	(revision 4872)
+++ /issm/trunk/src/c/EnumDefinitions/StringAsEnum.cpp	(revision 4873)
@@ -119,4 +119,5 @@
 	else if (strcmp(name,"DoubleVecParam")==0) return DoubleVecParamEnum;
 	else if (strcmp(name,"IntParam")==0) return IntParamEnum;
+	else if (strcmp(name,"FileParam")==0) return FileParamEnum;
 	else if (strcmp(name,"PetscMatParam")==0) return PetscMatParamEnum;
 	else if (strcmp(name,"PetscVecParam")==0) return PetscVecParamEnum;
@@ -289,5 +290,5 @@
 	else if (strcmp(name,"NumberOfVertices")==0) return NumberOfVerticesEnum;
 	else if (strcmp(name,"OptScal")==0) return OptScalEnum;
-	else if (strcmp(name,"OutputFileName")==0) return OutputFileNameEnum;
+	else if (strcmp(name,"OutputFilePointer")==0) return OutputFilePointerEnum;
 	else if (strcmp(name,"ParameterOutput")==0) return ParameterOutputEnum;
 	else if (strcmp(name,"PenaltyMelting")==0) return PenaltyMeltingEnum;
Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 4872)
+++ /issm/trunk/src/c/Makefile.am	(revision 4873)
@@ -188,4 +188,6 @@
 					./objects/Params/DoubleParam.cpp\
 					./objects/Params/DoubleParam.h\
+					./objects/Params/FileParam.cpp\
+					./objects/Params/FileParam.h\
 					./objects/Params/PetscMatParam.cpp\
 					./objects/Params/PetscMatParam.h\
@@ -750,4 +752,6 @@
 					./objects/Params/DoubleParam.cpp\
 					./objects/Params/DoubleParam.h\
+					./objects/Params/FileParam.cpp\
+					./objects/Params/FileParam.h\
 					./objects/Params/PetscMatParam.cpp\
 					./objects/Params/PetscMatParam.h\
Index: /issm/trunk/src/c/io/pfclose.cpp
===================================================================
--- /issm/trunk/src/c/io/pfclose.cpp	(revision 4872)
+++ /issm/trunk/src/c/io/pfclose.cpp	(revision 4873)
@@ -21,3 +21,2 @@
 	}
 }
-
Index: /issm/trunk/src/c/modules/ModelProcessorx/BedSlope/UpdateElementsBedSlope.cpp
===================================================================
--- /issm/trunk/src/c/modules/ModelProcessorx/BedSlope/UpdateElementsBedSlope.cpp	(revision 4872)
+++ /issm/trunk/src/c/modules/ModelProcessorx/BedSlope/UpdateElementsBedSlope.cpp	(revision 4873)
@@ -47,3 +47,4 @@
 	xfree((void**)&iomodel->elementonwater);
 	xfree((void**)&iomodel->elementonbed);
+	xfree((void**)&iomodel->elementonsurface);
 }
Index: /issm/trunk/src/c/modules/OutputResultsx/ElementResultsToPatch.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/ElementResultsToPatch.cpp	(revision 4872)
+++ /issm/trunk/src/c/modules/OutputResultsx/ElementResultsToPatch.cpp	(revision 4873)
@@ -15,5 +15,5 @@
 #include "../../objects/objects.h"
 		
-void ElementResultsToPatch(Elements* elements,  Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet* results){
+void ElementResultsToPatch(Elements* elements,  Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet* results,int step, double time){
 
 	int i;
@@ -96,8 +96,10 @@
 	patch->MPI_Gather();
 
-	/*create result object and add to results dataset: */
-	results->AddObject(new       IntExternalResult(results->Size()+1,PatchVerticesEnum,patch->maxvertices,1,0));
-	results->AddObject(new       IntExternalResult(results->Size()+1,PatchNodesEnum,   patch->maxnodes,1,0));
-	results->AddObject(new DoubleMatExternalResult(results->Size()+1,PatchEnum,patch->values,patch->numrows,patch->numcols,1,0));
+	/*create result object and add to results dataset (if not empty): */
+	if (patch->maxvertices && patch->maxnodes){
+		results->AddObject(new       IntExternalResult(results->Size()+1,PatchVerticesEnum,patch->maxvertices,step,time));
+		results->AddObject(new       IntExternalResult(results->Size()+1,PatchNodesEnum,   patch->maxnodes,step,time));
+		results->AddObject(new DoubleMatExternalResult(results->Size()+1,PatchEnum,patch->values,patch->numrows,patch->numcols,step,time));
+	}
 
 	/*Free ressources:*/
Index: /issm/trunk/src/c/modules/OutputResultsx/FileWriteResults.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/FileWriteResults.cpp	(revision 4872)
+++ /issm/trunk/src/c/modules/OutputResultsx/FileWriteResults.cpp	(revision 4873)
@@ -18,12 +18,8 @@
 	int         i;
 	extern int  my_rank;
-	char       *filename     = NULL;
 	FILE       *fid          = NULL;
 
 	//Recover file name: 
-	parameters->FindParam(&filename,OutputFileNameEnum);
-
-	//Open filename for writing only on cpu 0
-	if(my_rank==0)fid=pfopen(filename,"wb");
+	parameters->FindParam(&fid,OutputFilePointerEnum);
 
 	for(i=0;i<results->Size();i++){
@@ -33,9 +29,3 @@
 		result->WriteData(fid);
 	}
-
-	/*Close file: */
-	if(my_rank==0) pfclose(fid,filename);
-
-	/*Free ressources:*/
-	xfree((void**)&filename);
 }
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 4872)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 4873)
@@ -17,13 +17,20 @@
 		
 #ifdef _SERIAL_
-void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet* results){
-#else
-void OutputResultsx(                    Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet* results){
+void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet** presults, int step, double time){
+#else                                                                                                                                                                                             
+void OutputResultsx(                    Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet** presults, int step, double time){
 #endif
 
-	int  solutiontype;
+	/*Intermediaries*/
+	int      i;
+	int      solutiontype;
+	DataSet *results;
+	Element *element;
+
+	/*Recover results*/
+	results=*presults;
 	
 	/*Transfer element results into the femmodel->results dataset: */
-	ElementResultsToPatch( elements,  nodes,  vertices,  loads, materials, parameters,results);
+	ElementResultsToPatch( elements,  nodes,  vertices,  loads, materials, parameters,results,step,time);
 
 	#ifdef _PARALLEL_
@@ -36,7 +43,25 @@
 	/*Write data to matlab structure or filename: */
 	#ifdef _SERIAL_
+		/*Write Matlab structure*/
 		MatlabWriteResults(pdataref,parameters,results);
+
+		/*DO NOT delete results serially*/
 	#else
+		/*Write File*/
 		FileWriteResults(parameters,results);
+
+		/*Now delete results (ElementResults and ExternalResults)*/
+		delete results;
+		for (i=0;i<elements->Size();i++){
+			element=(Element*)elements->GetObjectByOffset(i);
+			element->DeleteResults();
+		}
 	#endif
+
+
+
+	/*We have to reinitialize results for next step*/
+	results=new DataSet();
+	*presults=results;
+
 }
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 4872)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 4873)
@@ -16,13 +16,13 @@
 #ifdef _SERIAL_
 #include <mex.h>
-void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters,DataSet* results);
+void OutputResultsx(mxArray** pdataref, Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters,DataSet** results,int step=0,double time=0);
 void MatlabWriteResults(mxArray** pdataref, Parameters* parameters, DataSet* results);
 #else
-void OutputResultsx(Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters,DataSet* results);
+void OutputResultsx(Elements* elements, Nodes* nodes, Vertices* vertices, Loads* loads,  Materials* materials, Parameters* parameters,DataSet** results,int step=0,double time=0);
 void FileWriteResults(Parameters* parameters, DataSet* results);
 #endif
 
 /* local prototypes: */
-void ElementResultsToPatch(Elements* elements,  Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet* results);
+void ElementResultsToPatch(Elements* elements,  Nodes* nodes, Vertices* vertices, Loads* loads, Materials* materials, Parameters* parameters,DataSet* results,int step, double time);
 
 #endif  /* _OUTPUTRESULTS_H */
Index: /issm/trunk/src/c/objects/Elements/Beam.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Beam.cpp	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Beam.cpp	(revision 4873)
@@ -284,4 +284,11 @@
 		ISSMERROR("analysis %i (%s) not supported yet",analysis_type,EnumAsString(analysis_type));
 	}
+
+}
+/*}}}*/
+/*FUNCTION Beam::DeleteResults {{{1*/
+void  Beam::DeleteResults(void){
+
+	ISSMERROR("not implemented yet");
 
 }
Index: /issm/trunk/src/c/objects/Elements/Beam.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Beam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Beam.h	(revision 4873)
@@ -70,5 +70,5 @@
 		void	   CreateKMatrix(Mat Kgg);
 		void	   CreatePVector(Vec pg);
-		void	   Du(Vec du_g);
+		void   DeleteResults(void);
 		void	   GetBedList(double* bed_list);
 		void*	   GetMatPar();
Index: /issm/trunk/src/c/objects/Elements/Element.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Element.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Element.h	(revision 4873)
@@ -50,4 +50,5 @@
 		virtual void   PatchSize(int* pnumrows, int* pnumvertices,int* pnumnodes)=0;
 		virtual void   PatchFill(int* pcount, Patch* patch)=0;
+		virtual void   DeleteResults(void)=0;
 		virtual void   Update(int index, IoModel* iomodel,int analysis_counter,int analysis_type)=0;
 		virtual void   UpdateGeometry(void)=0;
Index: /issm/trunk/src/c/objects/Elements/Penta.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Penta.cpp	(revision 4873)
@@ -828,4 +828,13 @@
 	}
 	else ISSMERROR("analysis %i (%s) not supported yet",analysis_type,EnumAsString(analysis_type));
+
+}
+/*}}}*/
+/*FUNCTION Penta::DeleteResults {{{1*/
+void  Penta::DeleteResults(void){
+
+	/*Delete and reinitialize results*/
+	delete this->results;
+	this->results=new Results();
 
 }
Index: /issm/trunk/src/c/objects/Elements/Penta.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Penta.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Penta.h	(revision 4873)
@@ -73,4 +73,5 @@
 		void   CreateKMatrix(Mat Kgg);
 		void   CreatePVector(Vec pg);
+		void   DeleteResults(void);
 		void   GetBedList(double* bed_list);
 		void*  GetMatPar();
Index: /issm/trunk/src/c/objects/Elements/Sing.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Sing.cpp	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Sing.cpp	(revision 4873)
@@ -255,4 +255,11 @@
 		ISSMERROR("analysis %i (%s) not supported yet",analysis_type,EnumAsString(analysis_type));
 	}
+
+}
+/*}}}*/
+/*FUNCTION Sing::DeleteResults {{{1*/
+void  Sing::DeleteResults(void){
+
+	ISSMERROR("not implemented yet");
 
 }
Index: /issm/trunk/src/c/objects/Elements/Sing.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Sing.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Sing.h	(revision 4873)
@@ -70,5 +70,5 @@
 		void   CreateKMatrix(Mat Kgg);
 		void   CreatePVector(Vec pg);
-		void   Du(Vec du_g);
+		void   DeleteResults(void);
 		void   GetBedList(double* bed_list);
 		void*  GetMatPar();
Index: /issm/trunk/src/c/objects/Elements/Tria.cpp
===================================================================
--- /issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Tria.cpp	(revision 4873)
@@ -747,4 +747,13 @@
 		ISSMERROR("analysis %i (%s) not supported yet",analysis_type,EnumAsString(analysis_type));
 	}
+
+}
+/*}}}*/
+/*FUNCTION Tria::DeleteResults {{{1*/
+void  Tria::DeleteResults(void){
+
+	/*Delete and reinitialize results*/
+	delete this->results;
+	this->results=new Results();
 
 }
Index: /issm/trunk/src/c/objects/Elements/Tria.h
===================================================================
--- /issm/trunk/src/c/objects/Elements/Tria.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Elements/Tria.h	(revision 4873)
@@ -28,11 +28,11 @@
 		int  id;
 
-		Node** nodes; // 3 nodes
-		Matice* matice;  // 1 material ice
-		Matpar* matpar;  // 1 material parameter
- 
-		Parameters* parameters; //pointer to solution parameters
-		Inputs*  inputs;
-		Results*  results; 
+		Node   **nodes;    // 3 nodes
+		Matice  *matice;   // 1 material ice
+		Matpar  *matpar;   // 1 material parameter
+
+		Parameters *parameters;   //pointer to solution parameters
+		Inputs     *inputs;
+		Results    *results;
 
 		/*Tria constructors, destructors {{{1*/
@@ -88,4 +88,5 @@
 		void   InputScale(int enum_type,double scale_factor);
 		void   InputToResult(int enum_type,int step,double time);
+		void   DeleteResults(void);
 		void   MaterialUpdateFromTemperature(void){ISSMERROR("not implemented yet");};
 		double MassFlux(double* segment);
Index: /issm/trunk/src/c/objects/Params/BoolParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/BoolParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/BoolParam.h	(revision 4873)
@@ -63,4 +63,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("Bool param of enum %i (%s) cannot return a Vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* pmat){ISSMERROR("Bool param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
+		void  GetParameterValue(FILE** pfid){ISSMERROR("Bool param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){this->value=boolean;}
@@ -73,6 +74,6 @@
 		void  SetValue(Vec vec){ISSMERROR("Bool param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat){ISSMERROR("Bool param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("Bool param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("Bool param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
-
 		
 		char* GetParameterName(void);
Index: /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/DoubleMatArrayParam.h	(revision 4873)
@@ -66,4 +66,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("DoubleMatArray param of enum %i (%s) cannot return a Vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* pmat){ISSMERROR("DoubleMatArray param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
+		void  GetParameterValue(FILE** pfid){ISSMERROR("DoubleMatArray param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){ISSMERROR("DoubleMatArray param of enum %i (%s) cannot hold a boolean",enum_type,EnumAsString(enum_type));}
@@ -76,4 +77,5 @@
 		void  SetValue(Vec vec){ISSMERROR("DoubleMatArray param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat){ISSMERROR("DoubleMatArray param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("Bool param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array);
 
Index: /issm/trunk/src/c/objects/Params/DoubleMatParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleMatParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/DoubleMatParam.h	(revision 4873)
@@ -65,4 +65,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("DoubleMat param of enum %i (%s) cannot return a Vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* pmat){ISSMERROR("DoubleMat param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
+		void  GetParameterValue(FILE** pfid){ISSMERROR("DoubleMat param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){ISSMERROR("DoubleMat param of enum %i (%s) cannot hold a boolean",enum_type,EnumAsString(enum_type));}
@@ -75,4 +76,5 @@
 		void  SetValue(Vec vec){ISSMERROR("DoubleMat param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat){ISSMERROR("DoubleMat param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("DoubleMat param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("DoubleMat param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
 
Index: /issm/trunk/src/c/objects/Params/DoubleParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/DoubleParam.h	(revision 4873)
@@ -64,4 +64,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("Double param of enum %i (%s) cannot return a Vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* pmat){ISSMERROR("Double param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
+		void  GetParameterValue(FILE** pfid){ISSMERROR("Double param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){this->value=(double)boolean;}
@@ -74,4 +75,5 @@
 		void  SetValue(Vec vec){ISSMERROR("Double param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat){ISSMERROR("Double param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("Double param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("Double param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
 
Index: /issm/trunk/src/c/objects/Params/DoubleVecParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/DoubleVecParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/DoubleVecParam.h	(revision 4873)
@@ -64,4 +64,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("DoubleVec param of enum %i (%s) cannot return a Vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* pmat){ISSMERROR("DoubleVec param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
+		void  GetParameterValue(FILE** pfid){ISSMERROR("DoubleVec param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){ISSMERROR("DoubleVec param of enum %i (%s) cannot hold a boolean",enum_type,EnumAsString(enum_type));}
@@ -74,4 +75,5 @@
 		void  SetValue(Vec vec){ISSMERROR("DoubleVec param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat){ISSMERROR("DoubleVec param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("DoubleVec param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("DoubleVec param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
 		
Index: /issm/trunk/src/c/objects/Params/IntParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/IntParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/IntParam.h	(revision 4873)
@@ -63,4 +63,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("Int param of enum %i (%s) cannot return a Vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* pmat){ISSMERROR("Int param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
+		void  GetParameterValue(FILE** pfid){ISSMERROR("Int param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){this->value=(int)boolean;}
@@ -73,4 +74,5 @@
 		void  SetValue(Vec vec){ISSMERROR("Int param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat){ISSMERROR("Int param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("Int param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("Int param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
 
Index: /issm/trunk/src/c/objects/Params/Param.h
===================================================================
--- /issm/trunk/src/c/objects/Params/Param.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/Param.h	(revision 4873)
@@ -42,4 +42,5 @@
 		virtual void  GetParameterValue(Vec* pvec)=0;
 		virtual void  GetParameterValue(Mat* pmat)=0;
+		virtual void  GetParameterValue(FILE** pfid)=0;
 		
 		virtual void  SetValue(bool boolean)=0;
@@ -52,4 +53,5 @@
 		virtual void  SetValue(Vec vec)=0;
 		virtual void  SetValue(Mat mat)=0;
+		virtual void  SetValue(FILE* fid)=0;
 		virtual void  SetValue(double** array, int M, int* mdim_array, int* ndim_array)=0;
 
Index: /issm/trunk/src/c/objects/Params/PetscMatParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/PetscMatParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/PetscMatParam.h	(revision 4873)
@@ -64,4 +64,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("PetscMat param of enum %i (%s) cannot return a vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* poutput);
+		void  GetParameterValue(FILE** pfid){ISSMERROR("PetscMat param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){ISSMERROR("PetscMat param of enum %i (%s) cannot hold a boolean",enum_type,EnumAsString(enum_type));}
@@ -74,4 +75,5 @@
 		void  SetValue(Vec vec){ISSMERROR("PetscMat param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat);
+		void  SetValue(FILE* fid){ISSMERROR("PetscMat param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("PetscMat param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
 
Index: /issm/trunk/src/c/objects/Params/PetscVecParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/PetscVecParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/PetscVecParam.h	(revision 4873)
@@ -64,14 +64,16 @@
 		void  GetParameterValue(Mat* pmat){ISSMERROR("PetscVec param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Vec* poutput);
+		void  GetParameterValue(FILE** pfid){ISSMERROR("PetscVec of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
-		void  SetValue(bool boolean){ISSMERROR("PetscVec param of enum %i (%s) cannot hold a boolean",enum_type,EnumAsString(enum_type));}
-		void  SetValue(int integer){ISSMERROR("PetscVec param of enum %i (%s) cannot hold an integer",enum_type,EnumAsString(enum_type));}
-		void  SetValue(double scalar){ISSMERROR("PetscVec param of enum %i (%s) cannot hold a scalar",enum_type,EnumAsString(enum_type));}
-		void  SetValue(char* string){ISSMERROR("PetscVec param of enum %i (%s) cannot hold a string",enum_type,EnumAsString(enum_type));}
-		void  SetValue(char** stringarray,int M){ISSMERROR("PetscVec param of enum %i (%s) cannot hold a string array",enum_type,EnumAsString(enum_type));}
-		void  SetValue(double* doublearray,int M){ISSMERROR("PetscVec param of enum %i (%s) cannot hold a double array",enum_type,EnumAsString(enum_type));}
-		void  SetValue(double* pdoublearray,int M,int N){ISSMERROR("PetscVec param of enum %i (%s) cannot hold a double array",enum_type,EnumAsString(enum_type));}
+		void  SetValue(bool boolean){ISSMERROR("PetscVec of enum %i (%s) cannot hold a boolean",enum_type,EnumAsString(enum_type));}
+		void  SetValue(int integer){ISSMERROR("PetscVec of enum %i (%s) cannot hold an integer",enum_type,EnumAsString(enum_type));}
+		void  SetValue(double scalar){ISSMERROR("PetscVec of enum %i (%s) cannot hold a scalar",enum_type,EnumAsString(enum_type));}
+		void  SetValue(char* string){ISSMERROR("PetscVec of enum %i (%s) cannot hold a string",enum_type,EnumAsString(enum_type));}
+		void  SetValue(char** stringarray,int M){ISSMERROR("PetscVec of enum %i (%s) cannot hold a string array",enum_type,EnumAsString(enum_type));}
+		void  SetValue(double* doublearray,int M){ISSMERROR("PetscVec of enum %i (%s) cannot hold a double array",enum_type,EnumAsString(enum_type));}
+		void  SetValue(double* pdoublearray,int M,int N){ISSMERROR("PetscVec of enum %i (%s) cannot hold a double array",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Vec vec);
-		void  SetValue(Mat mat){ISSMERROR("PetscVec param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(Mat mat){ISSMERROR("PetscVec of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("PetscVec of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("PetscVec param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
 
Index: /issm/trunk/src/c/objects/Params/StringArrayParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/StringArrayParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/StringArrayParam.h	(revision 4873)
@@ -66,4 +66,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("StringArray param of enum %i (%s) cannot return a Vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* pmat){ISSMERROR("StringArray param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
+		void  GetParameterValue(FILE** pfid){ISSMERROR("StringArray param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){ISSMERROR("StringArray param of enum %i (%s) cannot hold a boolean",enum_type,EnumAsString(enum_type));}
@@ -76,4 +77,5 @@
 		void  SetValue(Vec vec){ISSMERROR("StringArray param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat){ISSMERROR("StringArray param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("StringArray param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("StringArray param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
 
Index: /issm/trunk/src/c/objects/Params/StringParam.h
===================================================================
--- /issm/trunk/src/c/objects/Params/StringParam.h	(revision 4872)
+++ /issm/trunk/src/c/objects/Params/StringParam.h	(revision 4873)
@@ -64,4 +64,5 @@
 		void  GetParameterValue(Vec* pvec){ISSMERROR("String param of enum %i (%s) cannot return a Vec",enum_type,EnumAsString(enum_type));}
 		void  GetParameterValue(Mat* pmat){ISSMERROR("String param of enum %i (%s) cannot return a Mat",enum_type,EnumAsString(enum_type));}
+		void  GetParameterValue(FILE** pfid){ISSMERROR("Bool param of enum %i (%s) cannot return a FILE",enum_type,EnumAsString(enum_type));}
 
 		void  SetValue(bool boolean){ISSMERROR("String param of enum %i (%s) cannot hold a boolean",enum_type,EnumAsString(enum_type));}
@@ -74,4 +75,5 @@
 		void  SetValue(Vec vec){ISSMERROR("String param of enum %i (%s) cannot hold a Vec",enum_type,EnumAsString(enum_type));}
 		void  SetValue(Mat mat){ISSMERROR("String param of enum %i (%s) cannot hold a Mat",enum_type,EnumAsString(enum_type));}
+		void  SetValue(FILE* fid){ISSMERROR("String param of enum %i (%s) cannot hold a FILE",enum_type,EnumAsString(enum_type));}
 		void  SetValue(double** array, int M, int* mdim_array, int* ndim_array){ISSMERROR("String param of enum %i (%s) cannot hold an array of matrices",enum_type,EnumAsString(enum_type));}
 
Index: /issm/trunk/src/c/objects/Patch.cpp
===================================================================
--- /issm/trunk/src/c/objects/Patch.cpp	(revision 4872)
+++ /issm/trunk/src/c/objects/Patch.cpp	(revision 4873)
@@ -125,8 +125,10 @@
 	#endif
 	
-	
 	/*First, figure out total number of rows combining all the cpus: */
 	MPI_Reduce(&this->numrows,&total_numrows,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD );
 	MPI_Bcast(&total_numrows,1,MPI_INT,0,MPI_COMM_WORLD);
+
+	/*return if patch empty*/
+	if(total_numrows==0) return;
 
 	/*Now, allocate buffer to holds all the values, on node 0: */
Index: /issm/trunk/src/c/objects/objects.h
===================================================================
--- /issm/trunk/src/c/objects/objects.h	(revision 4872)
+++ /issm/trunk/src/c/objects/objects.h	(revision 4873)
@@ -83,4 +83,5 @@
 #include "./Params/DoubleVecParam.h"
 #include "./Params/IntParam.h"
+#include "./Params/FileParam.h"
 #include "./Params/Param.h"
 #include "./Params/PetscMatParam.h"
Index: /issm/trunk/src/c/solutions/controlrestart.cpp
===================================================================
--- /issm/trunk/src/c/solutions/controlrestart.cpp	(revision 4872)
+++ /issm/trunk/src/c/solutions/controlrestart.cpp	(revision 4873)
@@ -22,5 +22,5 @@
 
 	/*write to disk: */
-	OutputResultsx(femmodel->elements, femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,femmodel->results);
+	OutputResultsx(femmodel->elements, femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,&femmodel->results);
 
 }
Index: /issm/trunk/src/c/solutions/issm.cpp
===================================================================
--- /issm/trunk/src/c/solutions/issm.cpp	(revision 4872)
+++ /issm/trunk/src/c/solutions/issm.cpp	(revision 4873)
@@ -12,5 +12,6 @@
 
 	/*I/O: */
-	FILE     *fid              = NULL;
+	FILE     *input_fid        = NULL;
+	FILE     *output_fid       = NULL;
 	char     *inputfilename    = NULL;
 	char     *outputfilename   = NULL;
@@ -48,5 +49,5 @@
 	MPI_Comm_size(MPI_COMM_WORLD,&num_procs); 
 
-	_printf_("recover input and output file names:\n");
+	_printf_("recover solution and file names:\n");
 	solution_type=StringAsEnum(argv[1]);
 	inputfilename=argv[3];
@@ -60,12 +61,14 @@
 	SolutionConfiguration(&analyses,&numanalyses,&solutioncore,solution_type);
 
-	/*Open handle to data on disk: */
-	fid=pfopen(inputfilename,"rb");
+	/*Open input file to process model
+	 * and ouput file to start unload results*/
+	input_fid =pfopen(inputfilename ,"rb");
+	output_fid=pfopen(outputfilename,"wb");
 
 	_printf_("create finite element model:\n");
-	femmodel=new FemModel(fid,solution_type,analyses,numanalyses);
+	femmodel=new FemModel(input_fid,solution_type,analyses,numanalyses);
 
-	/*add outputfilename in parameters: */
-	femmodel->parameters->AddObject(new StringParam(OutputFileNameEnum,outputfilename));
+	/*add output_fid to parameters: */
+	femmodel->parameters->SetParam(output_fid,OutputFilePointerEnum);
 	
 	/*get parameters: */
@@ -96,5 +99,5 @@
 
 		_printf_("write results to disk:\n");
-		OutputResultsx(femmodel->elements, femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,femmodel->results);
+		OutputResultsx(femmodel->elements, femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,&femmodel->results);
 	}
 	else{
@@ -111,4 +114,6 @@
 	}
 
+	/*Close output file and write lock file if requested*/
+	pfclose(output_fid,outputfilename);
 	if (waitonlock>0){
 		_printf_("write lock file:\n");
Index: /issm/trunk/src/c/solutions/transient2d_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/transient2d_core.cpp	(revision 4872)
+++ /issm/trunk/src/c/solutions/transient2d_core.cpp	(revision 4873)
@@ -62,4 +62,8 @@
 			InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,SurfaceEnum,step,time);
 			InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,BedEnum,step,time);
+
+			/*unload results*/
+			if(verbose)_printf_("%s","      saving temporary results...");
+			OutputResultsx(femmodel->elements, femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,&femmodel->results,step,time);
 		}
 	}
Index: /issm/trunk/src/c/solutions/transient3d_core.cpp
===================================================================
--- /issm/trunk/src/c/solutions/transient3d_core.cpp	(revision 4872)
+++ /issm/trunk/src/c/solutions/transient3d_core.cpp	(revision 4873)
@@ -77,9 +77,8 @@
 			InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,TemperatureEnum,step,time);
 			InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,MeltingRateEnum,step,time);
-		}
 
-		if (step%5==0){
+			/*unload results*/
 			if(verbose)_printf_("%s","      saving temporary results...");
-			OutputResultsx(femmodel->elements, femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,femmodel->results);
+			OutputResultsx(femmodel->elements, femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,&femmodel->results,step,time);
 		}
 	}
Index: /issm/trunk/src/m/classes/public/display/displaymesh.m
===================================================================
--- /issm/trunk/src/m/classes/public/display/displaymesh.m	(revision 4872)
+++ /issm/trunk/src/m/classes/public/display/displaymesh.m	(revision 4873)
@@ -36,8 +36,7 @@
 
 disp(sprintf('\n      Properties:'));
-fielddisplay(md,'type','mesh type');
+fielddisplay(md,'dim','mesh dimension (2d or 3d)');
 fielddisplay(md,'numlayers','number of extrusion layers');
 fielddisplay(md,'extrusionexponent','exponent for extrusion');
-fielddisplay(md,'dof','maximum number of dofs solved');
 fielddisplay(md,'bamg','Geometry and 2d mesh properties (if generated by Bamg)');
 fielddisplay(md,'penalties','penalties list');
Index: /issm/trunk/src/m/classes/public/display/fielddisplay.m
===================================================================
--- /issm/trunk/src/m/classes/public/display/fielddisplay.m	(revision 4872)
+++ /issm/trunk/src/m/classes/public/display/fielddisplay.m	(revision 4873)
@@ -47,5 +47,6 @@
 
 	else
-		error('displayline error message: type not supported yet');
+		displayunit(offset,name,'not displayed',comment),
+
 	end
 end %function
Index: /issm/trunk/src/m/solutions/MatlabProcessPatch.m
===================================================================
--- /issm/trunk/src/m/solutions/MatlabProcessPatch.m	(revision 4872)
+++ /issm/trunk/src/m/solutions/MatlabProcessPatch.m	(revision 4873)
@@ -5,43 +5,51 @@
 %      Result=ProcessPatch(Result);
 
-%Get out if no Patch
+%return if there is no fiel Patch
 if (~isfield(structure,'Patch')),
 	return;
-else
-	Patch=structure(1).Patch;
-	numvertices=structure(1).PatchVertices;
 end
 
-%Get number of fields;
-fields=unique(Patch(:,1));
-steps=unique(Patch(:,2));
+%loop over steps
+for i=1:length(structure),
 
-%parse steps
-for j=1:length(steps),
+	%Get Patch for current step
+	Patch=structure(i).Patch;
+	numvertices=structure(i).PatchVertices;
 
-	posstep=find(Patch(:,2)==steps(j));
-	
-	%Take all the lines of the Patch for this timestep
-	temporarypatch=Patch(posstep,:);
-	time=temporarypatch(1,3);
-	step=temporarypatch(1,2);
+	%check that Patch is not empty
+	if length(Patch)==0 continue; end
 
-	%parse fields
-	for i=1:length(fields),
+	%Get number of fields;
+	fields=unique(Patch(:,1));
+	steps=unique(Patch(:,2));
 
-		%get name
-		fieldname=EnumAsString(fields(i));
+	%parse steps
+	for j=1:length(steps),
 
-		%get line positions
-		pos=find(temporarypatch(:,1)==fields(i));
+		posstep=find(Patch(:,2)==steps(j));
 
-		%Fill Result structure
-		structure(step).steps=step;
-		structure(step).time=time;
-		structure(step).(fieldname).element=temporarypatch(pos,4);
-		structure(step).(fieldname).interpolation=temporarypatch(pos,5);
-		structure(step).(fieldname).index=temporarypatch(pos,6:5+numvertices);
-		structure(step).(fieldname).value=temporarypatch(pos,6+numvertices:end);
+		%Take all the lines of the Patch for this timestep
+		temporarypatch=Patch(posstep,:);
+		time=temporarypatch(1,3);
+		step=temporarypatch(1,2);
 
+		%parse fields
+		for i=1:length(fields),
+
+			%get name
+			fieldname=EnumAsString(fields(i));
+
+			%get line positions
+			pos=find(temporarypatch(:,1)==fields(i));
+
+			%Fill Result structure
+			structure(step).steps=step;
+			structure(step).time=time;
+			structure(step).(fieldname).element=temporarypatch(pos,4);
+			structure(step).(fieldname).interpolation=temporarypatch(pos,5);
+			structure(step).(fieldname).index=temporarypatch(pos,6:5+numvertices);
+			structure(step).(fieldname).value=temporarypatch(pos,6+numvertices:end);
+
+		end
 	end
 end
Index: /issm/trunk/src/mex/OutputResults/OutputResults.cpp
===================================================================
--- /issm/trunk/src/mex/OutputResults/OutputResults.cpp	(revision 4872)
+++ /issm/trunk/src/mex/OutputResults/OutputResults.cpp	(revision 4873)
@@ -43,5 +43,5 @@
 
 	/*Call "x" code layer: */
-	OutputResultsx(&dataref, elements,nodes,vertices,loads,materials,parameters,results);
+	OutputResultsx(&dataref, elements,nodes,vertices,loads,materials,parameters,&results);
 
 	/*write output datasets: */
