Index: /issm/trunk-jpl/src/c/classes/IoModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/IoModel.cpp	(revision 18878)
+++ /issm/trunk-jpl/src/c/classes/IoModel.cpp	(revision 18879)
@@ -50,6 +50,9 @@
 }
 /*}}}*/
-IoModel::IoModel(FILE* iomodel_handle){/*{{{*/
-
+IoModel::IoModel(FILE* iomodel_handle,bool trace,IssmPDouble* X){/*{{{*/
+
+	bool autodiff=false;
+	bool iscontrol=false;
+	
 	/*First, keep track of the file handle: */
 	this->fid=iomodel_handle;
@@ -65,10 +68,25 @@
 	 *and prevent them from being erased during successive calls to iomodel->FetchConstants, iomodel->FetchData and 
 	 iomodel->DeleteData:*/
-	this->StartTrace();
-	this->DeclareIndependents();
+	this->StartTrace(trace);
+	this->DeclareIndependents(trace,X);
 
 	/*Initialize and read constants:*/
 	this->constants=new Parameters();
 	this->FetchConstants(); /*this routine goes through the input file, and fetches bools, ints, IssmDoubles and strings only, nothing memory intensive*/
+
+	/*Now some very specific piece of logic. We want to know whether we are going to carry out an autodiff run. There are 
+	 *several cases: either trace is true (which bypasses the isautodiff choice), or trace is false but isautodiff is on, in which 
+	 *case two cases are possible: are we running a control method or not? To make things simpler, we are going to pin down everyting 
+	 *on isautodiff. By the way, we could not do this before we had the constants dataset initialized! {{{*/
+	this->constants->FindParam(&autodiff,AutodiffIsautodiffEnum);
+	this->constants->FindParam(&iscontrol,InversionIscontrolEnum);
+
+	if(trace)autodiff=true;
+	else{
+		if(autodiff && !iscontrol) autodiff=true;
+		else autodiff=false;
+	}
+	this->constants->SetParam(autodiff,AutodiffIsautodiffEnum);
+	/*}}}*/
 
 	/*Initialize permanent data: */
@@ -108,5 +126,5 @@
 
 	/*checks in debugging mode*/
-	#ifdef _ISSM_DEBUG_
+	#if defined(_ISSM_DEBUG_) && !defined(_HAVE_ADOLC_)
 	if(this->data){
 		for(int i=0;i<MaximumNumberOfDefinitionsEnum;i++){
@@ -273,7 +291,8 @@
 }
 /*}}}*/
-void IoModel::StartTrace(void){/*{{{*/
+void IoModel::StartTrace(bool trace){/*{{{*/
 
 	bool autodiff = false;
+	bool iscontrol = false;
 	bool keep=false;
 	IssmDouble gcTriggerRatio;
@@ -287,6 +306,7 @@
 
 	this->FetchData(&autodiff,AutodiffIsautodiffEnum);
-	if(autodiff){
-
+	this->FetchData(&iscontrol,InversionIscontrolEnum);
+
+	if(trace || (autodiff && !iscontrol)){
 		#ifdef _HAVE_ADOLC_
 		/*Retrieve parameters: */
@@ -311,9 +331,11 @@
 }
 /*}}}*/
-void IoModel::DeclareIndependents(void){/*{{{*/
+void IoModel::DeclareIndependents(bool trace,IssmPDouble* X){/*{{{*/
 
 	int  i;
 	bool autodiff = false;
+	bool iscontrol = false;
 	int  num_independent_objects;
+	int  Xcount=0;
 
 	int *names = NULL;
@@ -327,5 +349,7 @@
 
 	this->FetchData(&autodiff,AutodiffIsautodiffEnum);
-	if(autodiff){
+	this->FetchData(&iscontrol,InversionIscontrolEnum);
+	
+	if(trace || (autodiff && !iscontrol)){
 
 		#ifdef _HAVE_ADOLC_
@@ -348,5 +372,5 @@
 
 				/*now go fetch the independent variable: */
-				independent_object->FetchIndependent(this); //supply the pointer to iomodel.
+				independent_object->FetchIndependent(this,&Xcount,X); //supply the pointer to iomodel.
 			}
 			xDelete<int>(names);
Index: /issm/trunk-jpl/src/c/classes/IoModel.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/IoModel.h	(revision 18878)
+++ /issm/trunk-jpl/src/c/classes/IoModel.h	(revision 18879)
@@ -59,5 +59,5 @@
 		~IoModel();
 		IoModel();
-		IoModel(FILE* iomodel_handle);
+		IoModel(FILE* iomodel_handle,bool trace,IssmPDouble* X);
 
 		/*Input/Output*/
@@ -93,6 +93,6 @@
 		FILE*       SetFilePointerToData(int* pcode,int* pvector_type, int data_enum);
 		fpos_t*     SetFilePointersToData(int** pcodes,int** pvector_types, int* pnum_instances, int data_enum);
-		void        DeclareIndependents(void);
-		void        StartTrace(void);
+		void        DeclareIndependents(bool trace,IssmPDouble* X);
+		void        StartTrace(bool trace);
 		void        FetchIndependent(int dependent_enum);
 };
