Index: /issm/trunk-jpl/src/c/EnumDefinitions/Synchronize.sh
===================================================================
--- /issm/trunk-jpl/src/c/EnumDefinitions/Synchronize.sh	(revision 12449)
+++ /issm/trunk-jpl/src/c/EnumDefinitions/Synchronize.sh	(revision 12450)
@@ -48,5 +48,5 @@
 
 	len=strlen(EnumToStringx(enum_in));
-	string=(char*)xmalloc((len+1)*sizeof(char));
+	string=xNew<char>(len+1);
 	memcpy(string,EnumToStringx(enum_in),(len+1)*sizeof(char));
 
Index: /issm/trunk-jpl/src/c/modules/AverageFilterx/AverageFilterx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/AverageFilterx/AverageFilterx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/AverageFilterx/AverageFilterx.cpp	(revision 12450)
@@ -18,7 +18,7 @@
 
 	/*output: */
-	double*         imageout=NULL;
+	double* imageout=NULL;
 
-	imageout=(double*)xmalloc(samps*lines*sizeof(double));
+	imageout=xNew<double>(samps*lines);
 
   	for ( i = 0; i < lines; i++ ){
Index: /issm/trunk-jpl/src/c/modules/AverageOntoPartitionx/AverageOntoPartitionx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/AverageOntoPartitionx/AverageOntoPartitionx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/AverageOntoPartitionx/AverageOntoPartitionx.cpp	(revision 12450)
@@ -65,5 +65,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&qmu_part);
+	xDelete<int>(qmu_part);
 	xdelete(&partition_contributions);
 	xdelete(&partition_areas);
Index: /issm/trunk-jpl/src/c/modules/ContourToMeshx/ContourToMeshx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ContourToMeshx/ContourToMeshx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ContourToMeshx/ContourToMeshx.cpp	(revision 12450)
@@ -70,5 +70,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&in_nod_serial);
+	xDelete<double>(in_nod_serial);
 
 	return noerr;
Index: /issm/trunk-jpl/src/c/modules/ControlInputGetGradientx/ControlInputGetGradientx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ControlInputGetGradientx/ControlInputGetGradientx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ControlInputGetGradientx/ControlInputGetGradientx.cpp	(revision 12450)
@@ -33,5 +33,5 @@
 
 	/*Clean up and return*/
-	xfree((void**)&control_type);
+	xDelete<int>(control_type);
 	*pgradient=gradient;
 }
Index: /issm/trunk-jpl/src/c/modules/ControlInputScaleGradientx/ControlInputScaleGradientx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ControlInputScaleGradientx/ControlInputScaleGradientx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ControlInputScaleGradientx/ControlInputScaleGradientx.cpp	(revision 12450)
@@ -37,5 +37,5 @@
 
 	/*Clean up and return*/
-	xfree((void**)&control_type);
-	xfree((void**)&scalar_list);
+	xDelete<int>(control_type);
+	xDelete<double>(scalar_list);
 }
Index: /issm/trunk-jpl/src/c/modules/ControlInputSetGradientx/ControlInputSetGradientx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ControlInputSetGradientx/ControlInputSetGradientx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ControlInputSetGradientx/ControlInputSetGradientx.cpp	(revision 12450)
@@ -27,5 +27,5 @@
 
 	/*Clean up and return*/
-	xfree((void**)&control_type);
+	xDelete<int>(control_type);
 
 }
@@ -39,4 +39,4 @@
 
 	/*Clean up and return*/
-	xfree((void**)&serial_gradient);
+	xDelete<double>(serial_gradient);
 }
Index: /issm/trunk-jpl/src/c/modules/CostFunctionx/CostFunctionx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/CostFunctionx/CostFunctionx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/CostFunctionx/CostFunctionx.cpp	(revision 12450)
@@ -35,5 +35,5 @@
 
 	/*Assign output pointers: */
-	xfree((void**)&responses);
+	xDelete<int>(responses);
 	*pJ=J;
 }
Index: /issm/trunk-jpl/src/c/modules/DakotaResponsesx/DakotaResponsesx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/DakotaResponsesx/DakotaResponsesx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/DakotaResponsesx/DakotaResponsesx.cpp	(revision 12450)
@@ -30,8 +30,7 @@
 	double femmodel_response;
 	int    flag;
-	double* vertex_response=NULL;
-	double* qmu_response=NULL;
-
-	double* responses_pointer=NULL;
+	double *vertex_response   = NULL;
+	double *qmu_response      = NULL;
+	double *responses_pointer = NULL;
 
 	/*retrieve npart: */
@@ -66,6 +65,6 @@
 
 			/*Free ressources:*/
-			xfree((void**)&vertex_response);
-			xfree((void**)&qmu_response);
+			xDelete<double>(vertex_response);
+			xDelete<double>(qmu_response);
 
 		}
Index: /issm/trunk-jpl/src/c/modules/Dakotax/DakotaFree.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Dakotax/DakotaFree.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Dakotax/DakotaFree.cpp	(revision 12450)
@@ -22,8 +22,8 @@
 	extern int my_rank;
 	
-	double* variables=NULL;
-	char**  variables_descriptors=NULL;
-	char**  responses_descriptors=NULL;
-	char*   string=NULL;
+	double  *variables             = NULL;
+	char   **variables_descriptors = NULL;
+	char   **responses_descriptors = NULL;
+	char    *string                = NULL;
 
 	/*recover pointers: */
@@ -35,10 +35,10 @@
 	/*Free variables and variables_descriptors only on cpu !=0*/
 	if(my_rank!=0){
-		xfree((void**)&variables);
+		xDelete<double>(variables);
 		for(i=0;i<numvariables;i++){
 			string=variables_descriptors[i];
-			xfree((void**)&string);
+			xDelete<char>(string);
 		}
-		xfree((void**)&variables_descriptors);
+		xDelete<char*>(variables_descriptors);
 	}
 	
@@ -46,8 +46,8 @@
 	for(i=0;i<numresponses;i++){
 		string=responses_descriptors[i];
-		xfree((void**)&string);
+		xDelete<char>(string);
 	}
 	//rest of dynamic allocations.
-	xfree((void**)&responses_descriptors);
+	xDelete<char*>(responses_descriptors);
 
 	/*Assign output pointers:*/
@@ -56,3 +56,2 @@
 	*presponses_descriptors=responses_descriptors;
 }
-
Index: /issm/trunk-jpl/src/c/modules/Dakotax/DakotaMPI_Bcast.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Dakotax/DakotaMPI_Bcast.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Dakotax/DakotaMPI_Bcast.cpp	(revision 12450)
@@ -38,10 +38,10 @@
 	
 	/*variables:*/
-	if(my_rank!=0)variables=(double*)xmalloc(numvariables*sizeof(double));
+	if(my_rank!=0)variables=xNew<double>(numvariables);
 	MPI_Bcast(variables,numvariables,MPI_DOUBLE,0,MPI_COMM_WORLD); 
 
 	/*variables_descriptors: */
 	if(my_rank!=0){
-		variables_descriptors=(char**)xmalloc(numvariables*sizeof(char*));
+		variables_descriptors=xNew<char*>(numvariables);
 	}
 	for(i=0;i<numvariables;i++){
@@ -51,5 +51,5 @@
 		}
 		MPI_Bcast(&string_length,1,MPI_INT,0,MPI_COMM_WORLD); 
-		if(my_rank!=0)string=(char*)xmalloc(string_length);
+		if(my_rank!=0)string=xNew<char>(string_length);
 		MPI_Bcast(string,string_length,MPI_CHAR,0,MPI_COMM_WORLD); 
 		if(my_rank!=0)variables_descriptors[i]=string;
Index: /issm/trunk-jpl/src/c/modules/Dakotax/Dakotax.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Dakotax/Dakotax.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Dakotax/Dakotax.cpp	(revision 12450)
@@ -121,7 +121,7 @@
 
 	/*Free ressources:*/
-	xfree((void**)&dakota_input_file);
-	xfree((void**)&dakota_error_file);
-	xfree((void**)&dakota_output_file);
+	xDelete<char>(dakota_input_file);
+	xDelete<char>(dakota_error_file);
+	xDelete<char>(dakota_output_file);
 
 	#endif //#ifdef _HAVE_DAKOTA_
Index: /issm/trunk-jpl/src/c/modules/ElementConnectivityx/ElementConnectivityx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ElementConnectivityx/ElementConnectivityx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ElementConnectivityx/ElementConnectivityx.cpp	(revision 12450)
@@ -36,5 +36,5 @@
 	maxels=width-1;
 	/*Allocate connectivity: */
-	elementconnectivity=(double*)xcalloc(nel*3,sizeof(double));
+	elementconnectivity=xNewZeroInit<double>(nel*3);
 
 	/*Go through all elements, and for each element, go through its nodes, to get the neighbouring elements. 
Index: /issm/trunk-jpl/src/c/modules/EnumToStringx/EnumToStringx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/EnumToStringx/EnumToStringx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/EnumToStringx/EnumToStringx.cpp	(revision 12450)
@@ -466,5 +466,5 @@
 
 	len=strlen(EnumToStringx(enum_in));
-	string=(char*)xmalloc((len+1)*sizeof(char));
+	string=xNew<char>(len+1);
 	memcpy(string,EnumToStringx(enum_in),(len+1)*sizeof(char));
 
Index: /issm/trunk-jpl/src/c/modules/GetVectorFromControlInputsx/GetVectorFromControlInputsx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/GetVectorFromControlInputsx/GetVectorFromControlInputsx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/GetVectorFromControlInputsx/GetVectorFromControlInputsx.cpp	(revision 12450)
@@ -32,5 +32,5 @@
 
 	/*Assign output pointers:*/
-	xfree((void**)&control_type);
+	xDelete<int>(control_type);
 	*pvector=vector;
 }
Index: /issm/trunk-jpl/src/c/modules/Gradjx/Gradjx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Gradjx/Gradjx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Gradjx/Gradjx.cpp	(revision 12450)
@@ -14,9 +14,9 @@
 	int     i,j,numberofvertices;
 	int     num_controls;
-	double  norm_inf;
-	double *norm_list       = NULL;
-	int    *control_type    = NULL;
-	Vector*     gradient        = NULL;
-	Vector*    *gradient_list   = NULL;
+	double   norm_inf;
+	double  *norm_list     = NULL;
+	int     *control_type  = NULL;
+	Vector  *gradient      = NULL;
+	Vector **gradient_list = NULL;
 	
 	/*retrieve some parameters: */
@@ -26,6 +26,6 @@
 
 	/*Allocate gradient_list */
-	gradient_list = (Vector**)xmalloc(num_controls*sizeof(Vector*));
-	norm_list = (double*)xmalloc(num_controls*sizeof(double));
+	gradient_list = xNew<Vector*>(num_controls);
+	norm_list = xNew<double>(num_controls);
 	for(i=0;i<num_controls;i++){
 		gradient_list[i]=new Vector(num_controls*numberofvertices);
@@ -62,8 +62,8 @@
 	}
 	else{
-		xfree((void**)&norm_list);
+		xDelete<double>(norm_list);
 	}
 	if(pgradient)  *pgradient=gradient;
-	xfree((void**)&gradient_list);
-	xfree((void**)&control_type);
+	xDelete<Vector*>(gradient_list);
+	xDelete<int>(control_type);
 }
Index: /issm/trunk-jpl/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationx.cpp	(revision 12450)
@@ -49,7 +49,7 @@
 	/*free ressouces: */
 	xdelete(&vec_old_floatingice);
-	xfree((void**)&vertices_potentially_ungrounding);
-	xfree((void**)&vertices_ungrounding);
-	xfree((void**)&old_floatingice);
+	xDelete<double>(vertices_potentially_ungrounding);
+	xDelete<double>(vertices_ungrounding);
+	xDelete<double>(old_floatingice);
 }
 
@@ -164,6 +164,6 @@
 
 		/*Avoid leaks: */
-		xfree((void**)&elements_neighboring_floatingce);
-		xfree((void**)&nodes_on_floatingice);
+		xDelete<double>(elements_neighboring_floatingce);
+		xDelete<double>(nodes_on_floatingice);
 
 		/*Assemble and serialize:*/
@@ -174,5 +174,5 @@
 	/*Free ressources:*/
 	xdelete(&vec_nodes_on_floatingice);
-	xfree((void**)&elements_neighboring_floatingce);
+	xDelete<double>(elements_neighboring_floatingce);
 
 	return nodes_on_floatingice;
Index: /issm/trunk-jpl/src/c/modules/HoleFillerx/HoleFillerx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/HoleFillerx/HoleFillerx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/HoleFillerx/HoleFillerx.cpp	(revision 12450)
@@ -43,5 +43,5 @@
 
 	 /*^^^^^^^^^^^^^  Remove pixels close to the holes ^^^^^^^^^^^^^*/
-	image2 = (double*) xmalloc( lines*samps*sizeof(double));
+	image2 = xNew<double>(lines*samps);
 	memcpy(image2,image,lines*samps*sizeof(double));
 	
@@ -64,5 +64,5 @@
 	}
 
-	image3 = (double*) xmalloc( lines*samps*sizeof(double));
+	image3 = xNew<double>(lines*samps);
 	memcpy(image3,image2,lines*samps*sizeof(double));
 
@@ -304,5 +304,5 @@
 /************************ SMOOTH THE RESULT ***********************/		
 		
-	image4 = (double*) xmalloc( lines*samps*sizeof(double));
+	image4 = xNew<double>(lines*samps);
 	memcpy(image4,image3,lines*samps*sizeof(double));
 
@@ -348,5 +348,5 @@
 
 	/*Allocate output image: */
-	imageout=(double*)xmalloc(samps*lines*sizeof(double));
+	imageout=xNew<double>(samps*lines);
 	memcpy(imageout,image3,lines*samps*sizeof(double));
 
@@ -363,6 +363,4 @@
 	/*Assign output pointers: */
 	*pimageout=imageout;
-
 	return 1;
-	
 }
Index: /issm/trunk-jpl/src/c/modules/InputConvergencex/InputConvergencex.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputConvergencex/InputConvergencex.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/InputConvergencex/InputConvergencex.cpp	(revision 12450)
@@ -12,13 +12,13 @@
 
 	/*intermediary:*/
-	int         i;
-	bool        converged;
-	int         num_notconverged=0;
-	int         total_notconverged;
-	double     *eps       = NULL;
-	Element*    element=NULL;
+	int      i;
+	bool     converged;
+	int      num_notconverged   = 0;
+	int      total_notconverged;
+	double  *eps                = NULL;
+	Element *element            = NULL;
 
 	/*allocate dynamic memory: */
-	eps=(double*)xmalloc(num_criterionenums*sizeof(double));
+	eps=xNew<double>(num_criterionenums);
 
 	/*Go through elements, and ask them to do the job: */
@@ -37,5 +37,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&eps);
+	xDelete<double>(eps);
 
 	/*return: */
Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 12450)
@@ -21,7 +21,7 @@
 	double *qmu_part  = NULL;
 
-	double* distributed_values=NULL;
-	double* parameter=NULL;
-	char*   descriptor=NULL;
+	double *distributed_values = NULL;
+	double *parameter          = NULL;
+	char   *descriptor         = NULL;
 	char    root[50]; //root name of variable, ex: DragCoefficent, RhoIce, etc ...
 
@@ -49,5 +49,5 @@
 
 
-			distributed_values=(double*)xmalloc(npart*sizeof(double));
+			distributed_values=xNew<double>(npart);
 			for(j=0;j<npart;j++){
 				distributed_values[j]=variables[i+j];
@@ -91,6 +91,6 @@
 
 			/*Free allocations: */
-			xfree((void**)&parameter);
-			xfree((void**)&distributed_values);
+			xDelete<double>(parameter);
+			xDelete<double>(distributed_values);
 		}
 		else if (strncmp(descriptor,"indexed_",8)==0){
@@ -107,5 +107,4 @@
 
 	/*Free ressources:*/
-	xfree((void**)&qmu_part);
-
+	xDelete<double>(qmu_part);
 }
Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromSolutionx/InputUpdateFromSolutionx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromSolutionx/InputUpdateFromSolutionx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromSolutionx/InputUpdateFromSolutionx.cpp	(revision 12450)
@@ -20,6 +20,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&serial_solution);
-
+	xDelete<double>(serial_solution);
 }
 
@@ -36,4 +35,3 @@
 		element->InputUpdateFromSolution(solution);
 	}
-
 }
Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.cpp	(revision 12450)
@@ -18,5 +18,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&serial_vector);
+	xDelete<double>(serial_vector);
 }
 
Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromVectorx/InputUpdateFromVectorx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromVectorx/InputUpdateFromVectorx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromVectorx/InputUpdateFromVectorx.cpp	(revision 12450)
@@ -18,5 +18,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&serial_vector);
+	xDelete<double>(serial_vector);
 }
 
Index: /issm/trunk-jpl/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp	(revision 12450)
@@ -52,6 +52,6 @@
 
 		/*The coordinates given in input describe the contour of each pixel. Take the center of each pixel*/
-		x=(double*)xmalloc(N*sizeof(double));
-		y=(double*)xmalloc(M*sizeof(double));
+		x=xNew<double>(N);
+		y=xNew<double>(M);
 		for (i=0;i<N;i++) x[i]=(x_in[i]+x_in[i+1])/2;
 		for (i=0;i<M;i++) y[i]=(y_in[i]+y_in[i+1])/2;
@@ -62,6 +62,6 @@
 
 		/*The coordinates given in input describe the center each pixel. Keep them*/
-		x=(double*)xmalloc(N*sizeof(double));
-		y=(double*)xmalloc(M*sizeof(double));
+		x=xNew<double>(N);
+		y=xNew<double>(M);
 		for (i=0;i<N;i++) x[i]=x_in[i];
 		for (i=0;i<M;i++) y[i]=y_in[i];
Index: /issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp	(revision 12450)
@@ -45,7 +45,7 @@
 
 	/*First, allocate pointers: */
-	griddata=(double*)xcalloc(nlines*ncols,sizeof(double));
-	x_grid=(double*)xcalloc(ncols,sizeof(double));
-	y_grid=(double*)xcalloc(nlines,sizeof(double));
+	griddata=xNewZeroInit<double>(nlines*ncols);
+	x_grid=xNewZeroInit<double>(ncols);
+	y_grid=xNewZeroInit<double>(nlines);
 
 	/*Set debug to 1 if there are lots of elements*/
Index: /issm/trunk-jpl/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 12450)
@@ -55,5 +55,5 @@
 	/*Initialize output*/
 	if (verbose) printf("Initializing output vector\n");
-	data_interp=(double*)xmalloc(nods_interp*data_cols*sizeof(double));
+	data_interp=xNew<double>(nods_interp*data_cols);
 
 	// read background mesh 
Index: /issm/trunk-jpl/src/c/modules/KMLFileReadx/KMLFileReadx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/KMLFileReadx/KMLFileReadx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/KMLFileReadx/KMLFileReadx.cpp	(revision 12450)
@@ -44,5 +44,5 @@
 
 //		_printf_(true,"%s\n",kstr);
-		xfree((void**)&kstr);
+		xDelete<char>(kstr);
 	}
 
Index: /issm/trunk-jpl/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp	(revision 12450)
@@ -184,6 +184,6 @@
 														cmap,mcmap,ncmap));
 
-	if(edfree) xfree((void**)&edata);
-	if(ncfree) xfree((void**)&nodecon);
+	if(edfree) xDelete<double>(edata);
+	if(ncfree) xDelete<int>(nodecon);
 	clock0a=clock();
 	time0a =time(NULL);
Index: /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp	(revision 12450)
@@ -44,6 +44,6 @@
 
 	/*Allocate output*/
-	predictions =(double*)xcalloc(n_interp,sizeof(double));
-	error       =(double*)xcalloc(n_interp,sizeof(double));
+	predictions =xNewZeroInit<double>(n_interp);
+	error       =xNewZeroInit<double>(n_interp);
 
 	/*Get output*/
@@ -68,15 +68,15 @@
 		printf("Generation Delaunay Triangulation\n");
 		BamgTriangulatex(&index,&nel,x,y,nobs);
-		indexd =(double*)xcalloc(nel*3,sizeof(double));
+		indexd =xNewZeroInit<double>(nel*3);
 		for(int i=0;i<nel*3;i++) indexd[i]=(double)index[i];
-		xfree((void**)&index);
+		xDelete<int>(index);
 
 		printf("Interpolating\n");
-		xfree((void**)&predictions);
+		xDelete<double>(predictions);
 		InterpFromMeshToMesh2dx(&predictions,indexd,x,y,nobs,nel,data,nobs,1,x_interp,y_interp,n_interp,NULL,0,new DataSet());
-		xfree((void**)&x);
-		xfree((void**)&y);
-		xfree((void**)&index);
-		xfree((void**)&data);
+		xDelete<double>(x);
+		xDelete<double>(y);
+		xDelete<double>(data);
+		xDelete<int>(index);
 	}
 	else if(strcmp(output,"nearestneighbor")==0){
@@ -92,10 +92,10 @@
 		gate.predictions  = predictions;
 		gate.error        = error;
-		gate.percent      = (double*)xcalloc(num,sizeof(double));
+		gate.percent      = xNewZeroInit<double>(num);
 
 		/*launch the thread manager with Krigingxt as a core: */
 		LaunchThread(NearestNeighbort,(void*)&gate,num);
 		printf("\r      interpolation progress:  100.00%%\n");
-		xfree((void**)&gate.percent);
+		xDelete<double>(gate.percent);
 	}
 	else if(strcmp(output,"idw")==0){ //Inverse distance weighting
@@ -111,10 +111,10 @@
 		gate.predictions  = predictions;
 		gate.error        = error;
-		gate.percent      = (double*)xcalloc(num,sizeof(double));
+		gate.percent      = xNewZeroInit<double>(num);
 
 		/*launch the thread manager with Krigingxt as a core: */
 		LaunchThread(idwt,(void*)&gate,num);
 		printf("\r      interpolation progress:  100.00%%\n");
-		xfree((void**)&gate.percent);
+		xDelete<double>(gate.percent);
 	}
 	else if(strcmp(output,"prediction")==0){
@@ -131,10 +131,10 @@
 		gate.predictions  = predictions;
 		gate.error        = error;
-		gate.percent      = (double*)xcalloc(num,sizeof(double));
+		gate.percent      = xNewZeroInit<double>(num);
 
 		/*launch the thread manager with Krigingxt as a core: */
 		LaunchThread(Krigingxt,(void*)&gate,num);
 		printf("\r      interpolation progress:  100.00%%\n");
-		xfree((void**)&gate.percent);
+		xDelete<double>(gate.percent);
 	}
 	else{
@@ -145,5 +145,5 @@
 	delete variogram;
 	delete observations;
-	xfree((void**)&output);
+	xDelete<char>(output);
 	*ppredictions = predictions;
 	*perror       = error;
@@ -311,5 +311,5 @@
 
 	/*Assign output pointer*/
-	xfree((void**)&model);
+	xDelete<char>(model);
 	*pvariogram = variogram;
 }/*}}}*/
Index: /issm/trunk-jpl/src/c/modules/MassFluxx/MassFluxx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/MassFluxx/MassFluxx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/MassFluxx/MassFluxx.cpp	(revision 12450)
@@ -67,9 +67,9 @@
 	for(j=0;j<M;j++){
 		double* matrix=array[j];
-		xfree((void**)&matrix);
+		xDelete<double>(matrix);
 	}
-	xfree((void**)&mdims_array);
-	xfree((void**)&ndims_array);
-	xfree((void**)&array);
+	xDelete<int>(mdims_array);
+	xDelete<int>(ndims_array);
+	xDelete<double*>(array);
 	
 	/*Assign output pointers: */
Index: /issm/trunk-jpl/src/c/modules/MeshPartitionx/MeshPartitionx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/MeshPartitionx/MeshPartitionx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/MeshPartitionx/MeshPartitionx.cpp	(revision 12450)
@@ -31,7 +31,7 @@
 
 	if(dim==2){
-		epart=(int*)xmalloc(numberofelements*sizeof(int));
-		npart=(int*)xmalloc(numberofnodes*sizeof(int));
-		index=(int*)xmalloc(elements_width*numberofelements*sizeof(int));
+		epart=xNew<int>(numberofelements);
+		npart=xNew<int>(numberofnodes);
+		index=xNew<int>(elements_width*numberofelements);
 		for (i=0;i<numberofelements;i++){
 			for (j=0;j<elements_width;j++){
@@ -57,7 +57,7 @@
 
 		/*First build concatenated 2d mesh  from 2d_coll and 2d_noncoll: */
-		epart2d=(int*)xmalloc(numberofelements2d*sizeof(int));
-		npart2d=(int*)xmalloc(numberofnodes2d*sizeof(int)); 
-		index2d=(int*)xmalloc(3*numberofelements2d*sizeof(int));
+		epart2d=xNew<int>(numberofelements2d);
+		npart2d=xNew<int>(numberofnodes2d); 
+		index2d=xNew<int>(3*numberofelements2d);
 
 		for (i=0;i<numberofelements2d;i++){
@@ -81,5 +81,5 @@
 
 		/*Extrude epart2d to epart, using numlayers: */
-		epart=(int*)xmalloc(numberofelements*sizeof(int));
+		epart=xNew<int>(numberofelements);
 		
 		count=0;
@@ -92,5 +92,5 @@
 
 		/*Extrude npart2d to npart, using numlayers: */
-		npart=(int*)xmalloc(numberofnodes*sizeof(int));
+		npart=xNew<int>(numberofnodes);
 		
 		count=0;
@@ -108,10 +108,8 @@
 
 	/*Free ressources: */
-	xfree((void**)&index);
-	xfree((void**)&epart2d);
-	xfree((void**)&npart2d);
-	xfree((void**)&index2d);
-
+	xDelete<int>(index);
+	xDelete<int>(epart2d);
+	xDelete<int>(npart2d);
+	xDelete<int>(index2d);
 	return noerr;
-
 }
Index: /issm/trunk-jpl/src/c/modules/MeshProfileIntersectionx/MeshProfileIntersectionx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/MeshProfileIntersectionx/MeshProfileIntersectionx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/MeshProfileIntersectionx/MeshProfileIntersectionx.cpp	(revision 12450)
@@ -5,5 +5,4 @@
 
 void MeshProfileIntersectionx( double** psegments, int* pnumsegs, int* index, double* x, double* y, int nel, int nods,  Contour** contours,int numcontours){
-
 
 	int i,j,k;
@@ -28,6 +27,6 @@
 
 	/*Allocate: */
-	allsegments=(double**)xmalloc(numcontours*sizeof(double*));
-	allnumsegs=(int*)xmalloc(numcontours*sizeof(int));
+	allsegments=xNew<double*>(numcontours);
+	allnumsegs=xNew<int>(numcontours);
 
 	/*Loop through all contours: */
@@ -53,5 +52,5 @@
 
 	/*Out of all segments, create one common array of segments: */
-	segments=(double*)xmalloc(5*numsegs*sizeof(double));
+	segments=xNew<double>(5*numsegs);
 	count=0;
 	for(i=0;i<numcontours;i++){
Index: /issm/trunk-jpl/src/c/modules/MeshProfileIntersectionx/MeshSegmentsIntersection.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/MeshProfileIntersectionx/MeshSegmentsIntersection.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/MeshProfileIntersectionx/MeshSegmentsIntersection.cpp	(revision 12450)
@@ -32,5 +32,5 @@
 	/*Using the segments_dataset dataset, create segments: */
 	numsegs=segments_dataset->Size();
-	segments=(double*)xmalloc(5*numsegs*sizeof(double));
+	segments=xNew<double>(5*numsegs);
 	for(i=0;i<numsegs;i++){
 		Segment* segment=(Segment*)segments_dataset->GetObjectByOffset(i);
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp	(revision 12450)
@@ -63,9 +63,9 @@
 		parameters->AddObject(new DoubleVecParam(InversionMaxiterPerStepEnum,maxiter,nsteps));
 
-		xfree((void**)&control_type);
-		xfree((void**)&cm_responses);
-		xfree((void**)&cm_jump);
-		xfree((void**)&optscal);
-		xfree((void**)&maxiter);
+		xDelete<int>(control_type);
+		xDelete<double>(cm_responses);
+		xDelete<double>(cm_jump);
+		xDelete<double>(optscal);
+		xDelete<double>(maxiter);
 	}
 
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateNumberNodeToElementConnectivity.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateNumberNodeToElementConnectivity.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateNumberNodeToElementConnectivity.cpp	(revision 12450)
@@ -43,5 +43,5 @@
 
 	/*Allocate ouput*/
-	connectivity=(int*)xcalloc(numberofvertices,sizeof(int));
+	connectivity=xNewZeroInit<int>(numberofvertices);
 
 	/*Get element width (3 or 6)*/
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateParameters.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateParameters.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateParameters.cpp	(revision 12450)
@@ -105,13 +105,13 @@
 	parameters->AddObject(new IntParam(DiagnosticNumRequestedOutputsEnum,numoutputs));
 	if(numoutputs)parameters->AddObject(new IntVecParam(DiagnosticRequestedOutputsEnum,requestedoutputs,numoutputs));
-	xfree((void**)&requestedoutputs);
+	xDelete<double>(requestedoutputs);
 	iomodel->FetchData(&requestedoutputs,&numoutputs,NULL,TransientRequestedOutputsEnum);
 	parameters->AddObject(new IntParam(TransientNumRequestedOutputsEnum,numoutputs));
 	if(numoutputs)parameters->AddObject(new IntVecParam(TransientRequestedOutputsEnum,requestedoutputs,numoutputs));
-	xfree((void**)&requestedoutputs);
+	xDelete<double>(requestedoutputs);
 	iomodel->FetchData(&requestedoutputs,&numoutputs,NULL,SteadystateRequestedOutputsEnum);
 	parameters->AddObject(new IntParam(SteadystateNumRequestedOutputsEnum,numoutputs));
 	if(numoutputs)parameters->AddObject(new IntVecParam(SteadystateRequestedOutputsEnum,requestedoutputs,numoutputs));
-	xfree((void**)&requestedoutputs);
+	xDelete<double>(requestedoutputs);
 	
 	/*Before returning, create parameters in case we are running Qmu or control types runs: */
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateSingleNodeToElementConnectivity.cpp	(revision 12450)
@@ -44,5 +44,5 @@
 
 	/*Allocate ouput*/
-	connectivity=(int*)xcalloc(numberofvertices,sizeof(int));
+	connectivity=xNewZeroInit<int>(numberofvertices);
 
 	/*Get element width (3 or 6)*/
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/Dakota/CreateParametersDakota.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/Dakota/CreateParametersDakota.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/Dakota/CreateParametersDakota.cpp	(revision 12450)
@@ -74,13 +74,13 @@
 
 		/*name of qmu input, error and output files:{{{*/
-		qmuinname=(char*)xmalloc((strlen(name)+strlen(".qmu.in")+1)*sizeof(char));
+		qmuinname=xNew<char>((strlen(name)+strlen(".qmu.in")+1));
 		sprintf(qmuinname,"%s%s",name,".qmu.in");
 		parameters->AddObject(new   StringParam(QmuInNameEnum,qmuinname));
 
-		qmuoutname=(char*)xmalloc((strlen(name)+strlen(".qmu.out")+1)*sizeof(char));
+		qmuoutname=xNew<char>((strlen(name)+strlen(".qmu.out")+1));
 		sprintf(qmuoutname,"%s%s",name,".qmu.out");
 		parameters->AddObject(new   StringParam(QmuOutNameEnum,qmuoutname));
 
-		qmuerrname=(char*)xmalloc((strlen(name)+strlen(".qmu.err")+1)*sizeof(char));
+		qmuerrname=xNew<char>((strlen(name)+strlen(".qmu.err")+1));
 		sprintf(qmuerrname,"%s%s",name,".qmu.err");
 		parameters->AddObject(new   StringParam(QmuErrNameEnum,qmuerrname));
@@ -111,5 +111,5 @@
 			ElementsAndVerticesPartitioning(&iomodel->my_elements,&iomodel->my_vertices,iomodel);
 
-			dpart=(double*)xmalloc(numberofvertices*sizeof(double));
+			dpart=xNew<double>(numberofvertices);
 			for(i=0;i<numberofvertices;i++)dpart[i]=iomodel->my_vertices[i];
 		}
@@ -136,5 +136,5 @@
 				
 				/*Free ressources:*/
-				xfree((void**)&dakota_parameter);
+				xDelete<int>(dakota_parameter);
 			}
 		}
@@ -166,5 +166,5 @@
 				}
 				if(m){
-					matrix=(double*)xcalloc(5*m,sizeof(double));
+					matrix=xNewZeroInit<double>(5*m);
 					count=0;
 					for(j=0;j<temp_m;j++){
@@ -185,5 +185,5 @@
 
 				/*Free temporary matrix: */
-				xfree((void**)&temp_matrix);
+				xDelete<double>(temp_matrix);
 			}
 
@@ -194,9 +194,9 @@
 			for(i=0;i<qmu_mass_flux_num_profiles;i++){
 				double* matrix=array[i];
-				xfree((void**)&matrix);
-			}
-			xfree((void**)&mdims_array); 
-			xfree((void**)&ndims_array);
-			xfree((void**)&array);
+				xDelete<double>(matrix);
+			}
+			xDelete<int>(mdims_array); 
+			xDelete<int>(ndims_array);
+			xDelete<double*>(array);
 		}
 		/*}}}*/
@@ -204,23 +204,23 @@
 		for(i=0;i<numresponsedescriptors;i++){
 			descriptor=responsedescriptors[i];
-			xfree((void**)&descriptor);
-		}
-		xfree((void**)&responsedescriptors);
+			xDelete<char>(descriptor);
+		}
+		xDelete<char*>(responsedescriptors);
 
 		for(i=0;i<numvariabledescriptors;i++){
 			descriptor=variabledescriptors[i];
-			xfree((void**)&descriptor);
-		}
-		xfree((void**)&variabledescriptors);
-		xfree((void**)&part);
-		xfree((void**)&dpart);
-		xfree((void**)&qmuinname);
-		xfree((void**)&qmuerrname);
-		xfree((void**)&qmuoutname);
+			xDelete<char>(descriptor);
+		}
+		xDelete<char*>(variabledescriptors);
+		xDelete<int>(part);
+		xDelete<int>(dpart);
+		xDelete<char>(qmuinname);
+		xDelete<char>(qmuerrname);
+		xDelete<char>(qmuoutname);
 		/*}}}*/
 	} //if(dakota_analysis)
 
 	/*Free data*/
-	xfree((void**)&name);
+	xDelete<char>(name);
 
 	/*Assign output pointer: */
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateConstraintsDiagnosticHoriz.cpp	(revision 12450)
@@ -87,5 +87,5 @@
 
 	/*figure out times: */
-	timesx=(double*)xmalloc(Nx*sizeof(double));
+	timesx=xNew<double>(Nx);
 	for(j=0;j<Nx;j++){
 		timesx[j]=spcvx[(Mx-1)*Nx+j];
@@ -94,5 +94,5 @@
 	UnitConversion(timesx,Nx,ExtToIuEnum,TimeEnum);
 	/*figure out times: */
-	timesy=(double*)xmalloc(Ny*sizeof(double));
+	timesy=xNew<double>(Ny);
 	for(j=0;j<Ny;j++){
 		timesy[j]=spcvy[(My-1)*Ny+j];
@@ -101,5 +101,5 @@
 	UnitConversion(timesy,Ny,ExtToIuEnum,TimeEnum);
 	/*figure out times: */
-	timesz=(double*)xmalloc(Nz*sizeof(double));
+	timesz=xNew<double>(Nz);
 	for(j=0;j<Nz;j++){
 		timesz[j]=spcvz[(Mz-1)*Nz+j];
@@ -107,5 +107,4 @@
 	/*unit conversion: */
 	UnitConversion(timesz,Nz,ExtToIuEnum,TimeEnum);
-
 
 	/*Create spcs from x,y,z, as well as the spc values on those spcs: */
@@ -236,5 +235,5 @@
 				else if (Mx==numberofvertices+1) {
 					/*figure out times and values: */
-					values=(double*)xmalloc(Nx*sizeof(double));
+					values=xNew<double>(Nx);
 					spcpresent=false;
 					for(j=0;j<Nx;j++){
@@ -247,5 +246,5 @@
 						count++;
 					}
-					xfree((void**)&values);
+					xDelete<double>(values);
 				}
 				else if (vertices_type[i]==HutterApproximationEnum){
@@ -260,5 +259,5 @@
 				else if (My==numberofvertices+1){
 					/*figure out times and values: */
-					values=(double*)xmalloc(Ny*sizeof(double));
+					values=xNew<double>(Ny);
 					spcpresent=false;
 					for(j=0;j<Ny;j++){
@@ -270,5 +269,5 @@
 						count++;
 					}
-					xfree((void**)&values);
+					xDelete<double>(values);
 				}
 				else if (vertices_type[i]==HutterApproximationEnum){
@@ -284,5 +283,5 @@
 					else if (Mz==numberofvertices+1){
 						/*figure out times and values: */
-						values=(double*)xmalloc(Nz*sizeof(double));
+						values=xNew<double>(Nz);
 						spcpresent=false;
 						for(j=0;j<Nz;j++){
@@ -294,5 +293,5 @@
 							count++;
 						}
-						xfree((void**)&values);
+						xDelete<double>(values);
 					}
 
@@ -326,21 +325,21 @@
 	  
 	/*Free data: */
-	xfree((void**)&spcvx);
-	xfree((void**)&spcvy);
-	xfree((void**)&spcvz);
-	xfree((void**)&nodeonmacayeal);
-	xfree((void**)&nodeonpattyn);
-	xfree((void**)&nodeonstokes);
-	xfree((void**)&nodeonicesheet);
-	xfree((void**)&nodeonbed);
-	xfree((void**)&vertices_type);
-	xfree((void**)&surface);
-	xfree((void**)&z);
+	xDelete<double>(spcvx);
+	xDelete<double>(spcvy);
+	xDelete<double>(spcvz);
+	xDelete<double>(nodeonmacayeal);
+	xDelete<double>(nodeonpattyn);
+	xDelete<double>(nodeonstokes);
+	xDelete<double>(nodeonicesheet);
+	xDelete<double>(nodeonbed);
+	xDelete<double>(vertices_type);
+	xDelete<double>(surface);
+	xDelete<double>(z);
 
 	/*Free resources:*/
-	xfree((void**)&timesx);
-	xfree((void**)&timesy);
-	xfree((void**)&timesz);
-	xfree((void**)&values);
+	xDelete<double>(timesx);
+	xDelete<double>(timesy);
+	xDelete<double>(timesz);
+	xDelete<double>(values);
 
 	/*Assign output pointer: */
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/DiagnosticHoriz/CreateLoadsDiagnosticHoriz.cpp	(revision 12450)
@@ -120,6 +120,6 @@
 	/*Free data: */
 	iomodel->DeleteData(3,DiagnosticIcefrontEnum,ThicknessEnum,BedEnum);
-	xfree((void**)&elements_type);
-	xfree((void**)&pressureload);
+	xDelete<double>(elements_type);
+	xDelete<double>(pressureload);
 
 	/*Create Penpair for penalties: */
@@ -144,5 +144,5 @@
 
 	/*free ressources: */
-	xfree((void**)&penalties);
+	xDelete<double>(penalties);
 
 	/*Create Riffront loads for rifts: */
@@ -157,5 +157,5 @@
 		}
 		iomodel->DeleteData(5,RiftsRiftstructEnum,ThicknessEnum,BedEnum,SurfaceEnum,MaskVertexonfloatingiceEnum);
-		xfree((void**)&riftfront);
+		xDelete<Riftfront>(riftfront);
 	}
 
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/DistributeNumDofs.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/DistributeNumDofs.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/DistributeNumDofs.cpp	(revision 12450)
@@ -35,5 +35,5 @@
 		else if (vertices_type[0]==MacAyealPattynApproximationEnum){
 			numdofs=4;
-			doftype=(int*)xmalloc(numdofs*sizeof(int));
+			doftype=xNew<int>(numdofs);
 			doftype[0]=MacAyealApproximationEnum;
 			doftype[1]=MacAyealApproximationEnum;
@@ -43,5 +43,5 @@
 		else if (vertices_type[0]==PattynStokesApproximationEnum){
 			numdofs=6;
-			doftype=(int*)xmalloc(numdofs*sizeof(int));
+			doftype=xNew<int>(numdofs);
 			doftype[0]=PattynApproximationEnum;
 			doftype[1]=PattynApproximationEnum;
@@ -53,5 +53,5 @@
 		else if (vertices_type[0]==MacAyealStokesApproximationEnum){
 			numdofs=6;
-			doftype=(int*)xmalloc(numdofs*sizeof(int));
+			doftype=xNew<int>(numdofs);
 			doftype[0]=MacAyealApproximationEnum;
 			doftype[1]=MacAyealApproximationEnum;
@@ -96,4 +96,4 @@
 
 	/*Clean up*/
-	 xfree((void**)&doftype);
+	 xDelete<int>(doftype);
 }
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/ElementsAndVerticesPartitioning.cpp	(revision 12450)
@@ -76,6 +76,6 @@
 
 	/*Free elements and elements2d: */
-	xfree((void**)&elements);
-	xfree((void**)&elements2d);
+	xDelete<double>(elements);
+	xDelete<double>(elements2d);
 
 	/*Deal with rifts, they have to be included into one partition only, not several: */
@@ -87,10 +87,10 @@
 			epart[el2]=epart[el1]; //ensures that this pair of elements will be in the same partition, as well as the corresponding vertices;
 		}
-		xfree((void**)&riftinfo); 
+		xDelete<double>(riftinfo); 
 	}
 
 	/*Used later on: */
-	my_vertices=(int*)xcalloc(numberofvertices,sizeof(int));
-	my_elements=(bool*)xcalloc(numberofelements,sizeof(bool));
+	my_vertices=xNewZeroInit<int>(numberofvertices);
+	my_elements=xNewZeroInit<bool>(numberofelements);
 
 	/*Start figuring out, out of the partition, which elements belong to this cpu: */
@@ -119,5 +119,5 @@
 	}//for (i=0;i<numberofelements;i++)
 	/*Free data : */
-	xfree((void**)&elements);
+	xDelete<double>(elements);
 
 	/*We might have vertex_pairing in which case, some vertices have to be cloned:
@@ -130,5 +130,5 @@
 		}
 	}
-	xfree((void**)&vertex_pairing);
+	xDelete<double>(vertex_pairing);
 	iomodel->FetchData(&vertex_pairing,&numvertex_pairing,NULL,PrognosticVertexPairingEnum);
 	for(i=0;i<numvertex_pairing;i++){
@@ -137,9 +137,9 @@
 		}
 	}
-	xfree((void**)&vertex_pairing);
+	xDelete<double>(vertex_pairing);
 
 	/*Free ressources:*/
-	xfree((void**)&npart);
-	xfree((void**)&epart);
+	xDelete<int>(npart);
+	xDelete<int>(epart);
 
 	/*Assign output pointers:*/
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/Enthalpy/CreateConstraintsEnthalpy.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/Enthalpy/CreateConstraintsEnthalpy.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/Enthalpy/CreateConstraintsEnthalpy.cpp	(revision 12450)
@@ -65,5 +65,5 @@
 
 	/*Free data: */
-	xfree((void**)&spctemperature);
+	xDelete<double>(spctemperature);
 	
 	/*Assign output pointer: */
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/NodesPartitioning.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/NodesPartitioning.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/NodesPartitioning.cpp	(revision 12450)
@@ -24,5 +24,5 @@
 	
 	/*First thing, this is a new partition for a new analysis_type, therefore, to avoid a leak, erase the nodes partition that might come through pmy_nodes: */
-	xfree((void**)pmy_nodes);
+	xDelete<bool>(*pmy_nodes);
 
 	/*Now, depending on whether we are running galerkin discontinous or continuous elements, carry out a different partition of the nodes: */
@@ -44,6 +44,6 @@
 	iomodel->Constant(&numberofvertices,MeshNumberofverticesEnum);
 
-	my_nodes=(bool*)xmalloc(numberofvertices*sizeof(bool));
-	memcpy(my_nodes,my_vertices,numberofvertices*sizeof(bool));
+	my_nodes=xNew<bool>(numberofvertices);
+	for(int i=0;i<numberofvertices;i++) my_nodes[i]=(bool)my_vertices[i];
 
 	/*Assign output pointers:*/
@@ -90,5 +90,5 @@
 
 	/*Allocate*/
-	my_nodes=(bool*)xcalloc(3*numberofelements,sizeof(int));
+	my_nodes=xNewZeroInit<bool>(3*numberofelements);
 
 	/*First: add all the nodes of all the elements belonging to this cpu*/
@@ -96,7 +96,7 @@
 		for (i=0;i<numberofelements;i++){
 			if (my_elements[i]){
-				my_nodes[3*i+0]=1;
-				my_nodes[3*i+1]=1;
-				my_nodes[3*i+2]=1;
+				my_nodes[3*i+0]=true;
+				my_nodes[3*i+1]=true;
+				my_nodes[3*i+2]=true;
 			}
 		}
@@ -140,14 +140,14 @@
 			 * we can now create the corresponding nodes:*/
 			if (pos==0){
-				my_nodes[(int)e2*3+0]=1;
-				my_nodes[(int)e2*3+2]=1;
+				my_nodes[(int)e2*3+0]=true;
+				my_nodes[(int)e2*3+2]=true;
 			}
 			else if(pos==1){
-				my_nodes[(int)e2*3+1]=1;
-				my_nodes[(int)e2*3+0]=1;
+				my_nodes[(int)e2*3+1]=true;
+				my_nodes[(int)e2*3+0]=true;
 			}
 			else if (pos==2){
-				my_nodes[(int)e2*3+2]=1;
-				my_nodes[(int)e2*3+1]=1;
+				my_nodes[(int)e2*3+2]=true;
+				my_nodes[(int)e2*3+1]=true;
 			}
 			else{
@@ -158,6 +158,6 @@
 
 	/*Free data: */
-	xfree((void**)&elements);
-	xfree((void**)&edges);
+	xDelete<double>(elements);
+	xDelete<double>(edges);
 
 	/*Assign output pointers:*/
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/Prognostic/CreateLoadsPrognostic.cpp	(revision 12450)
@@ -90,7 +90,6 @@
 
 	/*free ressources: */
-	xfree((void**)&vertex_pairing);
-	xfree((void**)&nodeonbed);
-
+	xDelete<double>(vertex_pairing);
+	xDelete<double>(nodeonbed);
 
 	/*Assign output pointer: */
Index: /issm/trunk-jpl/src/c/modules/NodeConnectivityx/NodeConnectivityx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/NodeConnectivityx/NodeConnectivityx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/NodeConnectivityx/NodeConnectivityx.cpp	(revision 12450)
@@ -37,5 +37,5 @@
 
 	/*Allocate connectivity: */
-	connectivity=(double*)xcalloc(nods*width,sizeof(double));
+	connectivity=xNewZeroInit<double>(nods*width);
 
 	/*Go through all elements, and for each elements, plug into the connectivity, all the nodes. 
Index: /issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/OutputResultsx/OutputResultsx.cpp	(revision 12450)
@@ -46,5 +46,5 @@
 		EnumToStringx(&solutiontypestring,solutiontype);
 		results->AddObject(new StringExternalResult(results->Size()+1,SolutionTypeEnum,solutiontypestring,1,0));
-		xfree((void**)&solutiontypestring);
+		xDelete<char>(solutiontypestring);
 	}
 
@@ -68,5 +68,5 @@
 			fid=pfopen(cpu_outputfilename ,"wb");
 		}
-		xfree((void**)&outputfilename);
+		xDelete<char>(outputfilename);
 		
 		/*Add file pointer in parameters for further calls to OutputResultsx: */
Index: /issm/trunk-jpl/src/c/modules/ParsePetscOptionsx/ParsePetscOptionsx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ParsePetscOptionsx/ParsePetscOptionsx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/ParsePetscOptionsx/ParsePetscOptionsx.cpp	(revision 12450)
@@ -48,6 +48,6 @@
 
 		/*Now, allocate analyses and strings: */
-		analyses=(double*)xmalloc(numanalyses*sizeof(double));
-		strings=(char**)xmalloc(numanalyses*sizeof(char*));
+		analyses=xNew<double>(numanalyses);
+		strings=xNew<char*>(numanalyses);
 		for(i=0;i<numanalyses;i++)strings[i]=NULL; 
 
@@ -70,5 +70,5 @@
 			to the already existing options*/
 				if(strings[numanalyses-1]==NULL){
-					string=(char*)xmalloc((strlen(line)+1)*sizeof(char)); 
+					string=xNew<char>((strlen(line)+1)); 
 					memcpy(string,line,(strlen(line)+1)*sizeof(char));
 
@@ -77,9 +77,9 @@
 				else{
 					string=strings[numanalyses-1];
-					newstring=(char*)xmalloc((strlen(line)+1)*sizeof(char));
+					newstring=xNew<char>((strlen(line)+1));
 					memcpy(newstring,line,(strlen(line)+1)*sizeof(char));
 
 					/*concatenate:*/
-					catstring=(char*)xmalloc((strlen(string)+1+strlen(newstring)+1+1)*sizeof(char)); //fit in a space " "
+					catstring=xNew<char>(strlen(string)+1+strlen(newstring)+1+1); //fit in a space " "
 					memcpy(catstring,string,(strlen(string)+1)*sizeof(char));
 
@@ -87,6 +87,6 @@
 					strcat(catstring,newstring);
 					strings[numanalyses-1]=catstring;
-					xfree((void**)&newstring);
-					xfree((void**)&string);
+					xDelete<char>(newstring);
+					xDelete<char>(string);
 				}
 			}
@@ -98,6 +98,6 @@
 	MPI_Bcast(&numanalyses,1,MPI_INT,0,MPI_COMM_WORLD);
 	if(my_rank!=0){
-		analyses=(double*)xmalloc(numanalyses*sizeof(double));
-		strings=(char**)xmalloc(numanalyses*sizeof(char*));
+		analyses=xNew<double>(numanalyses);
+		strings=xNew<char*>(numanalyses);
 	}
 	MPI_Bcast(analyses,numanalyses,MPI_DOUBLE,0,MPI_COMM_WORLD);
@@ -111,5 +111,5 @@
 		#ifdef _HAVE_MPI_
 		MPI_Bcast(&stringlength,1,MPI_INT,0,MPI_COMM_WORLD);
-		if(my_rank!=0)string=(char*)xmalloc(stringlength);
+		if(my_rank!=0)string=xNew<char>(stringlength);
 		MPI_Bcast(string,stringlength,MPI_CHAR,0,MPI_COMM_WORLD);
 		if(my_rank!=0)strings[i]=string;
@@ -122,8 +122,7 @@
 
 	/*Clean up and return*/
-	for(i=0;i<numanalyses;i++) xfree((void**)&strings[i]);
-	xfree((void**)&strings);
-	xfree((void**)&analyses);
+	for(i=0;i<numanalyses;i++) xDelete<char>(strings[i]);
+	xDelete<char*>(strings);
+	xDelete<double>(analyses);
 	return;
 }
-
Index: /issm/trunk-jpl/src/c/modules/PointCloudFindNeighborsx/PointCloudFindNeighborsxt.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/PointCloudFindNeighborsx/PointCloudFindNeighborsxt.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/PointCloudFindNeighborsx/PointCloudFindNeighborsxt.cpp	(revision 12450)
@@ -39,5 +39,5 @@
 
 	/*allocate: */
-	already=(bool*)xcalloc(nods,sizeof(bool));
+	already=xNewZeroInit<bool>(nods);
 
 	/*partition loop across threads: */
@@ -73,5 +73,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&already);
+	xDelete<bool>(already);
 	
 	return NULL;
Index: /issm/trunk-jpl/src/c/modules/PositiveDegreeDayx/PositiveDegreeDayx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/PositiveDegreeDayx/PositiveDegreeDayx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/PositiveDegreeDayx/PositiveDegreeDayx.cpp	(revision 12450)
@@ -40,6 +40,6 @@
   Element* element = NULL;
   
-  pdds=(double*)xmalloc(NPDMAX*sizeof(double)+1); 
-  pds=(double*)xmalloc(NPDCMAX*sizeof(double)+1); 
+  pdds=xNew<double>(NPDMAX+1); 
+  pds=xNew<double>(NPDCMAX+1); 
   
   // initialize PDD (creation of a lookup table)
@@ -106,6 +106,6 @@
   }
   /*free ressouces: */
-  xfree((void**)&pdds);
-  xfree((void**)&pds);
+  xDelete<double>(pdds);
+  xDelete<double>(pds);
   
 }
Index: /issm/trunk-jpl/src/c/modules/Reducevectorgtofx/Reducevectorgtofx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Reducevectorgtofx/Reducevectorgtofx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Reducevectorgtofx/Reducevectorgtofx.cpp	(revision 12450)
@@ -51,5 +51,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&ug_serial);
+	xDelete<double>(ug_serial);
 
 	/*Assign output pointers:*/
Index: /issm/trunk-jpl/src/c/modules/Reducevectorgtosx/Reducevectorgtosx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Reducevectorgtosx/Reducevectorgtosx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Reducevectorgtosx/Reducevectorgtosx.cpp	(revision 12450)
@@ -51,5 +51,5 @@
 
 	/*Free ressources:*/
-	xfree((void**)&yg_serial);
+	xDelete<double>(yg_serial);
 
 	/*Assign output pointers:*/
Index: /issm/trunk-jpl/src/c/modules/SetControlInputsFromVectorx/SetControlInputsFromVectorx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/SetControlInputsFromVectorx/SetControlInputsFromVectorx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/SetControlInputsFromVectorx/SetControlInputsFromVectorx.cpp	(revision 12450)
@@ -25,5 +25,5 @@
 	}
 
-	xfree((void**)&control_type);
+	xDelete<int>(control_type);
 }
 
@@ -37,4 +37,4 @@
 
 	/*Free ressources:*/
-	xfree((void**)&serial_vector);
+	xDelete<double>(serial_vector);
 }
Index: /issm/trunk-jpl/src/c/modules/Solverx/DofTypesToIndexSet.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Solverx/DofTypesToIndexSet.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Solverx/DofTypesToIndexSet.cpp	(revision 12450)
@@ -46,6 +46,6 @@
 
 		/*Allocate indices: */
-		if(pressure_num)pressure_indices=(int*)xmalloc(pressure_num*sizeof(int));
-		if(velocity_num)velocity_indices=(int*)xmalloc(velocity_num*sizeof(int));
+		if(pressure_num)pressure_indices=xNew<int>(pressure_num);
+		if(velocity_num)velocity_indices=xNew<int>(velocity_num);
 
 		pressure_count=0;
@@ -74,6 +74,6 @@
 
 	/*Free ressources:*/
-	xfree((void**)&pressure_indices);
-	xfree((void**)&velocity_indices);
+	xDelete<int>(pressure_indices);
+	xDelete<int>(velocity_indices);
 
 	/*Assign output pointers:*/
Index: /issm/trunk-jpl/src/c/modules/Solverx/SolverxGsl.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/Solverx/SolverxGsl.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/Solverx/SolverxGsl.cpp	(revision 12450)
@@ -18,19 +18,8 @@
 void SolverxGsl(SeqVec** puf,SeqMat* Kff, SeqVec* pf){/*{{{*/
 
-	/*Intermediaries*/
-	SeqMat* KffCopy = NULL;
-	SeqVec*  uf = NULL;
-	
-	/*GSL Matrices and vectors: */
-	gsl_matrix_view m;
-	gsl_vector_view b;
-	gsl_vector* x=NULL;
-	gsl_permutation* p=NULL;
-	
-	/*We are going to do an in place LU decomp, so we need to save the matrix with its original structure: */
-	KffCopy=Kff->Duplicate();
-
 	/*Intermediary: */
 	int M,N,N2,s;
+	SeqVec *uf = NULL;
+	double *x  = NULL;
 
 	Kff->GetSize(&M,&N);
@@ -40,24 +29,6 @@
 	if(M!=N)_error_("Stiffness matrix should be square!");
 
-	/*Initialize gsl matrices and vectors: */
-	m = gsl_matrix_view_array (KffCopy->matrix, M, N);
-	b = gsl_vector_view_array (pf->vector, N);
-	x = gsl_vector_alloc (N);
-
-	/*Run LU and solve: */
-	p = gsl_permutation_alloc (N);
-	gsl_linalg_LU_decomp (&m.matrix, p, &s);
-	gsl_linalg_LU_solve (&m.matrix, p, &b.vector, x);
-
-	//printf ("x = \n");
-	//gsl_vector_fprintf (stdout, x, "%g");
-
-	/*Get uf initialized with the results: */
-	uf=new SeqVec(gsl_vector_ptr(x,0),M);
-
-	/*Free resources:*/
-	gsl_permutation_free (p);
-	gsl_vector_free (x);
-	delete KffCopy;
+	SolverxGsl(&x,Kff->matrix,pf->vector,N);
+	uf=new SeqVec(x,N);
 
 	/*Assign output pointers:*/
@@ -74,5 +45,5 @@
 
 	/*A will be modified by LU decomposition. Use copy*/
-	double* Acopy = (double*)xmalloc(n*n*sizeof(double));
+	double* Acopy = xNew<double>(n*n);
 	memcpy(Acopy,A,n*n*sizeof(double));
 
@@ -91,9 +62,9 @@
 
 	/*Copy result*/
-	double* X = (double*)xmalloc(n*sizeof(double));
+	double* X = xNew<double>(n);
 	memcpy(X,gsl_vector_ptr(x,0),n*sizeof(double));
 
 	/*Clean up and assign output pointer*/
-	xfree((void**)&Acopy);
+	xDelete<double>(Acopy);
 	gsl_permutation_free(p);
 	gsl_vector_free(x);
Index: /issm/trunk-jpl/src/c/modules/TriMeshx/TriMeshx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/TriMeshx/TriMeshx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/TriMeshx/TriMeshx.cpp	(revision 12450)
@@ -98,5 +98,5 @@
 	
 	in.segmentlist = xNew<int>(in.numberofsegments*2);
-	in.segmentmarkerlist = (int*)xcalloc(in.numberofsegments,sizeof(int));
+	in.segmentmarkerlist = xNewZeroInit<int>(in.numberofsegments);
 	counter=0;
 	backcounter=0;
Index: /issm/trunk-jpl/src/c/modules/TriaSearchx/TriaSearchx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/TriaSearchx/TriaSearchx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/TriaSearchx/TriaSearchx.cpp	(revision 12450)
@@ -19,5 +19,5 @@
 
 	/*allocate: */
-	tria=(double*)xmalloc(numberofnodes*sizeof(double));
+	tria=xNew<double>(numberofnodes);
 
 	/*Intermediary*/
@@ -52,5 +52,4 @@
 	}
 
-
 	/*Assign output pointers:*/
 	*ptria=tria;
Index: /issm/trunk-jpl/src/c/modules/UpdateDynamicConstraintsx/UpdateDynamicConstraintsx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/UpdateDynamicConstraintsx/UpdateDynamicConstraintsx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/UpdateDynamicConstraintsx/UpdateDynamicConstraintsx.cpp	(revision 12450)
@@ -34,4 +34,4 @@
 
 	/*Free ressources:*/
-	xfree((void**)&yg_serial);
+	xDelete<double>(yg_serial);
 }
Index: /issm/trunk-jpl/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/UpdateVertexPositionsx/UpdateVertexPositionsx.cpp	(revision 12450)
@@ -38,6 +38,6 @@
 
 	/*Free ressources:*/
-	xfree((void**)&thickness);
-	xfree((void**)&bed);
+	xDelete<double>(thickness);
+	xDelete<double>(bed);
 	xdelete(&vz);
 	return 1;
Index: /issm/trunk-jpl/src/c/modules/VecMergex/VecMergex.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/VecMergex/VecMergex.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/modules/VecMergex/VecMergex.cpp	(revision 12450)
@@ -41,5 +41,5 @@
 	}
 	/*Free ressources:*/
-	xfree((void**)&uf_serial);
+	xDelete<double>(uf_serial);
 
 	/*Assemble vector: */
Index: /issm/trunk-jpl/src/c/objects/IoModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/objects/IoModel.cpp	(revision 12449)
+++ /issm/trunk-jpl/src/c/objects/IoModel.cpp	(revision 12450)
@@ -205,5 +205,5 @@
 		dataenum=va_arg(ap, int);
 		_assert_(dataenum<MaximumNumberOfEnums);
-		xfree((void**)&this->data[dataenum]);
+		xDelete<double>(this->data[dataenum]);
 	}
 	va_end(ap);
@@ -691,5 +691,5 @@
 	/*Now allocate matrix: */
 	if(M*N){
-		matrix=(IssmPDouble*)xmalloc(M*N*sizeof(IssmPDouble));
+		matrix=xNew<IssmPDouble>(M*N);
 
 		/*Read matrix on node 0, then broadcast: */
