Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 25214)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 25215)
@@ -6,9 +6,12 @@
 #include "../../shared/shared.h"
 #include "../../toolkits/toolkits.h"
+#include "../../classes/Inputs2/TransientInput2.h"
+#include "../../classes/Inputs2/DatasetInput2.h"
+#include "../../classes/Inputs2/TriaInput2.h"
 #include "../InputUpdateFromMatrixDakotax/InputUpdateFromMatrixDakotax.h"
 #include "../InputUpdateFromConstantx/InputUpdateFromConstantx.h"
 #include "../InputUpdateFromVectorDakotax/InputUpdateFromVectorDakotax.h"
-
-void InputUpdateFromDakotax(FemModel* femmodel,double* variables,char* *variables_descriptors,int numdakotavariables){
+			
+void InputUpdateFromDakotax(FemModel* femmodel,double* variables,char* *variables_descriptors,int numdakotavariables){ /*{{{*/
 
 	int     i,j,k,l;
@@ -166,4 +169,33 @@
 			xDelete<double>(distributed_values);
 		}
+		else if (strncmp(descriptor,"distributed_",12)==0){
+			
+			/*recover partition vector: */
+			variable_partition=variable_partitions[variablecount];
+			npart=variable_partitions_npart[variablecount];
+
+			/*Variable is distributed. Determine root name of variable (ex: distributed_DragCoefficient_1 -> DragCoefficient). 
+			 * Allocate distributed_values and fill the distributed_values with the next npart variables: */
+
+			memcpy(root,strstr(descriptor,"_")+1,(strlen(strstr(descriptor,"_")+1)+1)*sizeof(char));
+			*strstr(root,"_")='\0';
+
+			distributed_values=xNew<double>(npart);
+			for(j=0;j<npart;j++){
+				distributed_values[j]=variables[i+j];
+			}
+
+			//for (int j=0;j<npart;j++)_printf_(j << ":" << distributed_values[j] << "\n");
+			
+			//Call specialty code:
+			InputUpdateSpecialtyCode(femmodel,distributed_values,variable_partition,npart,root);
+			
+			/*increment i to skip the distributed values just collected: */
+			i+=npart-1; //careful, the for loop will add 1.
+			
+			/*Free allocations: */
+			xDelete<double>(parameter);
+			xDelete<double>(distributed_values);
+		}
 		else if (strncmp(descriptor,"indexed_",8)==0){
 			_error_("indexed variables not supported yet!");
@@ -188,3 +220,88 @@
 	xDelete<int>(variable_partitions_nt);
 
-}
+} /*}}}*/
+void  InputUpdateSpecialtyCode(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* variable_partition,int npart,char* root){ //{{{
+
+	/*Here, we put all the code that cannot be handled any other place: */
+	if (strncmp(root,"SurfaceloadModelid",18)==0){
+
+		if(VerboseQmu())_printf_("Updating SurfaceloadModelid MME, with ids: " << "\n");
+		for (int i=0;i<npart;i++)_printf_(distributed_values[i] << " ");
+
+
+		if (femmodel->inputs2->GetInputObjectEnum(SurfaceloadIceThicknessChangeEnum)==DatasetInput2Enum)
+			MmeToInput(femmodel,distributed_values,variable_partition,npart,SurfaceloadIceThicknessChangeEnum, P0Enum);
+
+		if (femmodel->inputs2->GetInputObjectEnum(MaskIceLevelsetEnum)==DatasetInput2Enum)
+			MmeToInput(femmodel,distributed_values,variable_partition,npart,MaskIceLevelsetEnum, P1Enum);
+
+		if (femmodel->inputs2->GetInputObjectEnum(MaskOceanLevelsetEnum)==DatasetInput2Enum)
+			MmeToInput(femmodel,distributed_values,variable_partition,npart,MaskOceanLevelsetEnum, P1Enum);
+
+	}
+	else _error_("InputUpdateSpecialtyCode error message: " << root << " not supported yet!");
+
+}	//}}}
+void  MmeToInput(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* variable_partition,int npart,int rootenum, int interpolationenum){ /*{{{*/
+
+	TransientInput2* transientinput  = NULL;
+	TransientInput2* transientinput2 = NULL;
+	Tria* element                    = NULL;
+	IssmDouble value;
+	IssmDouble* values               = NULL;
+	IssmDouble* times                = NULL;
+	int N;
+	int id;
+
+	/*find thickness dataset: */
+	DatasetInput2* datasetinput = femmodel->inputs2->GetDatasetInput2(rootenum);
+
+	/*Initialize new transient input: */
+	transientinput = datasetinput->GetTransientInputByOffset(0); _assert_(transientinput);
+	transientinput->GetAllTimes(&times,&N);
+	femmodel->inputs2->SetTransientInput(DummyEnum,times,N);
+	transientinput2 = femmodel->inputs2->GetTransientInput(DummyEnum);
+		
+	for (int i=0;i<femmodel->elements->Size();i++){
+
+		Tria*   element=xDynamicCast<Tria*>(femmodel->elements->GetObjectByOffset(i));
+
+		if((int)variable_partition[element->Sid()]==-1)id=0; //grab background field
+		else id=distributed_values[(int)variable_partition[element->Sid()]]; //grab partition field
+
+		if (element->Sid()==577 && rootenum==MaskOceanLevelsetEnum)_printf_("577 -> " << id);
+
+		/*recover the right field from the mme: */
+		transientinput = datasetinput->GetTransientInputByOffset(id); _assert_(transientinput);
+
+		/*copy values from the transientinput to the final transientinput2: */
+		for (int j=0;j<N;j++){
+			TriaInput2* tria_input=transientinput->GetTriaInput(j);
+			element->InputServe(tria_input);
+			if(interpolationenum==P0Enum){
+				value=tria_input->element_values[0];
+				transientinput2->AddTriaTimeInput( j,1,&(element->lid),&value,P0Enum); 
+			}
+			else if(interpolationenum==P1Enum){
+
+				/*Get values and lid list*/
+				const int   numvertices     = element->GetNumberOfVertices();
+				int        *vertexlids      = xNew<int>(numvertices);
+				int        *vertexsids      = xNew<int>(numvertices);
+
+				/*Recover vertices ids needed to initialize inputs*/
+				element->GetVerticesLidList(&vertexlids[0]);
+				element->GetVerticesSidList(&vertexsids[0]);
+				values=tria_input->element_values;
+				if (element->Sid()==577 && rootenum==MaskOceanLevelsetEnum)_printf_(" sids: " << vertexsids[0] << " " << vertexsids[1] << " " << vertexsids[2] << " values: " << values[0] << " " << values[1] << " " << values[2] << "\n");
+				transientinput2->AddTriaTimeInput( j,numvertices,vertexlids,values,P1Enum); 
+			}
+		}
+	}
+
+	/*wipe out existing SurfaceloadIceThicknessChangeEnum dataset:*/
+	femmodel->inputs2->ChangeEnum(DummyEnum,rootenum);
+
+	//reconfigure:
+	transientinput2->Configure(femmodel->parameters);
+}	//}}}
Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h	(revision 25214)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h	(revision 25215)
@@ -9,4 +9,7 @@
 
 void  InputUpdateFromDakotax(FemModel* femmodel,double* variables,char* *variables_descriptors,int numvariables);
+void  InputUpdateSpecialtyCode(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* variable_partition,int npart,char* root);
+void  MmeToInput(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* variable_partition,int npart,int rootenum, int interpolationenum);
+
 
 #endif  /* _INPUTUPDATEFROMDAKOTAXX_H */
