Index: ../trunk-jpl/src/c/classes/IndependentObject.cpp
===================================================================
--- ../trunk-jpl/src/c/classes/IndependentObject.cpp	(revision 18870)
+++ ../trunk-jpl/src/c/classes/IndependentObject.cpp	(revision 18871)
@@ -69,14 +69,18 @@
 } /*}}}*/
 
 /*IndependentObject methods: */
-void IndependentObject::FetchIndependent(IoModel* iomodel){/*{{{*/
+void IndependentObject::FetchIndependent(IoModel* iomodel,int* pXcount,IssmPDouble* X){ /*{{{*/
 
 	int my_rank;
 	FILE* fid=NULL;
+	int Xcount;
 
 	/*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: */
@@ -97,8 +101,14 @@
 		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!: */
-			scalar<<=pscalar;
+			/*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()); 
@@ -112,6 +122,9 @@
 		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;
 
@@ -149,8 +162,14 @@
 			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!: */
-				for (int i=0;i<M*N;++i) matrix[i]<<=buffer[i];  /*we use the <<= ADOLC overloaded operator to declare the independency*/
+				/*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];  /*we use the <<= ADOLC overloaded operator to declare the independency*/
+				}
+				else{
+					for (int i=0;i<M*N;++i) matrix[i]<<=buffer[i];  /*we use the <<= ADOLC overloaded operator to declare the independency*/
+				}
 			}
 			ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm()); 
 
@@ -164,6 +183,10 @@
 		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;
 
