Index: /issm/trunk/src/c/Makefile.am
===================================================================
--- /issm/trunk/src/c/Makefile.am	(revision 4138)
+++ /issm/trunk/src/c/Makefile.am	(revision 4139)
@@ -382,4 +382,7 @@
 					./modules/NodesDofx/NodesDofx.h\
 					./modules/NodesDofx/NodesDofx.cpp\
+					./modules/OutputResultsx/OutputResultsx.h\
+					./modules/OutputResultsx/OutputResultsx.cpp\
+					./modules/OutputResultsx/ElementResultsToPatch.cpp\
 					./modules/Dux/Dux.h\
 					./modules/Dux/Dux.cpp\
@@ -905,4 +908,5 @@
 					./modules/OutputResultsx/OutputResultsx.h\
 					./modules/OutputResultsx/OutputResultsx.cpp\
+					./modules/OutputResultsx/ElementResultsToPatch.cpp\
 					./modules/Dux/Dux.h\
 					./modules/Dux/Dux.cpp\
Index: /issm/trunk/src/c/modules/OutputResultsx/ElementResultsToPatch.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/ElementResultsToPatch.cpp	(revision 4139)
+++ /issm/trunk/src/c/modules/OutputResultsx/ElementResultsToPatch.cpp	(revision 4139)
@@ -0,0 +1,102 @@
+/*!\file:  ElementResultsToPatch
+ * \brief: go through our finite elements, and see what results they have stored within. 
+ * Then output them into serialized patch arrays, and add to results dataset
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "stdio.h"
+#include "../../DataSet/DataSet.h"
+#include "../../io/io.h"
+#include "../../objects/objects.h"
+		
+void ElementResultsToPatch(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters,DataSet* results){
+
+	int i;
+
+	/*output: */
+	Patch* patch=NULL;
+
+	/*intermediary: */
+	int count;
+	int numrows;
+	int numvertices;
+	int numnodes;
+	int max_numvertices;
+	int max_numnodes;
+	int element_numvertices;
+	int element_numrows;
+	int element_numnodes;
+
+	//Process results to be output in the correct units
+	for(i=0;i<elements->Size();i++){
+		Element* element=(Element*)elements->GetObjectByOffset(i);
+		element->ProcessResultsUnits();
+	}
+
+	/*We are going to extract from the results within the elements, the desired results , and create a table 
+	 * of patch information, that will hold, for each element that computed the result that 
+	 * we desire, the enum_type of the result, the step and time, the id of the element, the interpolation type, the vertices ids, and the values 
+	 * at the nodes (could be different from the vertices). This will be used for visualization purposes. 
+	 * For example, we could build the following patch table, for velocities: 
+	 * 
+	 * VxEnum 1  .5  1 P0  1 2       4.5 NaN  NaN //on a Beam element, Vx, at step 1, time .5, element id 1, interpolation type P0 (constant value on a beam element), vertices ids 1 and 2, one constant value 4.5
+	 * VzEnum 2  .8  2 P1  1 3 4     4.5 3.2  2.5 //on a Tria element, Vz, at step 2, time .8, element id 2, interpolation type P1  (linear values on a tria element), vertices ids 1 3 and 4, with values at 3 nodes 4.5, 3.2, 2.5
+	 * ... etc ...
+	 *
+	 * So what do we need to build the table: the maximum number of vertices included in the table, 
+	 * and the maximum number of nodal values, as well as the number of rows. Once we have that, 
+	 * we ask the elements to fill their own row in the table, by looping on the elememnts. 
+	 *
+	 * We will use the Patch object, which will store all of the information needed, and will be able 
+	 * to output itself to disk on its own. See object/Patch.h for format of this object.*/
+	
+	/*First, determine maximum number of vertices, nodes, and number of results: */
+	numrows=0;
+	numvertices=0;
+	numnodes=0;
+
+	for(i=0;i<elements->Size();i++){
+		Element* element=(Element*)elements->GetObjectByOffset(i);
+		element->PatchSize(&element_numrows,&element_numvertices,&element_numnodes);
+
+		numrows+=element_numrows;
+		if(element_numvertices>numvertices)numvertices=element_numvertices;
+		if(element_numnodes>numnodes)numnodes=element_numnodes;
+	}
+
+	#ifdef _PARALLEL_
+	/*Synchronize across cluster, so as to not end up with different sizes for each patch on each cpu: */
+	MPI_Reduce (&numvertices,&max_numvertices,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
+	MPI_Bcast(&max_numvertices,1,MPI_INT,0,MPI_COMM_WORLD);
+	numvertices=max_numvertices;
+
+	MPI_Reduce (&numnodes,&max_numnodes,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
+	MPI_Bcast(&max_numnodes,1,MPI_INT,0,MPI_COMM_WORLD);
+	numnodes=max_numnodes;
+	#endif
+
+	/*Ok, initialize Patch object: */
+	patch=new Patch(numrows,numvertices,numnodes);
+
+	/*Now, go through elements, and fill the Patch object: */
+	count=0;
+	for(i=0;i<elements->Size();i++){
+		Element* element=(Element*)elements->GetObjectByOffset(i);
+		element->PatchFill(&count,patch);
+	}
+
+	/*Now, gather patch onto node 0, so that we do not dump to disk from every node: */
+	patch->MPI_Gather();
+
+	/*create Result object and add to results dataset: */
+	results->AddObject(new DoubleMatExternalResult(results->Size()+1,PatchEnum,patch->numrows,patch->numcols,1,0));
+
+	/*Free ressources:*/
+	delete patch;
+
+}
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 4138)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 4139)
@@ -1,3 +1,3 @@
-/*!\file:  OutputResults.cpp
+/*!\file:  OutputResultsx.cpp
  * \brief: go through our finite elements, and see what results they have stored within. 
  * Then output them into serialized patch arrays, and dump to disk.
@@ -15,96 +15,42 @@
 #include "../../objects/objects.h"
 		
-void OutputResults(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters){
+void OutputResultsx(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters,DataSet* results){
 
-	int i;
-
-	Patch* patch=NULL;
-	char*  filename=NULL;
-
-	int solutiontype;
-	int count;
-	int numrows;
-	int numvertices;
-	int numnodes;
-	int max_numvertices;
-	int max_numnodes;
-	int element_numvertices;
-	int element_numrows;
-	int element_numnodes;
+	int         i;
+	extern int  my_rank;
+	char       *filename     = NULL;
+	int         solutiontype;
+	FILE       *fid          = NULL;
 
 	/*First, configure elements*/
 	elements->Configure(elements,loads, nodes,vertices, materials,parameters);
 
-	//Recover solutiontype which will be output to disk: 
+	/*Transfer element results into the femmodel->results dataset: */
+	ElementResultsToPatch( elements,  loads,  nodes,  vertices,  materials, parameters,results);
+
+	#ifdef _PARALLEL_
+	/*Results do not include the type of solution being run	. In parallel, we output results to a filename, 
+	 *therefore, we need to include the solutiontype into the filename: */
 	parameters->FindParam(&solutiontype,SolutionTypeEnum);
+	results->AddObject(new StringExternalResult(results->Size()+1,SolutionTypeEnum,EnumAsString(solutiontype),1,0));
+	#endif
+
+	//Recover file name: 
 	parameters->FindParam(&filename,OutputFileNameEnum);
 
-	//Process results to be output in the correct units
-	for(i=0;i<elements->Size();i++){
-		Element* element=(Element*)elements->GetObjectByOffset(i);
-		element->ProcessResultsUnits();
+	//Open filename for writing only on cpu 0
+	if(my_rank==0)fid=pfopen(filename,"wb");
+
+	for(i=0;i<results->Size();i++){
+		ExternalResult* result=(ExternalResult*)results->GetObjectByOffset(i);
+
+		/*write result to disk: */
+		result->WriteData(fid);
 	}
 
-	/*We are going to extract from the results within the elements, the desired results , and create a table 
-	 * of patch information, that will hold, for each element that computed the result that 
-	 * we desire, the enum_type of the result, the step and time, the id of the element, the interpolation type, the vertices ids, and the values 
-	 * at the nodes (could be different from the vertices). This will be used for visualization purposes. 
-	 * For example, we could build the following patch table, for velocities: 
-	 * 
-	 * VxEnum 1  .5  1 P0  1 2       4.5 NaN  NaN //on a Beam element, Vx, at step 1, time .5, element id 1, interpolation type P0 (constant value on a beam element), vertices ids 1 and 2, one constant value 4.5
-	 * VzEnum 2  .8  2 P1  1 3 4     4.5 3.2  2.5 //on a Tria element, Vz, at step 2, time .8, element id 2, interpolation type P1  (linear values on a tria element), vertices ids 1 3 and 4, with values at 3 nodes 4.5, 3.2, 2.5
-	 * ... etc ...
-	 *
-	 * So what do we need to build the table: the maximum number of vertices included in the table, 
-	 * and the maximum number of nodal values, as well as the number of rows. Once we have that, 
-	 * we ask the elements to fill their own row in the table, by looping on the elememnts. 
-	 *
-	 * We will use the Patch object, which will store all of the information needed, and will be able 
-	 * to output itself to disk on its own. See object/Patch.h for format of this object.*/
-	
-	/*First, determine maximum number of vertices, nodes, and number of results: */
-	numrows=0;
-	numvertices=0;
-	numnodes=0;
-
-	for(i=0;i<elements->Size();i++){
-		Element* element=(Element*)elements->GetObjectByOffset(i);
-		element->PatchSize(&element_numrows,&element_numvertices,&element_numnodes);
-
-		numrows+=element_numrows;
-		if(element_numvertices>numvertices)numvertices=element_numvertices;
-		if(element_numnodes>numnodes)numnodes=element_numnodes;
-	}
-
-	#ifdef _PARALLEL_
-	/*Synchronize across cluster, so as to not end up with different sizes for each patch on each cpu: */
-	MPI_Reduce (&numvertices,&max_numvertices,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
-	MPI_Bcast(&max_numvertices,1,MPI_INT,0,MPI_COMM_WORLD);
-	numvertices=max_numvertices;
-
-	MPI_Reduce (&numnodes,&max_numnodes,1,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD );
-	MPI_Bcast(&max_numnodes,1,MPI_INT,0,MPI_COMM_WORLD);
-	numnodes=max_numnodes;
-	#endif
-
-	/*Ok, initialize Patch object: */
-	patch=new Patch(numrows,numvertices,numnodes);
-
-	/*Now, go through elements, and fill the Patch object: */
-	count=0;
-	for(i=0;i<elements->Size();i++){
-		Element* element=(Element*)elements->GetObjectByOffset(i);
-		element->PatchFill(&count,patch);
-	}
-
-	/*Now, gather patch onto node 0, so that we do not dump to disk from every node: */
-	patch->MPI_Gather();
-
-	/*Write to disk:*/
-	patch->WriteToDisk(solutiontype,filename);
+	/*Close file: */
+	if(my_rank==0)pfclose(fid,filename);
 
 	/*Free ressources:*/
-	delete patch;
 	xfree((void**)&filename);
-
 }
Index: /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h
===================================================================
--- /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 4138)
+++ /issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.h	(revision 4139)
@@ -7,7 +7,10 @@
 
 class DataSet;
+class Parameters;
 
 /* local prototypes: */
-void OutputResults(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters);
+void ElementResultsToPatch(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters,DataSet* results);
+
+void OutputResultsx(DataSet* elements, DataSet* loads, DataSet* nodes, DataSet* vertices, DataSet* materials, Parameters* parameters,DataSet* results);
 
 #endif  /* _OUTPUTRESULTS_H */
Index: /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.cpp	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.cpp	(revision 4139)
@@ -140,2 +140,38 @@
 }
 /*}}}*/
+
+/*Numerics: */
+/*FUNCTION BoolExternalResult::WriteData(FILE* fid) {{{1*/
+void   BoolExternalResult::WriteData(FILE* fid){
+
+	int     length;
+	int     type;
+	char   *name    = NULL;
+	double  boolean;
+	extern  int my_rank;
+
+	/*return if now on cpu 0: */
+	if(my_rank)return;
+
+	/*First write enum: */
+	name=EnumAsString(this->enum_type);
+	length=(strlen(name)+1)*sizeof(char);
+	fwrite(&length,sizeof(int),1,fid);
+	fwrite(name,length,1,fid);
+
+	/*Now write time and step: */
+	fwrite(&time,sizeof(double),1,fid);
+	fwrite(&step,sizeof(int),1,fid);
+
+	/*Now write bool, after casting it: */
+	boolean=(double)this->value;
+
+	/*writing a double, type is 1, size is 1: */
+	type=1;
+	size=1;
+	fwrite(&type,sizeof(int),1,fid);
+	fwrite(&size,sizeof(int),1,fid);
+	fwrite(&boolean,size*sizeof(double),1,fid);
+
+}
+/*}}}1*/
Index: /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.h	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/BoolExternalResult.h	(revision 4139)
@@ -65,4 +65,5 @@
 		/*ExternalResult methods: {{{1*/
 		int   EnumType(){return enum_type;}
+		void  WriteData(FILE* fid);
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.cpp	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.cpp	(revision 4139)
@@ -140,2 +140,34 @@
 }
 /*}}}*/
+
+/*Numerics: */
+/*FUNCTION DoubleExternalResult::WriteData(FILE* fid) {{{1*/
+void   DoubleExternalResult::WriteData(FILE* fid){
+
+	int     length;
+	int     type;
+	char   *name    = NULL;
+	extern  int my_rank;
+
+	/*return if now on cpu 0: */
+	if(my_rank)return;
+
+	/*First write enum: */
+	name=EnumAsString(this->enum_type);
+	length=(strlen(name)+1)*sizeof(char);
+	fwrite(&length,sizeof(int),1,fid);
+	fwrite(name,length,1,fid);
+
+	/*Now write time and step: */
+	fwrite(&time,sizeof(double),1,fid);
+	fwrite(&step,sizeof(int),1,fid);
+
+	/*writing a double, type is 1, size is 1: */
+	type=1;
+	size=1;
+	fwrite(&type,sizeof(int),1,fid);
+	fwrite(&size,sizeof(int),1,fid);
+	fwrite(&this->value,size*sizeof(double),1,fid);
+
+}
+/*}}}1*/
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.h	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleExternalResult.h	(revision 4139)
@@ -65,4 +65,5 @@
 		/*ExternalResult methods: {{{1*/
 		int   EnumType(){return enum_type;}
+		void  WriteData(FILE* fid);
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.cpp	(revision 4139)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.cpp	(revision 4139)
@@ -0,0 +1,199 @@
+/*!\file DoubleMatExternalResult.c
+ * \brief: implementation of the DoubleMatExternalResult object
+ */
+
+/*header files: */
+/*{{{1*/
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "stdio.h"
+#include <string.h>
+#include "../objects.h"
+#include "../../EnumDefinitions/EnumDefinitions.h"
+#include "../../shared/shared.h"
+#include "../../DataSet/DataSet.h"
+#include "../../include/include.h"
+/*}}}*/
+
+/*Object constructors and destructor*/
+/*FUNCTION DoubleMatExternalResult::DoubleMatExternalResult(){{{1*/
+DoubleMatExternalResult::DoubleMatExternalResult(){
+	return;
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::DoubleMatExternalResult(int enum_type,IssmDoubleMat values,int M,int N){{{1*/
+DoubleMatExternalResult::DoubleMatExternalResult(int in_id, int in_enum_type,double* in_values, int in_M,int in_N,int in_step,double in_time){
+
+	id=in_id;
+	enum_type=in_enum_type;
+	M=in_M;
+	N=in_N;
+
+	values=(double*)xmalloc(M*N*sizeof(double));
+	memcpy(values,in_values,M*N*sizeof(double));
+
+	step=in_step;
+	time=in_time;
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::~DoubleMatExternalResult(){{{1*/
+DoubleMatExternalResult::~DoubleMatExternalResult(){
+	xfree((void**)&values);
+	return;
+}
+/*}}}*/
+
+/*Object methods*/
+/*FUNCTION DoubleMatExternalResult::copy{{{1*/
+Object* DoubleMatExternalResult::copy() {
+	
+	return new DoubleMatExternalResult(this->id,this->enum_type,this->values,this->M,this->N,this->step,this->time);
+
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::DeepEcho{{{1*/
+void DoubleMatExternalResult::DeepEcho(void){
+
+	int i;
+	
+	printf("DoubleMatExternalResult:\n");
+	printf("   id: %i\n",this->id);
+	printf("   enum: %i (%s)\n",this->enum_type,EnumAsString(this->enum_type));
+	printf("   matrix size: %i-%i\n",this->M,this->N);
+	for(i=0;i<this->M;i++){
+		printf("%i %g\n",i,this->values[i]);
+	}
+	printf("   step: %i\n",this->step);
+	printf("   time: %g\n",this->time);
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::Demarshall{{{1*/
+void  DoubleMatExternalResult::Demarshall(char** pmarshalled_dataset){
+
+	char* marshalled_dataset=NULL;
+	int   i;
+
+	/*recover marshalled_dataset: */
+	marshalled_dataset=*pmarshalled_dataset;
+
+	/*this time, no need to get enum type, the pointer directly points to the beginning of the 
+	 *object data (thanks to DataSet::Demarshall):*/
+	memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
+	memcpy(&enum_type,marshalled_dataset,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
+	
+	/*data: */
+	memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
+	memcpy(&N,marshalled_dataset,sizeof(N));marshalled_dataset+=sizeof(N);
+	values=(double*)xmalloc(M*N*sizeof(double));
+	memcpy(values,marshalled_dataset,M*N*sizeof(double));marshalled_dataset+=M*N*sizeof(double);
+	memcpy(&step,marshalled_dataset,sizeof(step));marshalled_dataset+=sizeof(step);
+	memcpy(&time,marshalled_dataset,sizeof(time));marshalled_dataset+=sizeof(time);
+
+	/*return: */
+	*pmarshalled_dataset=marshalled_dataset;
+	return;
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::Echo {{{1*/
+void DoubleMatExternalResult::Echo(void){
+
+	printf("DoubleMatExternalResult:\n");
+	printf("   enum: %i (%s)\n",this->enum_type,EnumAsString(this->enum_type));
+	printf("   matrix size: %i-%i\n",this->M,this->N);
+	printf("   step: %i\n",this->step);
+	printf("   time: %g\n",this->time);
+
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::Enum{{{1*/
+int DoubleMatExternalResult::Enum(void){
+
+	return DoubleMatExternalResultEnum;
+
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::Id{{{1*/
+int    DoubleMatExternalResult::Id(void){ return -1; }
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::Marshall{{{1*/
+void  DoubleMatExternalResult::Marshall(char** pmarshalled_dataset){
+
+	char* marshalled_dataset=NULL;
+	int   enum_value=0;
+
+	/*recover marshalled_dataset: */
+	marshalled_dataset=*pmarshalled_dataset;
+
+	/*get enum value of DoubleMatExternalResult: */
+	enum_value=DoubleMatExternalResultEnum;
+	
+	/*marshall enum: */
+	memcpy(marshalled_dataset,&enum_value,sizeof(enum_value));marshalled_dataset+=sizeof(enum_value);
+	
+	/*marshall DoubleMatExternalResult data: */
+	memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
+	memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
+	memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
+	memcpy(marshalled_dataset,&N,sizeof(N));marshalled_dataset+=sizeof(N);
+	memcpy(marshalled_dataset,values,M*sizeof(double));marshalled_dataset+=M*sizeof(double);
+	memcpy(marshalled_dataset,&step,sizeof(step));marshalled_dataset+=sizeof(step);
+	memcpy(marshalled_dataset,&time,sizeof(time));marshalled_dataset+=sizeof(time);
+
+	*pmarshalled_dataset=marshalled_dataset;
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::MarshallSize{{{1*/
+int   DoubleMatExternalResult::MarshallSize(){
+	
+	return sizeof(M)
+		+sizeof(N)
+		+M*N*sizeof(double)
+		+sizeof(id)
+		+sizeof(enum_type)
+		+sizeof(step)
+		+sizeof(time)
+		+sizeof(int); //sizeof(int) for enum value
+}
+/*}}}*/
+/*FUNCTION DoubleMatExternalResult::MyRank{{{1*/
+int    DoubleMatExternalResult::MyRank(void){ 
+	extern int my_rank;
+	return my_rank; 
+}
+/*}}}*/
+
+/*Numerics: */
+/*FUNCTION DoubleMatExternalResult::WriteData(FILE* fid) {{{1*/
+void   DoubleMatExternalResult::WriteData(FILE* fid){
+
+	int     length;
+	int     type;
+	char   *name    = NULL;
+	extern  int my_rank;
+
+	/*return if now on cpu 0: */
+	if(my_rank)return;
+
+	/*First write enum: */
+	name=EnumAsString(this->enum_type);
+	length=(strlen(name)+1)*sizeof(char);
+	fwrite(&length,sizeof(int),1,fid);
+	fwrite(name,length,1,fid);
+
+	/*Now write time and step: */
+	fwrite(&time,sizeof(double),1,fid);
+	fwrite(&step,sizeof(int),1,fid);
+
+	/*writing a double array, type is 3:*/
+	type=3;
+	size=this->M*this->N;
+	fwrite(&type,sizeof(int),1,fid);
+	fwrite(&size,sizeof(int),1,fid);
+	fwrite(this->values,size*sizeof(double),1,fid);
+
+}
+/*}}}1*/
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.h	(revision 4139)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleMatExternalResult.h	(revision 4139)
@@ -0,0 +1,70 @@
+/*! \file DoubleMatExternalResult.h 
+ */
+
+
+#ifndef _DOUBLEMATEXTERNALRESULT_H_
+#define _DOUBLEMATEXTERNALRESULT_H_
+
+/*Headers:*/
+/*{{{1*/
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#ifdef _SERIAL_
+#include <mex.h>
+#endif
+
+
+#include "./ExternalResult.h"
+#include "../../include/include.h"
+#include "../../shared/shared.h"
+#include "../../include/include.h"
+#include "../../include/include.h"
+/*}}}*/
+
+class DoubleMatExternalResult: public ExternalResult{
+
+	private: 
+		int id;
+		int enum_type;
+		double* values;
+		int M;
+		int N;
+		int step;
+		double time;
+
+	public:
+		/*constructors, destructors: {{{1*/
+		DoubleMatExternalResult();
+		DoubleMatExternalResult(int id,int enum_type,double* values,int M,int N,int step, double time);
+		~DoubleMatExternalResult();
+		/*}}}*/
+		/*Object methods: {{{1*/
+		Object* copy();
+		void  DeepEcho();
+		void  Demarshall(char** pmarshalled_dataset);
+		void  Echo();
+		int   Enum();
+		int   Id();
+		void  Marshall(char** pmarshalled_dataset);
+		int   MarshallSize();
+		int   MyRank();
+
+		void  InputUpdateFromVector(double* vector, int name, int type){ISSMERROR("Not implemented yet!");}
+		void  InputUpdateFromVector(int* vector, int name, int type){ISSMERROR("Not implemented yet!");}
+		void  InputUpdateFromVector(bool* vector, int name, int type){ISSMERROR("Not implemented yet!");}
+		void  InputUpdateFromConstant(double constant, int name){ISSMERROR("Not implemented yet!");}
+		void  InputUpdateFromConstant(int constant, int name){ISSMERROR("Not implemented yet!");}
+		void  InputUpdateFromConstant(bool constant, int name){ISSMERROR("Not implemented yet!");}
+		void  InputUpdateFromSolution(double* solution){ISSMERROR("Not implemented yet!");}
+		/*}}}*/
+		/*ExternalResult methods: {{{1*/
+		int   EnumType(){return enum_type;}
+		void  WriteData(FILE* fid);
+		/*}}}*/
+};
+#endif  /* _DOUBLEMATEXTERNALRESULT_H */
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.cpp	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.cpp	(revision 4139)
@@ -162,2 +162,34 @@
 }
 /*}}}*/
+
+/*Numerics: */
+/*FUNCTION DoubleVecExternalResult::WriteData(FILE* fid) {{{1*/
+void   DoubleVecExternalResult::WriteData(FILE* fid){
+
+	int     length;
+	int     type;
+	char   *name    = NULL;
+	extern  int my_rank;
+
+	/*return if now on cpu 0: */
+	if(my_rank)return;
+
+	/*First write enum: */
+	name=EnumAsString(this->enum_type);
+	length=(strlen(name)+1)*sizeof(char);
+	fwrite(&length,sizeof(int),1,fid);
+	fwrite(name,length,1,fid);
+
+	/*Now write time and step: */
+	fwrite(&time,sizeof(double),1,fid);
+	fwrite(&step,sizeof(int),1,fid);
+
+	/*writing a double, type is 1, size is 1: */
+	type=1;
+	size=this->M;
+	fwrite(&type,sizeof(int),1,fid);
+	fwrite(&size,sizeof(int),1,fid);
+	fwrite(this->values,size*sizeof(double),1,fid);
+
+}
+/*}}}1*/
Index: /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.h	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/DoubleVecExternalResult.h	(revision 4139)
@@ -64,4 +64,5 @@
 		/*ExternalResult methods: {{{1*/
 		int   EnumType(){return enum_type;}
+		void  WriteData(FILE* fid);
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/ExternalResults/ExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/ExternalResult.h	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/ExternalResult.h	(revision 4139)
@@ -32,6 +32,6 @@
 		/*methods:{{{1*/
 		virtual int   EnumType()=0;
+		virtual void  WriteData(FILE* fid);
 		/*}}}*/
-
 };
 #endif
Index: /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.cpp	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.cpp	(revision 4139)
@@ -140,2 +140,38 @@
 }
 /*}}}*/
+
+/*Numerics: */
+/*FUNCTION IntExternalResult::WriteData(FILE* fid) {{{1*/
+void   IntExternalResult::WriteData(FILE* fid){
+
+	int     length;
+	int     type;
+	char   *name    = NULL;
+	double  integer;
+	extern  int my_rank;
+
+	/*return if now on cpu 0: */
+	if(my_rank)return;
+
+	/*First write enum: */
+	name=EnumAsString(this->enum_type);
+	length=(strlen(name)+1)*sizeof(char);
+	fwrite(&length,sizeof(int),1,fid);
+	fwrite(name,length,1,fid);
+
+	/*Now write time and step: */
+	fwrite(&time,sizeof(double),1,fid);
+	fwrite(&step,sizeof(int),1,fid);
+
+	/*cast to a double: */
+	integer=(double)this->value;
+
+	/*writing a double, type is 1, size is 1: */
+	type=1;
+	size=this->M;
+	fwrite(&type,sizeof(int),1,fid);
+	fwrite(&size,sizeof(int),1,fid);
+	fwrite(&this->value,size*sizeof(double),1,fid);
+
+}
+/*}}}1*/
Index: /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.h	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/IntExternalResult.h	(revision 4139)
@@ -65,4 +65,5 @@
 		/*ExternalResult methods: {{{1*/
 		int   EnumType(){return enum_type;}
+		void  WriteData(FILE* fid);
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.cpp	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.cpp	(revision 4139)
@@ -194,2 +194,40 @@
 }
 /*}}}*/
+
+/*Numerics: */
+/*FUNCTION PetscVecExternalResult::WriteData(FILE* fid) {{{1*/
+void   PetscVecExternalResult::WriteData(FILE* fid){
+
+	int     length;
+	int     type;
+	char   *name      = NULL;
+	double *serialvec = NULL;
+
+	/*serialize: */
+	VecGetSize(this->value,&size);
+	VecToMPISerial(&serialvec,this->value);
+
+	/*now, exit if we are not on cpu 0: */
+	if(my_rank)return;
+
+	/*First write enum: */
+	name=EnumAsString(this->enum_type);
+	length=(strlen(name)+1)*sizeof(char);
+	fwrite(&length,sizeof(int),1,fid);
+	fwrite(name,length,1,fid);
+
+	/*Now write time and step: */
+	fwrite(&time,sizeof(double),1,fid);
+	fwrite(&step,sizeof(int),1,fid);
+
+	/*writing a double, type is 1, size is 1: */
+	type=1;
+	
+	fwrite(&type,sizeof(int),1,fid);
+	fwrite(&size,sizeof(int),1,fid);
+	fwrite(serialvec,size*sizeof(double),1,fid);
+
+	/*Free ressources:*/
+	xfree((void**)&serialvec);
+}
+/*}}}1*/
Index: /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.h	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/PetscVecExternalResult.h	(revision 4139)
@@ -63,4 +63,5 @@
 		/*ExternalResult methods: {{{1*/
 		int   EnumType(){return enum_type;}
+		void  WriteData(FILE* fid);
 		/*}}}*/
 };
Index: /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.cpp
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.cpp	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.cpp	(revision 4139)
@@ -155,2 +155,35 @@
 }
 /*}}}*/
+
+/*Numerics: */
+/*FUNCTION StringExternalResult::WriteData(FILE* fid) {{{1*/
+void   StringExternalResult::WriteData(FILE* fid){
+
+	int     length;
+	int     type;
+	char   *name      = NULL;
+	extern  int my_rank;
+
+	/*return if now on cpu 0: */
+	if(my_rank)return;
+
+	/*First write enum: */
+	name=EnumAsString(this->enum_type);
+	length=(strlen(name)+1)*sizeof(char);
+	fwrite(&length,sizeof(int),1,fid);
+	fwrite(name,length,1,fid);
+
+	/*Now write time and step: */
+	fwrite(&time,sizeof(double),1,fid);
+	fwrite(&step,sizeof(int),1,fid);
+
+	/*writing a string, type is 2: */
+	type=2;
+	fwrite(&type,sizeof(int),1,fid);
+	
+	length=(strlen(this->value)+1)*sizeof(char);
+	fwrite(&length,sizeof(int),1,fid);
+	fwrite(this->value,length,1,fid);
+
+}
+/*}}}1*/
Index: /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.h
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.h	(revision 4138)
+++ /issm/trunk/src/c/objects/ExternalResults/StringExternalResult.h	(revision 4139)
@@ -64,4 +64,5 @@
 		/*ExternalResult methods: {{{1*/
 		int   EnumType(){return enum_type;}
+		void  WriteData(FILE* fid);
 		/*}}}*/
 };
Index: sm/trunk/src/c/objects/ExternalResults/list
===================================================================
--- /issm/trunk/src/c/objects/ExternalResults/list	(revision 4138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-BoolExternalResultEnum
-DoubleExternalResultEnum
-DoubleVecExternalResultEnum
-IntExternalResultEnum
-PetscVecExternalResultEnum
-StringExternalResultEnum
