Index: /issm/trunk-jpl/src/c/Makefile.am
===================================================================
--- /issm/trunk-jpl/src/c/Makefile.am	(revision 22611)
+++ /issm/trunk-jpl/src/c/Makefile.am	(revision 22612)
@@ -77,4 +77,5 @@
 					./classes/Misfit.cpp\
 					./classes/Cfsurfacesquare.cpp\
+					./classes/Cfdragcoeffabsgrad.cpp\
 					./classes/Cfsurfacelogvel.cpp\
 					./classes/Regionaloutput.cpp\
Index: /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.cpp	(revision 22612)
+++ /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.cpp	(revision 22612)
@@ -0,0 +1,195 @@
+/*!\file Cfdragcoeffabsgrad.cpp
+ * \brief: Cfdragcoeffabsgrad Object
+ */
+
+/*Headers:*/
+/*{{{*/
+#ifdef HAVE_CONFIG_H
+   #include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./classes.h"
+#include "./ExternalResults/ExternalResult.h"
+#include "./ExternalResults/Results.h"
+#include "../datastructures/datastructures.h"
+#include "./Elements/Element.h"
+#include "./Elements/Elements.h"
+#include "./FemModel.h"
+#include "../modules/SurfaceAreax/SurfaceAreax.h"
+#include "../classes/Params/Parameters.h"
+#include "../classes/Inputs/Input.h"
+#include "../classes/gauss/Gauss.h"
+/*}}}*/
+		
+/*Cfdragcoeffabsgrad constructors, destructors :*/
+Cfdragcoeffabsgrad::Cfdragcoeffabsgrad(){/*{{{*/
+
+	this->definitionenum = -1;
+	this->name = NULL;
+	this->weights_enum = UNDEF;
+	this->misfit=0;
+	this->lock=0;
+	this->datatime=0.;
+	this->timepassedflag = false;
+	this->last_time = 0.;
+
+}
+/*}}}*/
+Cfdragcoeffabsgrad::Cfdragcoeffabsgrad(char* in_name, int in_definitionenum, int in_weights_enum, IssmDouble in_datatime, bool in_timepassedflag){/*{{{*/
+
+	this->definitionenum=in_definitionenum;
+	
+	this->name		= xNew<char>(strlen(in_name)+1);
+	xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
+
+	this->weights_enum=in_weights_enum;
+	this->datatime=in_datatime;
+	this->timepassedflag=in_timepassedflag;
+	
+	this->misfit=0;
+	this->lock=0;
+}
+/*}}}*/
+Cfdragcoeffabsgrad::~Cfdragcoeffabsgrad(){/*{{{*/
+	if(this->name)xDelete(this->name);
+	this->misfit=0;
+	this->lock=0;
+}
+/*}}}*/
+/*Object virtual function resolutoin: */
+Object* Cfdragcoeffabsgrad::copy() {/*{{{*/
+	Cfdragcoeffabsgrad* mf = new Cfdragcoeffabsgrad(this->name,this->definitionenum, this->weights_enum,this->datatime,this->timepassedflag);
+	mf->misfit=this->misfit;
+	mf->lock=this->lock;
+	return (Object*) mf;
+}
+/*}}}*/
+void Cfdragcoeffabsgrad::DeepEcho(void){/*{{{*/
+	this->Echo();
+}
+/*}}}*/
+void Cfdragcoeffabsgrad::Echo(void){/*{{{*/
+	_printf_(" Cfdragcoeffabsgrad: " << name << " " << this->definitionenum << "\n");
+	_printf_("    weights_enum: " << weights_enum << " " << EnumToStringx(weights_enum) << "\n");
+	_printf_("    datatime: " << datatime << "\n");
+	_printf_("	  timepassedflag: "<<timepassedflag<<"\n");
+}
+/*}}}*/
+int Cfdragcoeffabsgrad::Id(void){/*{{{*/
+	return -1;
+}
+/*}}}*/
+void Cfdragcoeffabsgrad::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/
+	_error_("not implemented yet!"); 
+} 
+/*}}}*/
+int Cfdragcoeffabsgrad::ObjectEnum(void){/*{{{*/
+	return CfdragcoeffabsgradEnum;
+}
+/*}}}*/
+/*Definition virtual function resolutoin: */
+int Cfdragcoeffabsgrad::DefinitionEnum(){/*{{{*/
+	return this->definitionenum;
+}
+/*}}}*/
+char* Cfdragcoeffabsgrad::Name(){/*{{{*/
+	char* name2=xNew<char>(strlen(this->name)+1);
+	xMemCpy(name2,this->name,strlen(this->name)+1);
+
+	return name2;
+}
+/*}}}*/
+IssmDouble Cfdragcoeffabsgrad::Response(FemModel* femmodel){/*{{{*/
+	 /*diverse: */
+	 IssmDouble time;
+	 
+	 /*recover time parameters: */
+	 femmodel->parameters->FindParam(&time,TimeEnum);
+	 if(time < last_time) timepassedflag = false;
+	 last_time = time;
+
+		 int i;
+		 IssmDouble J=0.;
+		 IssmDouble J_sum=0.;
+
+	 if(datatime<=time && !timepassedflag){
+		 for(i=0;i<femmodel->elements->Size();i++){
+			 Element* element=(Element*)femmodel->elements->GetObjectByOffset(i);
+			 J+=this->Cfdragcoeffabsgrad_Calculation(element,weights_enum);
+		 }
+
+		 ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
+		 ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
+		 J=J_sum;
+		
+		 timepassedflag = true;
+		 return J;
+	}
+	 else return J;
+ }
+	/*}}}*/
+IssmDouble Cfdragcoeffabsgrad::Cfdragcoeffabsgrad_Calculation(Element* element, int weights_enum){/*{{{*/
+
+	int        domaintype,numcomponents;
+	IssmDouble Jelem=0.;
+	IssmDouble misfit,Jdet;
+	IssmDouble dp[2],weight;
+	IssmDouble* xyz_list = NULL;
+
+	/*Get basal element*/
+	if(!element->IsOnBase()) return 0.;
+
+	/*If on water, return 0: */
+	if(!element->IsIceInElement()) return 0.;
+
+	/*Get problem dimension*/
+	element->FindParam(&domaintype,DomainTypeEnum);
+	switch(domaintype){
+		case Domain2DverticalEnum:   numcomponents   = 1; break;
+		case Domain3DEnum:           numcomponents   = 2; break;
+		case Domain2DhorizontalEnum: numcomponents   = 2; break;
+		default: _error_("not supported yet");
+	}
+
+	/*Spawn surface element*/
+	Element* basalelement = element->SpawnBasalElement();
+
+	/* Get node coordinates*/
+	basalelement->GetVerticesCoordinates(&xyz_list);
+
+	/*Get input if it already exists*/
+	Input*  tempinput = basalelement->GetInput(definitionenum);
+	/*Cast it to a Datasetinput*/
+	if(tempinput->ObjectEnum()!=DatasetInputEnum) _error_("don't know what to do! confused!");
+	DatasetInput* datasetinput = (DatasetInput*)tempinput;
+
+	/*Get the drag from the model*/
+	Input* drag_input=basalelement->GetInput(FrictionCoefficientEnum);	_assert_(drag_input);
+
+	/* Start  looping on the number of gaussian points: */
+	Gauss* gauss=basalelement->NewGauss(2);
+	for(int ig=gauss->begin();ig<gauss->end();ig++){
+
+		gauss->GaussPoint(ig);
+
+		/* Get Jacobian determinant: */
+		basalelement->JacobianDeterminant(&Jdet,xyz_list,gauss);
+
+		/*Get all parameters at gaussian point*/
+		datasetinput->GetInputValue(&weight,gauss,WeightsSurfaceObservationEnum);
+		drag_input->GetInputDerivativeValue(&dp[0],xyz_list,gauss);
+
+		/*Add to cost function*/
+		Jelem+=weight*.5*dp[0]*dp[0]*Jdet*gauss->weight;
+		if(numcomponents==2) Jelem+=weight*.5*dp[1]*dp[1]*Jdet*gauss->weight;
+	}
+
+	/*clean up and Return: */
+	if(domaintype!=Domain2DhorizontalEnum){basalelement->DeleteMaterials(); delete basalelement;};
+	xDelete<IssmDouble>(xyz_list);
+	delete gauss;
+	return Jelem;
+}/*}}}*/
+
Index: /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.h	(revision 22612)
+++ /issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.h	(revision 22612)
@@ -0,0 +1,48 @@
+/*!\file Cfdragcoeffabsgrad.h
+ * \brief: header file for Cfdragcoeffabsgrad object
+ */
+
+#ifndef _CFDRAGCOEFFABSGRAD_H_
+#define _CFDRAGCOEFFABSGRAD_H_
+
+/*Headers:*/
+#include "./Definition.h"
+#include "./FemModel.h"
+
+IssmDouble OutputDefinitionsResponsex(FemModel* femmodel,int output_enum);
+void  GetVectorFromInputsx( IssmDouble** pvector, int* pvector_size, FemModel* femmodel,int name);
+
+class Cfdragcoeffabsgrad: public Object, public Definition{
+
+	public: 
+
+		int         definitionenum;
+		char*       name;
+		int         weights_enum;
+		IssmDouble	datatime;
+		bool			timepassedflag;
+		IssmDouble	last_time;
+		
+		int         lock; // if lock is on, we just return the value stored in "misfit".  this is used so we don't compute misfit past the final_time
+		IssmDouble  misfit; //value carried over in time.
+		
+		/*Cfdragcoeffabsgrad constructors, destructors :*/
+		Cfdragcoeffabsgrad();
+		Cfdragcoeffabsgrad(char* in_name, int in_definitionenum, int in_weights_enum, IssmDouble in_datatime, bool timepassedflag);
+		~Cfdragcoeffabsgrad();
+		
+		/*Object virtual function resolutoin: */
+		Object* copy();
+		void DeepEcho(void);
+		void Echo(void);
+		int Id(void);
+		void Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction);
+		int ObjectEnum(void);
+		
+		/*Definition virtual function resolutoin: */
+		int DefinitionEnum();
+		char* Name();
+		IssmDouble Response(FemModel* femmodel);
+		IssmDouble Cfdragcoeffabsgrad_Calculation(Element* element, int weights_enum);
+};
+#endif  /* _CFDRAGCOEFFABSGRAD_H_ */
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.cpp	(revision 22611)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.cpp	(revision 22612)
@@ -33,4 +33,5 @@
 	this->datatime=0.;
 	this->timepassedflag = false;
+	this->last_time=0.;
 
 }
@@ -105,6 +106,7 @@
 	 /*recover time parameters: */
 	 femmodel->parameters->FindParam(&time,TimeEnum);
-
-/*ELLEN UNFINISHED*/
+	 if(time < last_time) timepassedflag = false;
+	 last_time = time;
+
 		 int i;
 		 IssmDouble J=0.;
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.h	(revision 22611)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.h	(revision 22612)
@@ -3,6 +3,6 @@
  */
 
-#ifndef _CFSURFACESQUARE_H_
-#define _CFSURFACESQUARE_H_
+#ifndef _CFSURFACELOGVEL_H_
+#define _CFSURFACELOGVEL_H_
 
 /*Headers:*/
@@ -21,4 +21,5 @@
 		IssmDouble	datatime;
 		bool			timepassedflag;
+		IssmDouble	last_time;
 		
 		int         lock; // if lock is on, we just return the value stored in "misfit".  this is used so we don't compute misfit past the final_time
@@ -44,3 +45,3 @@
 		IssmDouble Cfsurfacelogvel_Calculation(Element* element, int definitionenum);
 };
-#endif  /* _CFSURFACESQUARE_H_ */
+#endif  /* _CFSURFACELOGVEL_H_ */
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.cpp	(revision 22611)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.cpp	(revision 22612)
@@ -36,4 +36,5 @@
 	this->datatime=0.;
 	this->timepassedflag = false;
+	this->last_time = 0.;
 
 }
@@ -108,5 +109,4 @@
 /*}}}*/
 IssmDouble Cfsurfacesquare::Response(FemModel* femmodel){/*{{{*/
-		 
 	 /*diverse: */
 	 IssmDouble time;
@@ -114,8 +114,11 @@
 	 /*recover time parameters: */
 	 femmodel->parameters->FindParam(&time,TimeEnum);
+	 if(time < last_time) timepassedflag = false;
+	 last_time = time;
 
 		 int i;
 		 IssmDouble J=0.;
 		 IssmDouble J_sum=0.;
+
 	 if(datatime<=time && !timepassedflag){
 		 for(i=0;i<femmodel->elements->Size();i++){
@@ -130,5 +133,5 @@
 		 timepassedflag = true;
 		 return J;
-		}
+	}
 	 else return J;
  }
Index: /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.h	(revision 22611)
+++ /issm/trunk-jpl/src/c/classes/Cfsurfacesquare.h	(revision 22612)
@@ -3,6 +3,6 @@
  */
 
-#ifndef _TIMEMISFIT_H_
-#define _TIMEMISFIT_H_
+#ifndef _CFSURFACESQUARE_H_
+#define _CFSURFACESQUARE_H_
 
 /*Headers:*/
@@ -26,4 +26,5 @@
 		IssmDouble	datatime;
 		bool			timepassedflag;
+		IssmDouble	last_time;
 		
 		int         lock; // if lock is on, we just return the value stored in "misfit".  this is used so we don't compute misfit past the final_time
@@ -49,3 +50,3 @@
 		IssmDouble Cfsurfacesquare_Calculation(Element* element, int model_enum, int observation_enum, int weights_enum);
 };
-#endif  /* _TIMEMISFIT_H_ */
+#endif  /* _CFSURFACESQUARE_H_ */
Index: /issm/trunk-jpl/src/c/classes/classes.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/classes.h	(revision 22611)
+++ /issm/trunk-jpl/src/c/classes/classes.h	(revision 22612)
@@ -21,4 +21,5 @@
 #include "./Numberedcostfunction.h"
 #include "./Cfsurfacesquare.h"
+#include "./Cfdragcoeffabsgrad.h"
 #include "./Cfsurfacelogvel.h"
 #include "./Masscon.h"
Index: /issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp
===================================================================
--- /issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp	(revision 22611)
+++ /issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp	(revision 22612)
@@ -65,5 +65,13 @@
 	/*Recover Arguments*/
 	m1qn3_struct *input_struct = (m1qn3_struct*)dzs;
-	FemModel     *femmodel     = input_struct->femmodel;
+
+	FemModel* femmodel = input_struct->femmodel;
+	int num_responses,num_controls,numberofvertices,solution_type;
+	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
+	
+	if (solution_type == TransientSolutionEnum){
+		femmodel = input_struct->femmodel->copy();
+		}
+
 	IssmPDouble  *Jlist        = input_struct->Jlist;
 	int           JlistM       = input_struct->M;
@@ -73,10 +81,8 @@
 
 	/*Recover some parameters*/
-	int num_responses,num_controls,numberofvertices,solution_type;
 	IssmDouble* scaling_factors = NULL;
 	femmodel->parameters->FindParam(&num_responses,InversionNumCostFunctionsEnum);
 	femmodel->parameters->FindParam(&num_controls,InversionNumControlParametersEnum);
 	femmodel->parameters->FindParam(&scaling_factors,NULL,InversionControlScalingFactorsEnum);
-	femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
 	numberofvertices=femmodel->vertices->NumberOfVertices();
 
@@ -98,5 +104,5 @@
 	simul_starttrace(femmodel);
 
-	/*Set X as our new control input abd as INDEPENDENT!!*/
+	/*Set X as our new control input and as INDEPENDENT*/
 #ifdef _HAVE_AD_
 	IssmDouble* aX=xNew<IssmDouble>(num_controls*numberofvertices,"t");
@@ -112,9 +118,19 @@
 	SetControlInputsFromVectorx(femmodel,aX);
 	xDelete<IssmDouble>(aX);
-
+	
 	/*Compute solution (forward)*/
 	void (*solutioncore)(FemModel*)=NULL;
 	CorePointerFromSolutionEnum(&solutioncore,femmodel->parameters,solution_type);
 	solutioncore(femmodel);
+
+
+	/*Reset the time to zero for next optimization*/
+	if(solution_type==TransientSolutionEnum){
+		IssmDouble restart_time;
+	
+		femmodel->parameters->FindParam(&restart_time,TimesteppingStartTimeEnum);
+		femmodel->parameters->SetParam(restart_time,TimeEnum);
+
+	}
 
 	/*Get Dependents*/
@@ -123,5 +139,6 @@
 	IssmPDouble *dependents;
 	DataSet*    dependent_objects=NULL;
-
+	IssmDouble	J=0.;
+	
 	femmodel->parameters->FindParam(&num_dependents,AutodiffNumDependentsEnum);
 	femmodel->parameters->FindParam(&dependent_objects,AutodiffDependentObjectsEnum);
@@ -131,7 +148,9 @@
 	for(int i=0;i<dependent_objects->Size();i++){
 		DependentObject* dep=(DependentObject*)dependent_objects->GetObjectByOffset(i);
-		dep->Responsex(&output_value,femmodel);
+		if(solution_type==TransientSolutionEnum) output_value = dep->GetValue();
+		if(solution_type!=TransientSolutionEnum) dep->Responsex(&output_value,femmodel);
 		if (my_rank==0) {
 			output_value>>=dependents[i];
+			J+=output_value;
 		}
 	}
@@ -218,5 +237,5 @@
 	/* Ok, now we are going to call the fos_reverse in a loop on the index, from 0 to num_dependents, so
 	 * as to generate num_dependents gradients: */
-	totalgradient=xNewZeroInit<IssmPDouble>(num_independents);
+	totalgradient=xNewZeroInit<IssmPDouble>(num_independents_old);
 
 	for(int aDepIndex=0;aDepIndex<num_dependents_old;aDepIndex++){
@@ -253,5 +272,4 @@
 	/*Broadcast gradient to other ranks*/
 	ISSM_MPI_Bcast(totalgradient,num_independents_old,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm());
-
 	/*Check size of Jlist to avoid crashes*/
 	_assert_((*Jlisti)<JlistM);
@@ -259,14 +277,10 @@
 
 	/*Compute objective function*/
-	IssmDouble* Jtemp = NULL;
-	IssmDouble J;
-	femmodel->CostFunctionx(&J,&Jtemp,NULL);
 	*pf = reCast<double>(J);
 	_printf0_("f(x) = "<<setw(12)<<setprecision(7)<<*pf<<"  |  ");
 
 	/*Record cost function values and delete Jtemp*/
-	for(int i=0;i<num_responses;i++) Jlist[(*Jlisti)*JlistN+i] = reCast<IssmPDouble>(Jtemp[i]);
+	for(int i=0;i<num_responses;i++) Jlist[(*Jlisti)*JlistN+i] = reCast<IssmPDouble>(dependents[i]);
 	Jlist[(*Jlisti)*JlistN+num_responses] = reCast<IssmPDouble>(J);
-	xDelete<IssmDouble>(Jtemp);
 
 	if(*indic==0){
@@ -285,5 +299,5 @@
 
 	/*Compute gradient*/
-	for(long i=0;i<num_independents_old;i++) G[i] = totalgradient[i];
+	for(long i=0;i<num_independents_old;i++)	G[i] = totalgradient[i];
 
 	/*Constrain Gradient*/
@@ -359,5 +373,4 @@
 	Vector<double> *Xpetsc = NULL;
 
-	/*THIS IS WHERE IT FAILS*/
 	GetPassiveVectorFromControlInputsx(&Xpetsc,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"value");
 	X = Xpetsc->ToMPISerial();
@@ -397,9 +410,11 @@
 	/*Initialize Gradient and cost function of M1QN3*/
 	indic = 4; /*gradient required*/
-printf("-------------- file: controladm1qn3_core.cpp line: %i\n",__LINE__); 
+	printf("-------------- file: controladm1qn3_core.cpp line: %i\n",__LINE__); 
 	simul_ad(&indic,&n,X,&f,G,izs,rzs,(void*)&mystruct);
+	printf("-------------- file: controladm1qn3_core.cpp line: %i\n",__LINE__); 
 	/*Estimation of the expected decrease in f during the first iteration*/
 	double df1=f;
 
+printf("-------------- file: controladm1qn3_core.cpp line: %i\n",__LINE__); 
 	/*Call M1QN3 solver*/
 	m1qn3_(simul_ptr,prosca,&ctonbe_,&ctcabe_,
@@ -407,4 +422,5 @@
 				&gttol,normtype,&impres,&io,imode,&omode,&niter,&nsim,iz,dz,&ndz,
 				&reverse,&indic,izs,rzs,(void*)&mystruct);
+	printf("-------------- file: controladm1qn3_core.cpp line: %i\n",__LINE__); 
 	switch(int(omode)){
 		case 0:  _printf0_("   Stop requested (indic = 0)\n"); break;
@@ -420,8 +436,11 @@
 	/*Constrain solution vector*/
 	double  *XL = NULL;
+	printf("-------------- file: controladm1qn3_core.cpp line: %i\n",__LINE__); 
 	double  *XU = NULL;
 	GetPassiveVectorFromControlInputsx(&XL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"lowerbound");
+	printf("-------------- file: controladm1qn3_core.cpp line: %i\n",__LINE__); 
 	GetPassiveVectorFromControlInputsx(&XU,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"upperbound");
 
+	printf("-------------- file: controladm1qn3_core.cpp line: %i\n",__LINE__); 
 	for(int i=0;i<numberofvertices;i++){
 		for(int c=0;c<num_controls;c++){
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp	(revision 22611)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/Control/CreateParametersControl.cpp	(revision 22612)
@@ -86,7 +86,6 @@
 
 				parameters->AddObject(new IntVecParam(InversionControlParametersEnum,ind_enums,num_independent_objects));
-				//iomodel->FetchData(&num_costfunc,"md.numberedcostfunction.num_cost_functions");
+				iomodel->FindConstant(&cm_responses,&num_costfunc,"md.autodiff.dependent_object_names");
 				      _assert_(num_costfunc>0);
-				iomodel->FindConstant(&cm_responses,&num_costfunc,"md.autodiff.dependent_object_names");
 				if(num_costfunc<1) _error_ ("no cost functions found");
 				int* costfunc_enums=xNew<int>(num_costfunc);
Index: /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp	(revision 22611)
+++ /issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp	(revision 22612)
@@ -249,4 +249,69 @@
 				/*}}}*/
 			}
+			else if (output_definition_enums[i]==CfdragcoeffabsgradEnum){
+				/*Deal with cfdragcoeffabsgrad: {{{*/
+				
+				/*cfdragcoeffabsgrad variables: */
+				int          num_cfdragcoeffabsgrads;
+				char**       cfdragcoeffabsgrad_name_s						= NULL;    
+				char**		 cfdragcoeffabsgrad_definitionstring_s		= NULL;    
+				IssmDouble** cfdragcoeffabsgrad_weights_s					= NULL;
+				int*         cfdragcoeffabsgrad_weights_M_s				= NULL;
+				int*         cfdragcoeffabsgrad_weights_N_s				= NULL;
+				char**       cfdragcoeffabsgrad_weights_string_s		= NULL;
+				int*			 cfdragcoeffabsgrad_datatime_s				= NULL;
+
+				/*Fetch name, model_string, observation, observation_string, etc ... (see src/m/classes/cfdragcoeffabsgrad.m): */
+				iomodel->FetchMultipleData(&cfdragcoeffabsgrad_name_s,&num_cfdragcoeffabsgrads,                                                        "md.cfdragcoeffabsgrad.name");
+				iomodel->FetchMultipleData(&cfdragcoeffabsgrad_definitionstring_s,&num_cfdragcoeffabsgrads,                                            "md.cfdragcoeffabsgrad.definitionstring");
+				iomodel->FetchMultipleData(&cfdragcoeffabsgrad_weights_s,&cfdragcoeffabsgrad_weights_M_s,&cfdragcoeffabsgrad_weights_N_s,&num_cfdragcoeffabsgrads,             "md.cfdragcoeffabsgrad.weights");
+				iomodel->FetchMultipleData(&cfdragcoeffabsgrad_weights_string_s,&num_cfdragcoeffabsgrads,                                              "md.cfdragcoeffabsgrad.weights_string");
+				iomodel->FetchMultipleData(&cfdragcoeffabsgrad_datatime_s,&num_cfdragcoeffabsgrads,																	 "md.cfdragcoeffabsgrad.datatime");
+
+				for(j=0;j<num_cfdragcoeffabsgrads;j++){
+
+					int weight_vector_type=0;
+					if ((cfdragcoeffabsgrad_weights_M_s[j]==iomodel->numberofvertices) || (cfdragcoeffabsgrad_weights_M_s[j]==iomodel->numberofvertices+1)){
+						weight_vector_type=1;
+					}
+					else if ((cfdragcoeffabsgrad_weights_M_s[j]==iomodel->numberofelements) || (cfdragcoeffabsgrad_weights_M_s[j]==iomodel->numberofelements+1)){
+						weight_vector_type=2;
+					}
+					else
+					 _error_("cfdragcoeffabsgrad weight size not supported yet");
+
+					/*First create a cfdragcoeffabsgrad object for that specific string (cfdragcoeffabsgrad_model_string_s[j]):*/
+					output_definitions->AddObject(new Cfdragcoeffabsgrad(cfdragcoeffabsgrad_name_s[j],StringToEnumx(cfdragcoeffabsgrad_definitionstring_s[j]),StringToEnumx(cfdragcoeffabsgrad_weights_string_s[j]),cfdragcoeffabsgrad_datatime_s[j],false));
+
+					/*Now, for this particular cfdragcoeffabsgrad object, make sure we plug into the elements: the observation, and the weights.*/
+					for(int k=0;k<elements->Size();k++){
+
+						Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(k));
+						
+						element->DatasetInputAdd(StringToEnumx(cfdragcoeffabsgrad_definitionstring_s[j]),cfdragcoeffabsgrad_weights_s[j], iomodel,cfdragcoeffabsgrad_weights_M_s[j],cfdragcoeffabsgrad_weights_N_s[j],weight_vector_type,StringToEnumx(cfdragcoeffabsgrad_weights_string_s[j]),7,WeightsSurfaceObservationEnum);
+
+					}
+
+				}
+
+				/*Free ressources:*/
+				for(j=0;j<num_cfdragcoeffabsgrads;j++){
+					char* string=NULL;
+					IssmDouble* matrix = NULL;
+
+					string = cfdragcoeffabsgrad_definitionstring_s[j];		xDelete<char>(string);
+					string = cfdragcoeffabsgrad_weights_string_s[j];		xDelete<char>(string);
+					string = cfdragcoeffabsgrad_name_s[j];    xDelete<char>(string);
+					matrix = cfdragcoeffabsgrad_weights_s[j]; xDelete<IssmDouble>(matrix);
+				}
+				xDelete<char*>(cfdragcoeffabsgrad_name_s);
+				xDelete<char*>(cfdragcoeffabsgrad_definitionstring_s);
+				xDelete<IssmDouble*>(cfdragcoeffabsgrad_weights_s);
+				xDelete<int>(cfdragcoeffabsgrad_weights_M_s);
+				xDelete<int>(cfdragcoeffabsgrad_weights_N_s);
+				xDelete<char*>(cfdragcoeffabsgrad_weights_string_s);
+				xDelete<int>(cfdragcoeffabsgrad_datatime_s);
+				/*}}}*/
+			}
 			else if (output_definition_enums[i]==CfsurfacelogvelEnum){
 				/*Deal with cfsurfacelogvel: {{{*/
@@ -552,5 +617,5 @@
 					for(int k=0;k<elements->Size();k++){
 						Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(k));
-						element->DatasetInputCreate(cost_functions_weights[i],cost_functions_weights_M[i],cost_functions_weights_N[i],cost_function_enums,num_cost_functions,iomodel,InversionCostFunctionsCoefficientsEnum);
+						element->DatasetInputCreate(cost_functions_weights[j],cost_functions_weights_M[j],cost_functions_weights_N[j],cost_function_enums,num_cost_functions,iomodel,InversionCostFunctionsCoefficientsEnum);
 					}
 					output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_cost_functions,cost_function_enums));
Index: /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h	(revision 22611)
+++ /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h	(revision 22612)
@@ -636,4 +636,5 @@
 	CfsurfacelogvelEnum,
 	CfsurfacesquareEnum,
+	CfdragcoeffabsgradEnum,
 	ClosedEnum,
 	ColinearEnum,
Index: /issm/trunk-jpl/src/c/shared/Enum/EnumToStringx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Enum/EnumToStringx.cpp	(revision 22611)
+++ /issm/trunk-jpl/src/c/shared/Enum/EnumToStringx.cpp	(revision 22612)
@@ -640,4 +640,5 @@
 		case CfsurfacelogvelEnum : return "Cfsurfacelogvel";
 		case CfsurfacesquareEnum : return "Cfsurfacesquare";
+		case CfdragcoeffabsgradEnum : return "Cfdragcoeffabsgrad";
 		case ClosedEnum : return "Closed";
 		case ColinearEnum : return "Colinear";
Index: /issm/trunk-jpl/src/c/shared/Enum/StringToEnumx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Enum/StringToEnumx.cpp	(revision 22611)
+++ /issm/trunk-jpl/src/c/shared/Enum/StringToEnumx.cpp	(revision 22612)
@@ -655,4 +655,5 @@
 	      else if (strcmp(name,"Cfsurfacelogvel")==0) return CfsurfacelogvelEnum;
 	      else if (strcmp(name,"Cfsurfacesquare")==0) return CfsurfacesquareEnum;
+	      else if (strcmp(name,"Cfdragcoeffabsgrad")==0) return CfdragcoeffabsgradEnum;
 	      else if (strcmp(name,"Closed")==0) return ClosedEnum;
 	      else if (strcmp(name,"Colinear")==0) return ColinearEnum;
@@ -751,9 +752,9 @@
 	      else if (strcmp(name,"HydrologyDCEfficientAnalysis")==0) return HydrologyDCEfficientAnalysisEnum;
 	      else if (strcmp(name,"Hydrologydc")==0) return HydrologydcEnum;
-	      else if (strcmp(name,"HydrologydcEplColapseThickness")==0) return HydrologydcEplColapseThicknessEnum;
          else stage=7;
    }
    if(stage==7){
-	      if (strcmp(name,"HydrologydcEplCompressibility")==0) return HydrologydcEplCompressibilityEnum;
+	      if (strcmp(name,"HydrologydcEplColapseThickness")==0) return HydrologydcEplColapseThicknessEnum;
+	      else if (strcmp(name,"HydrologydcEplCompressibility")==0) return HydrologydcEplCompressibilityEnum;
 	      else if (strcmp(name,"HydrologydcEplConductivity")==0) return HydrologydcEplConductivityEnum;
 	      else if (strcmp(name,"HydrologydcEplInitialThickness")==0) return HydrologydcEplInitialThicknessEnum;
@@ -874,9 +875,9 @@
 	      else if (strcmp(name,"Mumps")==0) return MumpsEnum;
 	      else if (strcmp(name,"NewDamage")==0) return NewDamageEnum;
-	      else if (strcmp(name,"Nodal")==0) return NodalEnum;
          else stage=8;
    }
    if(stage==8){
-	      if (strcmp(name,"Nodalvalue")==0) return NodalvalueEnum;
+	      if (strcmp(name,"Nodal")==0) return NodalEnum;
+	      else if (strcmp(name,"Nodalvalue")==0) return NodalvalueEnum;
 	      else if (strcmp(name,"NodeSId")==0) return NodeSIdEnum;
 	      else if (strcmp(name,"NoneApproximation")==0) return NoneApproximationEnum;
@@ -997,9 +998,9 @@
 	      else if (strcmp(name,"TotalSmbScaled")==0) return TotalSmbScaledEnum;
 	      else if (strcmp(name,"TransientArrayParam")==0) return TransientArrayParamEnum;
-	      else if (strcmp(name,"TransientInput")==0) return TransientInputEnum;
          else stage=9;
    }
    if(stage==9){
-	      if (strcmp(name,"TransientParam")==0) return TransientParamEnum;
+	      if (strcmp(name,"TransientInput")==0) return TransientInputEnum;
+	      else if (strcmp(name,"TransientParam")==0) return TransientParamEnum;
 	      else if (strcmp(name,"TransientSolution")==0) return TransientSolutionEnum;
 	      else if (strcmp(name,"Tria")==0) return TriaEnum;
@@ -1120,9 +1121,9 @@
 	      else if (strcmp(name,"Outputdefinition96")==0) return Outputdefinition96Enum;
 	      else if (strcmp(name,"Outputdefinition97")==0) return Outputdefinition97Enum;
-	      else if (strcmp(name,"Outputdefinition98")==0) return Outputdefinition98Enum;
          else stage=10;
    }
    if(stage==10){
-	      if (strcmp(name,"Outputdefinition99")==0) return Outputdefinition99Enum;
+	      if (strcmp(name,"Outputdefinition98")==0) return Outputdefinition98Enum;
+	      else if (strcmp(name,"Outputdefinition99")==0) return Outputdefinition99Enum;
 	      else if (strcmp(name,"Outputdefinition9")==0) return Outputdefinition9Enum;
 	      else if (strcmp(name,"OutputdefinitionList")==0) return OutputdefinitionListEnum;
Index: /issm/trunk-jpl/src/c/shared/io/Marshalling/IoCodeConversions.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/io/Marshalling/IoCodeConversions.cpp	(revision 22611)
+++ /issm/trunk-jpl/src/c/shared/io/Marshalling/IoCodeConversions.cpp	(revision 22612)
@@ -13,5 +13,5 @@
 	int   input_enum = -1;
 
-	if(strcmp(string_in,"Thickness")==0){
+	if(strcmp(string_in,"Thickness")==0 || strcmp(string_in,"md.geometry.thickness")==0){
 		const char* field = "md.geometry.thickness";
 		input_enum        = ThicknessEnum;
