Index: sm/trunk-jpl/src/c/classes/IndependentObject.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/IndependentObject.cpp	(revision 20653)
+++ 	(revision )
@@ -1,216 +1,0 @@
-/*!\file IndependentObject.c
- * \brief: implementation of the IndependentObject object
- */
-
-#ifdef HAVE_CONFIG_H
-	#include <config.h>
-#else
-#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
-#endif
-
-#include "./classes.h"
-#include "../shared/shared.h"
-#include "IoModel.h"
-
-/*IndependentObject constructors and destructor*/
-IndependentObject::IndependentObject(){/*{{{*/
-	this->name=NoneEnum;
-	this->type=0;
-	this->numberofindependents=0;
-}
-/*}}}*/
-IndependentObject::IndependentObject(int in_name, int in_type){/*{{{*/
-
-	this->numberofindependents=0;
-	this->name=in_name;
-	this->type=in_type;
-	if(in_type!=0 && in_type!=1)_error_("cannot create an IndependentObject of type " << in_type);
-
-}
-/*}}}*/
-IndependentObject::~IndependentObject(){ //destructor/*{{{*/
-}
-/*}}}*/
-
-/*Object virtual functions definitions:*/
-void IndependentObject::Echo(void){/*{{{*/
-
-	_printf_("IndependentObject:\n");
-	_printf_("   name: " << EnumToStringx(this->name) << "\n");
-	if(this->type==0)
-		_printf_("   type: scalar\n");
-	else if(this->type==1)
-		_printf_("   type: vertex\n");
-	else
-		_error_(" unknown type: " << this->type);
-	_printf_("   numberofindependents: " << this->numberofindependents << "\n");
-}
-/*}}}*/
-void IndependentObject::DeepEcho(void){/*{{{*/
-	this->Echo();
-}
-/*}}}*/
-int    IndependentObject::Id(void){ return -1; }/*{{{*/
-/*}}}*/
-int IndependentObject::ObjectEnum(void){/*{{{*/
-
-	return IndependentObjectEnum;
-
-}
-/*}}}*/
-Object* IndependentObject::copy(void) { /*{{{*/
-
-	IndependentObject* object=new IndependentObject();
-	object->name=this->name;
-	object->type=this->type;
-	object->numberofindependents=this->numberofindependents;
-
-	return  object;
-} /*}}}*/
-
-/*IndependentObject methods: */
-void IndependentObject::FetchIndependent(IoModel* iomodel,int* pXcount,IssmPDouble* X){ /*{{{*/
-
-	int my_rank;
-	FILE* fid=NULL;
-	int Xcount=0;
-
-	/*recover my_rank:*/
-	my_rank=IssmComm::GetRank();
-
-	/*recover Xcount if X is not NULL:*/
-	if(X)Xcount=*pXcount;
-
-	#ifdef _HAVE_ADOLC_ //cannot come here unless you are running AD mode, from DeclaredIndependents:
-
-	/*Branch according to the type of variable: */
-	if(type==0){ /*scalar: {{{*/
-
-		/*output: */
-		IssmPDouble  pscalar;
-		IssmDouble   scalar; //same as pscalar, except it's an ADOLC independent variable
-		IssmDouble*  scalar_slot=NULL;
-		int      code;
-
-		/*Set file pointer to beginning of the data: */
-		fid=iomodel->SetFilePointerToData(&code,NULL,name);
-
-		if(code!=3)_error_("expecting a IssmDouble for enum " << EnumToStringx(name));
-
-		/*We have to read a scalar from disk. First read the dimensions of the scalar, then the scalar: */
-		if(my_rank==0){
-			if(fread(&pscalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
-
-			/*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!. If we 
-			 *have been supplied an X vector, use it instead of what we just read: */
-			if(X){
-				scalar<<=X[Xcount];
-			}
-			else{
-				scalar<<=pscalar;
-			}
-		}
-
-		ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
-
-		/*Ok, we are almost done. scalar is now an independent variable. We don't want this variable to be fetched again in the 
-		 *future, which would effectively write over the independency in the ADOLC tape! So we are going to keep track of this 
-		 independent variable inthe iomodel->data[name] data slot. Because this data slot holds double*, we allocate a sizeof(double)
-		 space for it: */
-		scalar_slot=xNew<IssmDouble>(1); *scalar_slot=scalar;
-
-		iomodel->data[name]=scalar_slot;
-		iomodel->independents[name]=true;
-
-		/*increment offset into X vector, now that we have read 1 value:*/
-		Xcount++; *pXcount=Xcount;
-
-		//finally, record the number of independents:
-		this->numberofindependents=1;
-
-	} /*}}}*/
-	else if(type==1){ /* vector: {{{*/
-
-		FILE* fid=NULL;
-		int M,N;
-		IssmPDouble* buffer=NULL; //a buffer to read the data from disk
-		IssmDouble* matrix=NULL; //our independent variable
-		int code=0;
-
-		/*Set file pointer to beginning of the data: */
-		fid=iomodel->SetFilePointerToData(&code,NULL,name);
-		if((code!=5) && (code!=6) && (code!=7))_error_("expecting a IssmDouble, integer or boolean matrix for enum " << EnumToStringx(name));
-
-		/*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
-		/*numberofelements: */
-		if(my_rank==0){  
-			if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
-		}
-		ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-		if(my_rank==0){  
-			if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
-		}
-		ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-		/*Now allocate matrix: */
-		if(M*N){
-			buffer=xNew<IssmPDouble>(M*N);
-			matrix=xNew<IssmDouble>(M*N);
-
-			/*Read matrix on node 0, then broadcast: */
-			if(my_rank==0){  
-				if(fread(buffer,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
-
-				/*Now, before we even broadcast this to other nodes, declare the whole matrix as a independent variable!
-				 If we have been supplied an X vector, use it instead of what we just read: */
-				if(X){
-					for (int i=0;i<M*N;i++) matrix[i]<<=X[Xcount+i];  /*<<= ADOLC overloaded operator to declare independent*/
-				}
-				else{
-					for (int i=0;i<M*N;i++) matrix[i]<<=buffer[i];
-				}
-			}
-			ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
-
-			xDelete<IssmPDouble>(buffer);
-		}
-		else _error_("cannot declare the independent variable " << EnumToStringx(name) <<  "if it's empty!");
-
-		/*Ok, we are almost done. Matrix is now a independent matrix. We don't want this matrix to be fetched again in the 
-		 *future, which would effectively write over the independency in the ADOLC tape! So we are going to keep track of this 
-		 independent matrix inthe iomodel->data[name] data slot: */
-		iomodel->data[name]=matrix;
-		iomodel->independents[name]=true;
-
-			
-		/*increment offset into X vector, now that we have read M*N values:*/
-		Xcount+=M*N; *pXcount=Xcount;
-		
-		//Finally, record the number of independents created: 
-		this->numberofindependents=M*N;
-
-	}/*}}}*/
-	else _error_("should not have a type of " << type);
-
-	#endif
-}
-/*}}}*/
-int  IndependentObject::NumIndependents(void){/*{{{*/
-
-	return this->numberofindependents;;
-}
-/*}}}*/
-void IndependentObject::FillIndependents(IssmDouble** data, IssmDouble* xp){/*{{{*/
-
-	/*Branch according to the type of variable: */
-	if(type==0){ /*scalar:*/
-		xp[0]=*(data[name]);
-	}
-	else if(type==1){ /* vector:*/
-		IssmDouble* values=data[name];
-		for(int i=0;i<this->numberofindependents;i++) xp[i]=values[i];
-	}
-	else _error_("should not have a type of " << type);
-}
-/*}}}*/
Index: sm/trunk-jpl/src/c/classes/IndependentObject.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/IndependentObject.h	(revision 20653)
+++ 	(revision )
@@ -1,42 +1,0 @@
-/*!\file: IndependentObject.h
- * \brief prototype for IndependentObject.h
- */ 
-
-#ifndef _INDEPENDENTOBJECT_H_
-#define  _INDEPENDENTOBJECT_H_
-
-/*{{{*/
-#include "../datastructures/datastructures.h"
-#include "../shared/shared.h"
-/*}}}*/
-class IoModel;
-
-class IndependentObject: public Object{
-
-	public:
-
-		int name;
-		int type;  /*0: scalar, 1: vertex*/
-		int numberofindependents;
-
-		/*IndependentObject constructors, destructors {{{*/
-		IndependentObject();
-		IndependentObject(int name, int type);
-		~IndependentObject();
-		/*}}}*/
-		/*Object virtual functions definitions:{{{ */
-		void  Echo();
-		void  DeepEcho();
-		int   Id(); 
-		int   ObjectEnum();
-		Object* copy(void);
-		void Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ _error_("not implemented yet!");};
-		/*}}}*/
-		/*IndependentObject methods: {{{*/
-		void FetchIndependent(IoModel* iomodel,int* pXcount,IssmPDouble* X);
-		int  NumIndependents(void);
-		void FillIndependents(IssmDouble** data, IssmDouble* xp);
-		/*}}}*/
-
-};
-#endif //ifndef _INDEPENDENTOBJECT_H_
Index: /issm/trunk-jpl/src/c/classes/IoModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/IoModel.cpp	(revision 20653)
+++ /issm/trunk-jpl/src/c/classes/IoModel.cpp	(revision 20654)
@@ -27,5 +27,5 @@
 #include "../shared/shared.h"
 
-/*NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW*/
+/*IoConstant class and methods*/
 IoConstant::IoConstant(){/*{{{*/
 	this->isindependent = false;
@@ -69,4 +69,5 @@
 /*}}}*/
 
+/*IoData class and methods*/
 IoData::IoData(){/*{{{*/
 	this->isindependent = false;
@@ -98,289 +99,5 @@
 /*}}}*/
 
-void  IoModel::AddConstant(IoConstant* in_constant){/*{{{*/
-
-	_assert_(in_constant);
-
-	/*Go through dataset of constant and check whether it already exists */
-	vector<IoConstant*>::iterator iter;
-
-	for(iter=constants.begin();iter<constants.end();iter++){
-		if((*iter)->data_enum==in_constant->data_enum){
-			delete in_constant;
-			return;
-		}
-	}
-
-	this->constants.push_back(in_constant);
-}
-/*}}}*/
-void  IoModel::AddConstantIndependent(IoConstant* in_constant){/*{{{*/
-
-	_assert_(in_constant);
-
-	/*Set constant as independent*/
-	in_constant->isindependent = true;
-
-	/*Add to constnats*/
-	this->AddConstant(in_constant);
-}
-/*}}}*/
-void  IoModel::AddData(IoData* in_data){/*{{{*/
-
-	_assert_(in_data);
-
-	/*Go through dataset of data and check whether it already exists */
-	vector<IoData*>::iterator iter;
-
-	for(iter=data.begin();iter<data.end();iter++){
-		if((*iter)->data_enum==in_data->data_enum){
-			delete in_data;
-			return;
-		}
-	}
-
-	this->data.push_back(in_data);
-}
-/*}}}*/
-void  IoModel::AddDataIndependent(IoData* in_data){/*{{{*/
-
-	_assert_(in_data);
-
-	/*Set data as independent*/
-	in_data->isindependent = true;
-
-	/*Add to constnats*/
-	this->AddData(in_data);
-}
-/*}}}*/
-void  IoModel::FetchIndependentConstant(int* pXcount,IssmPDouble* X,int name){/*{{{*/
-
-	/*recover my_rank:*/
-	int my_rank=IssmComm::GetRank();
-
-	/*recover Xcount if X is not NULL:*/
-	int Xcount = 0;
-	if(X) Xcount=*pXcount;
-
-	#ifdef _HAVE_ADOLC_ //cannot come here unless you are running AD mode, from DeclaredIndependents:
-
-	/*output: */
-	IssmPDouble  pscalar;
-	IssmDouble   scalar; //same as pscalar, except it's an ADOLC independent variable
-	int          code;
-
-	/*Set file pointer to beginning of the data: */
-	fid=this->SetFilePointerToData(&code,NULL,name);
-	if(code!=3) _error_("expecting a IssmDouble for enum " << EnumToStringx(name));
-
-	/*We have to read a scalar from disk. First read the dimensions of the scalar, then the scalar: */
-	if(my_rank==0){
-		if(fread(&pscalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
-
-		/*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!. If we 
-		 *have been supplied an X vector, use it instead of what we just read: */
-		if(X){
-			scalar<<=X[Xcount];
-		}
-		else{
-			scalar<<=pscalar;
-		}
-	}
-
-	ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
-	this->AddConstantIndependent(new IoConstant(scalar,name));
-
-	/*increment offset into X vector, now that we have read 1 value:*/
-	Xcount++; *pXcount=Xcount;
-	#endif
-}
-/*}}}*/
-void  IoModel::FetchIndependentData(int* pXcount,IssmPDouble* X,int name){/*{{{*/
-
-	/*recover my_rank:*/
-	int my_rank=IssmComm::GetRank();
-
-	/*recover Xcount if X is not NULL:*/
-	int Xcount = 0;
-	if(X) Xcount=*pXcount;
-
-	#ifdef _HAVE_ADOLC_ //cannot come here unless you are running AD mode, from DeclaredIndependents:
-
-	/*Intermediaries*/
-	int M,N;
-	IssmPDouble* buffer=NULL; //a buffer to read the data from disk
-	IssmDouble* matrix=NULL; //our independent variable
-	int code,layout;
-
-	/*Set file pointer to beginning of the data: */
-	fid=this->SetFilePointerToData(&code,&layout,name);
-	if((code!=5) && (code!=6) && (code!=7))_error_("expecting a IssmDouble, integer or boolean matrix for enum " << EnumToStringx(name));
-
-	/*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
-	/*numberofelements: */
-	if(my_rank==0){  
-		if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
-	}
-	ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-	if(my_rank==0){  
-		if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
-	}
-	ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
-
-	/*Now allocate matrix: */
-	if(M*N){
-		buffer=xNew<IssmPDouble>(M*N);
-		matrix=xNew<IssmDouble>(M*N);
-
-		/*Read matrix on node 0, then broadcast: */
-		if(my_rank==0){  
-			if(fread(buffer,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
-
-			/*Now, before we even broadcast this to other nodes, declare the whole matrix as a independent variable!
-			  If we have been supplied an X vector, use it instead of what we just read: */
-			if(X){
-				for(int i=0;i<M*N;i++) matrix[i]<<=X[Xcount+i];  /*<<= ADOLC overloaded operator to declare independent*/
-			}
-			else{
-				for(int i=0;i<M*N;i++) matrix[i]<<=buffer[i];
-			}
-		}
-		ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
-
-		xDelete<IssmPDouble>(buffer);
-	}
-	else _error_("cannot declare the independent variable " << EnumToStringx(name) <<  "if it's empty!");
-
-	/*Add to data as independent*/
-	this->AddDataIndependent(new IoData(matrix,code,layout,M,N,name));
-
-	/*increment offset into X vector, now that we have read M*N values:*/
-	Xcount+=M*N; *pXcount=Xcount;
-	#endif
-}
-/*}}}*/
-void  IoModel::FindConstant(bool* pvalue,int constant_enum){/*{{{*/
-
-	/*Intermediary*/
-	vector<IoConstant*>::iterator iter;
-
-	for(iter=constants.begin();iter<constants.end();iter++){
-		IoConstant* ioconstant=*iter;
-
-		if(ioconstant->data_enum==constant_enum){
-			ioconstant->constant->GetParameterValue(pvalue);
-			return;
-		}
-	}
-
-	for(vector<IoConstant*>::iterator iter=constants.begin();iter<constants.end();iter++) (*iter)->constant->Echo();
-	_error_("Could not find constant \""<<EnumToStringx(constant_enum) <<"\"");
-}
-/*}}}*/
-void  IoModel::FindConstant(int* pvalue,int constant_enum){/*{{{*/
-
-	/*Intermediary*/
-	vector<IoConstant*>::iterator iter;
-
-	for(iter=constants.begin();iter<constants.end();iter++){
-		IoConstant* ioconstant=*iter;
-
-		if(ioconstant->data_enum==constant_enum){
-			ioconstant->constant->GetParameterValue(pvalue);
-			return;
-		}
-	}
-
-	_error_("Could not find constant \""<<EnumToStringx(constant_enum) <<"\"");
-}
-/*}}}*/
-void  IoModel::FindConstant(IssmDouble* pvalue,int constant_enum){/*{{{*/
-
-	/*Intermediary*/
-	vector<IoConstant*>::iterator iter;
-
-	for(iter=constants.begin();iter<constants.end();iter++){
-		IoConstant* ioconstant=*iter;
-
-		if(ioconstant->data_enum==constant_enum){
-			ioconstant->constant->GetParameterValue(pvalue);
-			return;
-		}
-	}
-
-	_error_("Could not find constant \""<<EnumToStringx(constant_enum) <<"\"");
-}
-/*}}}*/
-void  IoModel::FindConstant(char** pvalue,int constant_enum){/*{{{*/
-
-	/*Intermediary*/
-	vector<IoConstant*>::iterator iter;
-
-	for(iter=constants.begin();iter<constants.end();iter++){
-		IoConstant* ioconstant=*iter;
-
-		if(ioconstant->data_enum==constant_enum){
-			ioconstant->constant->GetParameterValue(pvalue);
-			return;
-		}
-	}
-
-	_error_("Could not find constant \""<<EnumToStringx(constant_enum) <<"\"");
-}
-/*}}}*/
-int   IoModel::NumIndependents(void){/*{{{*/
-
-	/*Initialize output*/
-	int num_independents = 0;
-
-	/*Process constants*/
-	for(vector<IoConstant*>::iterator iter=constants.begin();iter<constants.end();iter++){
-		if((*iter)->isindependent){
-			num_independents+= 1;
-		}
-	}
-
-	/*Process data*/
-	for(vector<IoData*>::iterator iter=data.begin();iter<data.end();iter++){
-		if((*iter)->isindependent){
-			num_independents+= (*iter)->M*(*iter)->N;
-		}
-	}
-
-	/*return*/
-	return num_independents;
-}
-/*}}}*/
-void  IoModel::FillIndependents(IssmDouble* xp){/*{{{*/
-
-	_assert_(xp);
-
-	/*Initialize local num ind*/
-	int local_num_ind = 0;
-
-	/*Process constants*/
-	for(vector<IoConstant*>::iterator iter=constants.begin();iter<constants.end();iter++){
-		if((*iter)->isindependent){
-			(*iter)->constant->GetParameterValue(&xp[local_num_ind]);
-			local_num_ind += 1;
-		}
-	}
-
-	/*Process data*/
-	for(vector<IoData*>::iterator iter=data.begin();iter<data.end();iter++){
-		if((*iter)->isindependent){
-			for(int i=0;i<(*iter)->M*(*iter)->N;i++){
-				xp[local_num_ind+i] = (*iter)->data[i];
-			}
-			local_num_ind += (*iter)->M*(*iter)->N;
-		}
-	}
-
-	_assert_(local_num_ind == this->NumIndependents());
-}
-/*}}}*/
-/*NEW NEW NEW NEW NEW NEW NEW NEW NEW NEW*/
-
+/*IoModel constructors/destructors*/
 IoModel::IoModel(){/*{{{*/
 
@@ -506,4 +223,61 @@
 /*}}}*/
 
+/*IoModel methods*/
+void  IoModel::AddConstant(IoConstant* in_constant){/*{{{*/
+
+	_assert_(in_constant);
+
+	/*Go through dataset of constant and check whether it already exists */
+	vector<IoConstant*>::iterator iter;
+
+	for(iter=constants.begin();iter<constants.end();iter++){
+		if((*iter)->data_enum==in_constant->data_enum){
+			delete in_constant;
+			return;
+		}
+	}
+
+	this->constants.push_back(in_constant);
+}
+/*}}}*/
+void  IoModel::AddConstantIndependent(IoConstant* in_constant){/*{{{*/
+
+	_assert_(in_constant);
+
+	/*Set constant as independent*/
+	in_constant->isindependent = true;
+
+	/*Add to constnats*/
+	this->AddConstant(in_constant);
+}
+/*}}}*/
+void  IoModel::AddData(IoData* in_data){/*{{{*/
+
+	_assert_(in_data);
+
+	/*Go through dataset of data and check whether it already exists */
+	vector<IoData*>::iterator iter;
+
+	for(iter=data.begin();iter<data.end();iter++){
+		if((*iter)->data_enum==in_data->data_enum){
+			delete in_data;
+			return;
+		}
+	}
+
+	this->data.push_back(in_data);
+}
+/*}}}*/
+void  IoModel::AddDataIndependent(IoData* in_data){/*{{{*/
+
+	_assert_(in_data);
+
+	/*Set data as independent*/
+	in_data->isindependent = true;
+
+	/*Add to constnats*/
+	this->AddData(in_data);
+}
+/*}}}*/
 void  IoModel::CheckEnumSync(void){/*{{{*/
 
@@ -589,4 +363,231 @@
 		}
 	}
+}
+/*}}}*/
+void  IoModel::FetchIndependentConstant(int* pXcount,IssmPDouble* X,int name){/*{{{*/
+
+	/*recover my_rank:*/
+	int my_rank=IssmComm::GetRank();
+
+	/*recover Xcount if X is not NULL:*/
+	int Xcount = 0;
+	if(X) Xcount=*pXcount;
+
+	#ifdef _HAVE_ADOLC_ //cannot come here unless you are running AD mode, from DeclaredIndependents:
+
+	/*output: */
+	IssmPDouble  pscalar;
+	IssmDouble   scalar; //same as pscalar, except it's an ADOLC independent variable
+	int          code;
+
+	/*Set file pointer to beginning of the data: */
+	fid=this->SetFilePointerToData(&code,NULL,name);
+	if(code!=3) _error_("expecting a IssmDouble for enum " << EnumToStringx(name));
+
+	/*We have to read a scalar from disk. First read the dimensions of the scalar, then the scalar: */
+	if(my_rank==0){
+		if(fread(&pscalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
+
+		/*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!. If we 
+		 *have been supplied an X vector, use it instead of what we just read: */
+		if(X){
+			scalar<<=X[Xcount];
+		}
+		else{
+			scalar<<=pscalar;
+		}
+	}
+
+	ISSM_MPI_Bcast(&scalar,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
+	this->AddConstantIndependent(new IoConstant(scalar,name));
+
+	/*increment offset into X vector, now that we have read 1 value:*/
+	Xcount++; *pXcount=Xcount;
+	#endif
+}
+/*}}}*/
+void  IoModel::FetchIndependentData(int* pXcount,IssmPDouble* X,int name){/*{{{*/
+
+	/*recover my_rank:*/
+	int my_rank=IssmComm::GetRank();
+
+	/*recover Xcount if X is not NULL:*/
+	int Xcount = 0;
+	if(X) Xcount=*pXcount;
+
+	#ifdef _HAVE_ADOLC_ //cannot come here unless you are running AD mode, from DeclaredIndependents:
+
+	/*Intermediaries*/
+	int M,N;
+	IssmPDouble* buffer=NULL; //a buffer to read the data from disk
+	IssmDouble* matrix=NULL; //our independent variable
+	int code,layout;
+
+	/*Set file pointer to beginning of the data: */
+	fid=this->SetFilePointerToData(&code,&layout,name);
+	if((code!=5) && (code!=6) && (code!=7))_error_("expecting a IssmDouble, integer or boolean matrix for enum " << EnumToStringx(name));
+
+	/*We have to read a matrix from disk. First read the dimensions of the matrix, then the whole matrix: */
+	/*numberofelements: */
+	if(my_rank==0){  
+		if(fread(&M,sizeof(int),1,fid)!=1) _error_("could not read number of rows for matrix ");
+	}
+	ISSM_MPI_Bcast(&M,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+
+	if(my_rank==0){  
+		if(fread(&N,sizeof(int),1,fid)!=1) _error_("could not read number of columns for matrix ");
+	}
+	ISSM_MPI_Bcast(&N,1,ISSM_MPI_INT,0,IssmComm::GetComm()); 
+
+	/*Now allocate matrix: */
+	if(M*N){
+		buffer=xNew<IssmPDouble>(M*N);
+		matrix=xNew<IssmDouble>(M*N);
+
+		/*Read matrix on node 0, then broadcast: */
+		if(my_rank==0){  
+			if(fread(buffer,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
+
+			/*Now, before we even broadcast this to other nodes, declare the whole matrix as a independent variable!
+			  If we have been supplied an X vector, use it instead of what we just read: */
+			if(X){
+				for(int i=0;i<M*N;i++) matrix[i]<<=X[Xcount+i];  /*<<= ADOLC overloaded operator to declare independent*/
+			}
+			else{
+				for(int i=0;i<M*N;i++) matrix[i]<<=buffer[i];
+			}
+		}
+		ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
+
+		xDelete<IssmPDouble>(buffer);
+	}
+	else _error_("cannot declare the independent variable " << EnumToStringx(name) <<  "if it's empty!");
+
+	/*Add to data as independent*/
+	this->AddDataIndependent(new IoData(matrix,code,layout,M,N,name));
+
+	/*increment offset into X vector, now that we have read M*N values:*/
+	Xcount+=M*N; *pXcount=Xcount;
+	#endif
+}
+/*}}}*/
+void  IoModel::FindConstant(bool* pvalue,int constant_enum){/*{{{*/
+
+	/*Intermediary*/
+	vector<IoConstant*>::iterator iter;
+
+	for(iter=constants.begin();iter<constants.end();iter++){
+		IoConstant* ioconstant=*iter;
+
+		if(ioconstant->data_enum==constant_enum){
+			ioconstant->constant->GetParameterValue(pvalue);
+			return;
+		}
+	}
+
+	for(vector<IoConstant*>::iterator iter=constants.begin();iter<constants.end();iter++) (*iter)->constant->Echo();
+	_error_("Could not find constant \""<<EnumToStringx(constant_enum) <<"\"");
+}
+/*}}}*/
+void  IoModel::FindConstant(int* pvalue,int constant_enum){/*{{{*/
+
+	/*Intermediary*/
+	vector<IoConstant*>::iterator iter;
+
+	for(iter=constants.begin();iter<constants.end();iter++){
+		IoConstant* ioconstant=*iter;
+
+		if(ioconstant->data_enum==constant_enum){
+			ioconstant->constant->GetParameterValue(pvalue);
+			return;
+		}
+	}
+
+	_error_("Could not find constant \""<<EnumToStringx(constant_enum) <<"\"");
+}
+/*}}}*/
+void  IoModel::FindConstant(IssmDouble* pvalue,int constant_enum){/*{{{*/
+
+	/*Intermediary*/
+	vector<IoConstant*>::iterator iter;
+
+	for(iter=constants.begin();iter<constants.end();iter++){
+		IoConstant* ioconstant=*iter;
+
+		if(ioconstant->data_enum==constant_enum){
+			ioconstant->constant->GetParameterValue(pvalue);
+			return;
+		}
+	}
+
+	_error_("Could not find constant \""<<EnumToStringx(constant_enum) <<"\"");
+}
+/*}}}*/
+void  IoModel::FindConstant(char** pvalue,int constant_enum){/*{{{*/
+
+	/*Intermediary*/
+	vector<IoConstant*>::iterator iter;
+
+	for(iter=constants.begin();iter<constants.end();iter++){
+		IoConstant* ioconstant=*iter;
+
+		if(ioconstant->data_enum==constant_enum){
+			ioconstant->constant->GetParameterValue(pvalue);
+			return;
+		}
+	}
+
+	_error_("Could not find constant \""<<EnumToStringx(constant_enum) <<"\"");
+}
+/*}}}*/
+int   IoModel::NumIndependents(void){/*{{{*/
+
+	/*Initialize output*/
+	int num_independents = 0;
+
+	/*Process constants*/
+	for(vector<IoConstant*>::iterator iter=constants.begin();iter<constants.end();iter++){
+		if((*iter)->isindependent){
+			num_independents+= 1;
+		}
+	}
+
+	/*Process data*/
+	for(vector<IoData*>::iterator iter=data.begin();iter<data.end();iter++){
+		if((*iter)->isindependent){
+			num_independents+= (*iter)->M*(*iter)->N;
+		}
+	}
+
+	/*return*/
+	return num_independents;
+}
+/*}}}*/
+void  IoModel::FillIndependents(IssmDouble* xp){/*{{{*/
+
+	_assert_(xp);
+
+	/*Initialize local num ind*/
+	int local_num_ind = 0;
+
+	/*Process constants*/
+	for(vector<IoConstant*>::iterator iter=constants.begin();iter<constants.end();iter++){
+		if((*iter)->isindependent){
+			(*iter)->constant->GetParameterValue(&xp[local_num_ind]);
+			local_num_ind += 1;
+		}
+	}
+
+	/*Process data*/
+	for(vector<IoData*>::iterator iter=data.begin();iter<data.end();iter++){
+		if((*iter)->isindependent){
+			for(int i=0;i<(*iter)->M*(*iter)->N;i++){
+				xp[local_num_ind+i] = (*iter)->data[i];
+			}
+			local_num_ind += (*iter)->M*(*iter)->N;
+		}
+	}
+
+	_assert_(local_num_ind == this->NumIndependents());
 }
 /*}}}*/
Index: /issm/trunk-jpl/src/c/classes/classes.h
===================================================================
--- /issm/trunk-jpl/src/c/classes/classes.h	(revision 20653)
+++ /issm/trunk-jpl/src/c/classes/classes.h	(revision 20654)
@@ -15,5 +15,4 @@
 #include "./Profiler.h"
 #include "./DependentObject.h"
-#include "./IndependentObject.h"
 #include "./Segment.h"
 #include "./Massfluxatgate.h"
Index: /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h	(revision 20653)
+++ /issm/trunk-jpl/src/c/shared/Enum/EnumDefinitions.h	(revision 20654)
@@ -189,5 +189,4 @@
 	HydrologySpcheadEnum,
 	HydrologyConductivityEnum,
-	IndependentObjectEnum,
 	InversionControlParametersEnum,
 	InversionControlScalingFactorsEnum,
Index: /issm/trunk-jpl/src/c/shared/Enum/EnumToStringx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Enum/EnumToStringx.cpp	(revision 20653)
+++ /issm/trunk-jpl/src/c/shared/Enum/EnumToStringx.cpp	(revision 20654)
@@ -193,5 +193,4 @@
 		case HydrologySpcheadEnum : return "HydrologySpchead";
 		case HydrologyConductivityEnum : return "HydrologyConductivity";
-		case IndependentObjectEnum : return "IndependentObject";
 		case InversionControlParametersEnum : return "InversionControlParameters";
 		case InversionControlScalingFactorsEnum : return "InversionControlScalingFactors";
Index: /issm/trunk-jpl/src/c/shared/Enum/StringToEnumx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Enum/StringToEnumx.cpp	(revision 20653)
+++ /issm/trunk-jpl/src/c/shared/Enum/StringToEnumx.cpp	(revision 20654)
@@ -196,5 +196,4 @@
 	      else if (strcmp(name,"HydrologySpchead")==0) return HydrologySpcheadEnum;
 	      else if (strcmp(name,"HydrologyConductivity")==0) return HydrologyConductivityEnum;
-	      else if (strcmp(name,"IndependentObject")==0) return IndependentObjectEnum;
 	      else if (strcmp(name,"InversionControlParameters")==0) return InversionControlParametersEnum;
 	      else if (strcmp(name,"InversionControlScalingFactors")==0) return InversionControlScalingFactorsEnum;
@@ -260,9 +259,9 @@
 	      else if (strcmp(name,"DamageStabilization")==0) return DamageStabilizationEnum;
 	      else if (strcmp(name,"DamageMaxiter")==0) return DamageMaxiterEnum;
+	      else if (strcmp(name,"DamageSpcdamage")==0) return DamageSpcdamageEnum;
          else stage=3;
    }
    if(stage==3){
-	      if (strcmp(name,"DamageSpcdamage")==0) return DamageSpcdamageEnum;
-	      else if (strcmp(name,"DamageMaxDamage")==0) return DamageMaxDamageEnum;
+	      if (strcmp(name,"DamageMaxDamage")==0) return DamageMaxDamageEnum;
 	      else if (strcmp(name,"DamageEquivStress")==0) return DamageEquivStressEnum;
 	      else if (strcmp(name,"DamageEvolutionNumRequestedOutputs")==0) return DamageEvolutionNumRequestedOutputsEnum;
@@ -383,9 +382,9 @@
 	      else if (strcmp(name,"TimesteppingTimeStep")==0) return TimesteppingTimeStepEnum;
 	      else if (strcmp(name,"TimesteppingInterpForcings")==0) return TimesteppingInterpForcingsEnum;
+	      else if (strcmp(name,"TransientIssmb")==0) return TransientIssmbEnum;
          else stage=4;
    }
    if(stage==4){
-	      if (strcmp(name,"TransientIssmb")==0) return TransientIssmbEnum;
-	      else if (strcmp(name,"TransientIscoupler")==0) return TransientIscouplerEnum;
+	      if (strcmp(name,"TransientIscoupler")==0) return TransientIscouplerEnum;
 	      else if (strcmp(name,"TransientIsstressbalance")==0) return TransientIsstressbalanceEnum;
 	      else if (strcmp(name,"TransientIsgroundingline")==0) return TransientIsgroundinglineEnum;
@@ -506,9 +505,9 @@
 	      else if (strcmp(name,"ConfigurationType")==0) return ConfigurationTypeEnum;
 	      else if (strcmp(name,"AdjointBalancethicknessAnalysis")==0) return AdjointBalancethicknessAnalysisEnum;
+	      else if (strcmp(name,"AdjointBalancethickness2Analysis")==0) return AdjointBalancethickness2AnalysisEnum;
          else stage=5;
    }
    if(stage==5){
-	      if (strcmp(name,"AdjointBalancethickness2Analysis")==0) return AdjointBalancethickness2AnalysisEnum;
-	      else if (strcmp(name,"AdjointHorizAnalysis")==0) return AdjointHorizAnalysisEnum;
+	      if (strcmp(name,"AdjointHorizAnalysis")==0) return AdjointHorizAnalysisEnum;
 	      else if (strcmp(name,"AnalysisCounter")==0) return AnalysisCounterEnum;
 	      else if (strcmp(name,"DefaultAnalysis")==0) return DefaultAnalysisEnum;
@@ -629,9 +628,9 @@
 	      else if (strcmp(name,"MassconName")==0) return MassconNameEnum;
 	      else if (strcmp(name,"MassconDefinitionenum")==0) return MassconDefinitionenumEnum;
+	      else if (strcmp(name,"MassconLevelset")==0) return MassconLevelsetEnum;
          else stage=6;
    }
    if(stage==6){
-	      if (strcmp(name,"MassconLevelset")==0) return MassconLevelsetEnum;
-	      else if (strcmp(name,"Massconaxpby")==0) return MassconaxpbyEnum;
+	      if (strcmp(name,"Massconaxpby")==0) return MassconaxpbyEnum;
 	      else if (strcmp(name,"MassconaxpbyName")==0) return MassconaxpbyNameEnum;
 	      else if (strcmp(name,"MassconaxpbyDefinitionenum")==0) return MassconaxpbyDefinitionenumEnum;
@@ -752,9 +751,9 @@
 	      else if (strcmp(name,"DeviatoricStressxz")==0) return DeviatoricStressxzEnum;
 	      else if (strcmp(name,"DeviatoricStressyy")==0) return DeviatoricStressyyEnum;
+	      else if (strcmp(name,"DeviatoricStressyz")==0) return DeviatoricStressyzEnum;
          else stage=7;
    }
    if(stage==7){
-	      if (strcmp(name,"DeviatoricStressyz")==0) return DeviatoricStressyzEnum;
-	      else if (strcmp(name,"DeviatoricStresszz")==0) return DeviatoricStresszzEnum;
+	      if (strcmp(name,"DeviatoricStresszz")==0) return DeviatoricStresszzEnum;
 	      else if (strcmp(name,"DeviatoricStresseffective")==0) return DeviatoricStresseffectiveEnum;
 	      else if (strcmp(name,"StrainRate")==0) return StrainRateEnum;
@@ -875,9 +874,9 @@
 	      else if (strcmp(name,"Outputdefinition70")==0) return Outputdefinition70Enum;
 	      else if (strcmp(name,"Outputdefinition71")==0) return Outputdefinition71Enum;
+	      else if (strcmp(name,"Outputdefinition72")==0) return Outputdefinition72Enum;
          else stage=8;
    }
    if(stage==8){
-	      if (strcmp(name,"Outputdefinition72")==0) return Outputdefinition72Enum;
-	      else if (strcmp(name,"Outputdefinition73")==0) return Outputdefinition73Enum;
+	      if (strcmp(name,"Outputdefinition73")==0) return Outputdefinition73Enum;
 	      else if (strcmp(name,"Outputdefinition74")==0) return Outputdefinition74Enum;
 	      else if (strcmp(name,"Outputdefinition75")==0) return Outputdefinition75Enum;
@@ -998,9 +997,9 @@
 	      else if (strcmp(name,"ToolkitsOptionsStrings")==0) return ToolkitsOptionsStringsEnum;
 	      else if (strcmp(name,"QmuErrName")==0) return QmuErrNameEnum;
+	      else if (strcmp(name,"QmuInName")==0) return QmuInNameEnum;
          else stage=9;
    }
    if(stage==9){
-	      if (strcmp(name,"QmuInName")==0) return QmuInNameEnum;
-	      else if (strcmp(name,"QmuOutName")==0) return QmuOutNameEnum;
+	      if (strcmp(name,"QmuOutName")==0) return QmuOutNameEnum;
 	      else if (strcmp(name,"Regular")==0) return RegularEnum;
 	      else if (strcmp(name,"Scaled")==0) return ScaledEnum;
