Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 25257)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp	(revision 25258)
@@ -13,5 +13,5 @@
 #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;
@@ -46,13 +46,82 @@
 
 	/*Go through all dakota descriptors, ex: "rho_ice","thermal_conductivity","thickness1","thickness2", etc ..., and 
-	 * for each descriptor, take the variable value and plug it into the inputs: */
+	 * for each descriptor, take the variable value and plug it into the inputs (more or less :)): 
+	 * We also start with distributed and standard values , as they tend to be used to pluck data from a multi-modle ensemble (mme) 
+	 * which can then be scaled. Doing the scaling first would be impractical, as the entire mme would have to be scaled, 
+	 * which is a waste of time:*/
+
+	variablecount=0;
 	for(i=0;i<numdakotavariables;i++){ //these are the dakota variables, for all partitions. 
 
 		descriptor=variables_descriptors[i];
 	
-		if (VerboseQmu())_printf0_("   updating variable " << descriptor << "\n");
-
-		/*From descriptor, figure out if the variable is scaled, indexed, nodal, or just a simple variable: */
+
+		/*From descriptor, figure out if the variable is scaled, indexed, distributed or just a simple variable: */
+		if (strncmp(descriptor,"scaled_",7)==0){ 
+			/*we are skipping these for now.*/
+			variable_partition=variable_partitions[variablecount];
+			npart=variable_partitions_npart[variablecount];
+			nt=variable_partitions_nt[variablecount];
+				
+			/*increment i to skip the distributed values just collected: */
+			i+=npart*nt-1; //careful, the for loop will add 1.
+		}
+		else if (strncmp(descriptor,"indexed_",8)==0){
+			/*we are skipping these for now.*/
+		}
+		else if (strncmp(descriptor,"nodal_",8)==0){
+			/*we are skipping these for now.*/
+		}
+		
+		else if (strncmp(descriptor,"distributed_",12)==0){
+		
+			if (VerboseQmu())_printf0_("   updating variable " << descriptor << "\n");
+			
+			/*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{
+			/*Ok, standard variable, just update inputs using the variable: */
+			if (VerboseQmu())_printf0_("   updating variable " << descriptor << "\n");
+			InputUpdateFromConstantx(femmodel,variables[i],StringToEnumx(descriptor));
+		}
+		variablecount++;
+	}
+	
+	variablecount=0;
+	/*now deal with scaled variabes:*/
+	for(i=0;i<numdakotavariables;i++){ //these are the dakota variables, for all partitions. 
+
+		descriptor=variables_descriptors[i];
+	
+
+		/*From descriptor, figure out if the variable is scaled, indexed, distributed or just a simple variable: */
 		if (strncmp(descriptor,"scaled_",7)==0){
+		
+			if (VerboseQmu())_printf0_("   updating variable " << descriptor << "\n");
 		
 			/*recover partition vector: */
@@ -61,8 +130,6 @@
 			nt=variable_partitions_nt[variablecount];
 
-			/*Variable is scaled. Determine root name of variable (ex: scaled_DragCoefficient_1 -> DragCoefficient). Allocate distributed_values and fill the 
-			 * distributed_values with the next npart variables: */
-
-			//strcpy(root,strstr(descriptor,"_")+1); *strstr(root,"_")='\0';
+			/* Variable is scaled, determine its root name (ex: scaled_DragCoefficient_1 -> DragCoefficient). Allocate distributed_values and fill the 
+			 * distributed_values with the next npart variables coming from Dakota: */
 			memcpy(root,strstr(descriptor,"_")+1,(strlen(strstr(descriptor,"_")+1)+1)*sizeof(char));
 			*strstr(root,"_")='\0';
@@ -74,91 +141,84 @@
 
 			
-			/*Now, pick up the parameter corresponding to root: */
-			femmodel->parameters->FindParamInDataset(&parameter,&nrows,&ncols,QmuVariableDescriptorsEnum,StringToEnumx(root));
-
-			/*We've got the parameter, we need to update it using the partition vector, and the distributed_values. 
-			 In addition, the parameter can be either a static or transient (nrows+1) vector. Finally, the partition vectors can include
-			 -1 (meaning, don't update). */
-			
-			//_printf_("nrows: " << nrows << " numberofvertices: " << numberofvertices << " numberofelements: " << numberofelements << "\n");
-
-			if(ncols!=nt){
-				/*we are trying to update a col sized transient input by scaling with a matrix of col size nt. This can only work if nt==1, otherwise, error out: */
-				if (nt!=1) _error_("InputUpdateFromDakotax error message: transient input being updated should be the same col size as the number of time step in the qmu variable specificationi");
-			}
-
-			if(nt==1){
-				/*scale all the columns by the same vector:*/
-				if (nrows==numberofvertices || nrows==(numberofvertices+1)){
-					for(k=0;k<numberofvertices;k++){
-						if (variable_partition[k]==-1)continue;
-						else{
-							for(l=0;l<ncols;l++){
-								*(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]];
+			int inputscaling=0;
+			if(!inputscaling){
+				/*Scale variable outside of the inputs:{{{*/
+
+				/*Now, pick up the parameter corresponding to root: */   
+				femmodel->parameters->FindParamInDataset(&parameter,&nrows,&ncols,QmuVariableDescriptorsEnum,StringToEnumx(root));
+
+				/*We've got the parameter, we need to update it using the partition vector, and the distributed_values. 
+				 In addition, the parameter can be either a static or transient (nrows+1) vector. Finally, the partition vectors can include
+				 -1 (meaning, don't update). */
+				
+				//_printf_("nrows: " << nrows << " numberofvertices: " << numberofvertices << " numberofelements: " << numberofelements << "\n");
+
+				if(ncols!=nt){
+					/*we are trying to update a col sized transient input by scaling with a matrix of col size nt. This can only work if nt==1, otherwise, error out: */
+					if (nt!=1) _error_("InputUpdateFromDakotax error message: transient input being updated should be the same col size as the number of time step in the qmu variable specificationi");
+				}
+
+				if(nt==1){
+					/*scale all the columns by the same vector:*/
+					if (nrows==numberofvertices || nrows==(numberofvertices+1)){
+						for(k=0;k<numberofvertices;k++){
+							if (variable_partition[k]==-1)continue;
+							else{
+								for(l=0;l<ncols;l++){
+									*(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]];
+								}
 							}
 						}
 					}
+					else if (nrows==numberofelements || nrows==(numberofelements+1)){
+						for(k=0;k<numberofelements;k++){
+							if (variable_partition[k]==-1)continue;
+							else{
+								for(l=0;l<ncols;l++){
+									*(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]];
+								}
+							}
+						}
+
+					}
+					else _error_("partitioning vector should be either elements or vertex sized!");
+
 				}
-				else if (nrows==numberofelements || nrows==(numberofelements+1)){
-					for(k=0;k<numberofelements;k++){
-						if (variable_partition[k]==-1)continue;
-						else{
-							for(l=0;l<ncols;l++){
-								*(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]];
+				else{
+					/*scale all the columns by the scalar matrix:*/
+					if (nrows==numberofvertices || nrows==(numberofvertices+1)){
+						for(k=0;k<numberofvertices;k++){
+							if (variable_partition[k]==-1)continue;
+							else{
+								for(l=0;l<ncols;l++){
+									*(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]*nt+l];
+								}
 							}
 						}
 					}
-
-				}
-				else _error_("partitioning vector should be either elements or vertex sized!");
-
-			}
-			else{
-				/*scale all the columns by the scalar matrix:*/
-				if (nrows==numberofvertices || nrows==(numberofvertices+1)){
-					for(k=0;k<numberofvertices;k++){
-						if (variable_partition[k]==-1)continue;
-						else{
-							for(l=0;l<ncols;l++){
-								*(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]*nt+l];
+					else if (nrows==numberofelements || nrows==(numberofelements+1)){
+						for(k=0;k<numberofelements;k++){
+							if (variable_partition[k]==-1)continue;
+							else{
+								for(l=0;l<ncols;l++){
+									*(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]*nt+l];
+								}
 							}
 						}
+
 					}
+					else _error_("partitioning vector should be either elements or vertex sized!");
 				}
-				else if (nrows==numberofelements || nrows==(numberofelements+1)){
-					for(k=0;k<numberofelements;k++){
-						if (variable_partition[k]==-1)continue;
-						else{
-							for(l=0;l<ncols;l++){
-								*(parameter+ncols*k+l)=*(parameter+ncols*k+l)*distributed_values[(int)variable_partition[k]*nt+l];
-							}
-						}
-					}
-
-				}
-				else _error_("partitioning vector should be either elements or vertex sized!");
-			}
-
-			#ifdef _DEBUG_
-				PetscSynchronizedPrintf(IssmComm::GetComm(),"Parameter matrix:");
-				PetscSynchronizedFlush(IssmComm::GetComm());
-				for(l=0;l<ncols;l++){
-					PetscSynchronizedPrintf(IssmComm::GetComm()," time %i\n",l);
-					PetscSynchronizedFlush(IssmComm::GetComm());
-
-					for(k=0;k<numberofvertices;k++){
-						PetscSynchronizedPrintf(IssmComm::GetComm()," node %i value %g\n",k+1,*(parameter+k*ncols+l));
-						PetscSynchronizedFlush(IssmComm::GetComm());
-					}
-				}
-				PetscSynchronizedPrintf(IssmComm::GetComm()," descriptor: %s root %s enum: %i\n",descriptor,root,StringToEnumx(root));
-				PetscSynchronizedFlush(IssmComm::GetComm());
-			#endif
-
-			/*Update inputs using the parameter matrix: */
-			if(nrows==numberofvertices || (nrows==numberofvertices+1))
-				InputUpdateFromMatrixDakotax(femmodel, parameter, nrows,ncols,StringToEnumx(root), VertexEnum);
-			else
-				InputUpdateFromMatrixDakotax(femmodel, parameter, nrows,ncols,StringToEnumx(root), ElementEnum);
+
+				/*Update inputs using the parameter matrix: */
+				if(nrows==numberofvertices || (nrows==numberofvertices+1))
+					InputUpdateFromMatrixDakotax(femmodel, parameter, nrows,ncols,StringToEnumx(root), VertexEnum);
+				else
+					InputUpdateFromMatrixDakotax(femmodel, parameter, nrows,ncols,StringToEnumx(root), ElementEnum); /*}}}*/
+			}
+			else{
+				/*Scale variable inside the inputs:*/
+				InputScaleFromDakotax(femmodel, distributed_values, variable_partition,npart, nt, StringToEnumx(root));
+			}
 
 			/*increment i to skip the distributed values just collected: */
@@ -168,43 +228,4 @@
 			xDelete<double>(parameter);
 			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!");
-		}
-		else if (strncmp(descriptor,"nodal_",8)==0){
-			_error_("nodal variables not supported yet!");
-		}
-		else{
-			/*Ok, standard variable, just update inputs using the variable: */
-			InputUpdateFromConstantx(femmodel,variables[i],StringToEnumx(descriptor));
 		}
 		variablecount++;
@@ -230,5 +251,5 @@
 
 		if(VerboseQmu()){
-			_printf0_("Updating SurfaceloadModelid MME, with ids: ");
+			_printf0_("      SurfaceloadModelid MME, with ids: ");
 			for (int i=0;i<npart;i++)_printf0_((int)distributed_values[i]+1 << " ");
 			_printf0_("\n");
@@ -309,2 +330,19 @@
 	transientinput2->Configure(femmodel->parameters);
 }	//}}}
+void InputScaleFromDakotax(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* partition, int npart, int nt, int name){ /*{{{*/
+
+	/*Copy input:*/
+	femmodel->inputs2->DuplicateInput(name,DummyEnum);
+
+	/*Go through elements, copy input name to dummy, and scale it using the distributed_values and the partition vector:*/
+	for(int i=0;i<femmodel->elements->Size();i++){
+		Element* element=xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
+		element->InputScaleFromDakota(distributed_values,partition,npart,nt,name);
+	}
+
+	/*We created a dummy input, which was a scaled copy of the name input. Now wipe 
+	 * out the name input with the new input:*/
+	femmodel->inputs2->ChangeEnum(DummyEnum,name);
+
+
+} /*}}}*/
Index: /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h
===================================================================
--- /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h	(revision 25257)
+++ /issm/trunk-jpl/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.h	(revision 25258)
@@ -11,4 +11,5 @@
 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);
+void InputScaleFromDakotax(FemModel* femmodel,IssmDouble* distributed_values,IssmDouble* partition, int npart, int nt, int name);
 
 
