Index: /issm/trunk-jpl/src/c/classes/Numberedcostfunction.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Numberedcostfunction.h	(revision 22409)
+++ /issm/trunk-jpl/src/c/classes/Numberedcostfunction.h	(revision 22410)
@@ -38,5 +38,4 @@
 		/*}}}*/
 		Numberedcostfunction(char* in_name, int in_definitionenum,int number_cost_functions_in,int* cost_functions_list_in){/*{{{*/
-
 			_assert_(number_cost_functions_in>0); 
 			_assert_(cost_functions_list_in); 
@@ -108,38 +107,32 @@
 		 IssmDouble Response(FemModel* femmodel){/*{{{*/
 			
+			 _assert_(number_cost_functions>0 && number_cost_functions<1e3); 
 			 /*output:*/
 			 IssmDouble value;
 
 			 /*Intermediary*/
-			 int      num_responses;
-			 int     *responses      = NULL;
 			 Results *cost_functions = NULL;
 
-
-			 /*Recover parameters*/
-			 femmodel->parameters->FindParam(&num_responses,InversionNumCostFunctionsEnum);
-			 femmodel->parameters->FindParam(&responses,NULL,InversionCostFunctionsEnum);
-
 			 /*Get the value of all cost functions*/
-			 femmodel->RequestedOutputsx(&cost_functions,responses,num_responses);
+			 femmodel->RequestedOutputsx(&cost_functions,cost_functions_list,number_cost_functions);
 
 			 /*Get and add all contributions one by one*/
-			 IssmDouble  J=0;
-			 IssmDouble* Jlist = xNew<IssmDouble>(num_responses);
-			 for(int i=0;i<num_responses;i++){
+			 IssmDouble  J=0.;
+			 IssmDouble* Jlist = xNew<IssmDouble>(number_cost_functions);
+			 for(int i=0;i<number_cost_functions;i++){
 				 ExternalResult* result=(ExternalResult*)cost_functions->GetObjectByOffset(i);
 				 Jlist[i] = reCast<IssmDouble>(result->GetValue());
 				 J       += Jlist[i];
 			 }
-			 _assert_(cost_functions->Size()==num_responses);
+			 _assert_(cost_functions->Size()==number_cost_functions);
 			 
 			 
 			value = J;		
 			_printf_("J: "<<J<<"\n");
-			 
-			// _error_("STOP!");
 
 			 /*done:*/
-			 return value;
+			delete  cost_functions;
+			xDelete<IssmDouble>(Jlist);
+			return value;
 		 }
 		 /*}}}*/
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp	(revision 22409)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp	(revision 22410)
@@ -182,5 +182,4 @@
 				for(j=0;j<numnodalvalues;j++){
 					char* string=NULL;
-					IssmDouble* matrix = NULL;
 					string = nodalvalue_name_s[j];    xDelete<char>(string);
 				}
@@ -322,9 +321,7 @@
 				char **ncf_name_s             = NULL;
 				char **ncf_definitionstring_s = NULL;
+				char **cost_functions         = NULL;
 				int    cost_function ,domaintype;
 				int    num_cost_functions;
-				char **cost_functions         = NULL;
-				int    num_costfunc;
-				char **cm_responses           = NULL;
 
 				/*Process cost functions and convert from string to enums*/
@@ -337,5 +334,5 @@
 				}
 
-				iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");
+				//iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");
 
 				iomodel->FetchMultipleData(&ncf_name_s,&numout,"md.numberedcostfunction.name");
@@ -362,27 +359,23 @@
 				for(j=0;j<numout;j++){
 
-					output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_costfunc,cost_function_enums));
-
-				}
-
-				parameters->AddObject(iomodel->CopyConstantObject("md.inversion.num_cost_functions",InversionNumCostFunctionsEnum));
+					output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_cost_functions,cost_function_enums));
+
+				}
+
 				
-				iomodel->FindConstant(&cm_responses,&num_costfunc,"md.inversion.cost_functions");
-				//if(num_costfunc<1) error ("no cost functions found");
-				int* costfunc_enums=xNew<int>(num_costfunc);
-				for(int i=0;i<num_costfunc;i++){
-						costfunc_enums[i]=StringToEnumx(cm_responses[i]);
-						xDelete<char>(cm_responses[i]);
-					}
-				xDelete<char*>(cm_responses);
-				
-				parameters->AddObject(new IntVecParam(InversionCostFunctionsEnum,costfunc_enums,num_costfunc));
-				xDelete<int>(costfunc_enums);
-
 				/*Free data: */
-				iomodel->DeleteData(1,"md.inversion.cost_functions_coefficients");
+				//iomodel->DeleteData(1,"md.inversion.cost_functions_coefficients");
+				iomodel->DeleteData(2,"md.numberedcostfunction.name","md.numberedcostfunction.definitionstring");
 				xDelete<int>(cost_function_enums);
 				for(int i=0;i<num_cost_functions;i++) xDelete<char>(cost_functions[i]);
 				xDelete<char*>(cost_functions);
+
+				/*Free ressources:*/
+				for(j=0;j<numout;j++){
+					xDelete<char>(ncf_name_s[j]);
+					xDelete<char>(ncf_definitionstring_s[j]);
+				}
+				xDelete<char*>(ncf_name_s);
+				xDelete<char*>(ncf_definitionstring_s);
 			}
 			/*}}}*/
