Index: ../trunk-jpl/src/c/modules/ModelProcessorx/Control/UpdateElementsAndMaterialsControl.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ModelProcessorx/Control/UpdateElementsAndMaterialsControl.cpp	(revision 18675)
+++ ../trunk-jpl/src/c/modules/ModelProcessorx/Control/UpdateElementsAndMaterialsControl.cpp	(revision 18676)
@@ -11,10 +11,10 @@
 void	UpdateElementsAndMaterialsControl(Elements* elements,Materials* materials, IoModel* iomodel){
 
 	/*Intermediary*/
-	int       control;
+	int       control,cost_function;
 	Element  *element = NULL;
 	Material *material = NULL;
-	int       num_control_type;
+	int       num_control_type,num_cost_functions;
 	bool      control_analysis;
 
 	/*Fetch parameters: */
@@ -24,14 +24,20 @@
 	/*Now, return if no control*/
 	if(!control_analysis) return;
 
+	iomodel->FetchData(5,InversionControlParametersEnum,InversionCostFunctionsEnum,InversionCostFunctionsCoefficientsEnum,InversionMinParametersEnum,InversionMaxParametersEnum);
+
 	/*Fetch data needed: */
-	iomodel->FetchDataToInput(elements,InversionVxObsEnum,0.);
-	iomodel->FetchDataToInput(elements,InversionVyObsEnum,0.); 
-	iomodel->FetchDataToInput(elements,InversionThicknessObsEnum,0.);
-	iomodel->FetchDataToInput(elements,InversionSurfaceObsEnum,0.);
+	iomodel->Constant(&num_cost_functions,InversionNumCostFunctionsEnum);
+	for(int i=0;i<num_cost_functions;i++){
+		cost_function= reCast<int,IssmDouble>(iomodel->Data(InversionCostFunctionsEnum)[i]);
+		if(cost_function==ThicknessAbsMisfitEnum) iomodel->FetchDataToInput(elements,InversionThicknessObsEnum,0.);
+		else if(cost_function==SurfaceAbsVelMisfitEnum || cost_function==SurfaceRelVelMisfitEnum || cost_function==SurfaceLogVelMisfitEnum || cost_function==SurfaceLogVxVyMisfitEnum || cost_function==SurfaceAverageVelMisfitEnum){
+			iomodel->FetchDataToInput(elements,InversionVxObsEnum,0.);
+			iomodel->FetchDataToInput(elements,InversionVyObsEnum,0.); 
+		}
+	}
+	//iomodel->FetchDataToInput(elements,InversionSurfaceObsEnum,0.);
 
-	iomodel->FetchData(5,InversionControlParametersEnum,InversionCostFunctionsEnum,InversionCostFunctionsCoefficientsEnum,InversionMinParametersEnum,InversionMaxParametersEnum);
-
 	for(int i=0;i<num_control_type;i++){
 		control = reCast<int,IssmDouble>(iomodel->Data(InversionControlParametersEnum)[i]);
 		switch(control){
