Index: /issm/trunk/src/c/DataSet/DataSet.cpp
===================================================================
--- /issm/trunk/src/c/DataSet/DataSet.cpp	(revision 7)
+++ /issm/trunk/src/c/DataSet/DataSet.cpp	(revision 8)
@@ -882,4 +882,5 @@
 	Load* load=NULL;
 	Material* material=NULL;
+	Node* node=NULL;
 
 	for ( object=objects.begin() ; object < objects.end(); object++ ){
@@ -899,4 +900,8 @@
 			material=(Material*)(*object);
 			material->UpdateFromInputs(inputs);
+		}
+		if((*object)->Enum()==NodeEnum()){
+			node=(Node*)(*object);
+			node->UpdateFromInputs(inputs);
 		}		
 	}
Index: /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.cpp
===================================================================
--- /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.cpp	(revision 7)
+++ /issm/trunk/src/c/EnumDefinitions/EnumDefinitions.cpp	(revision 8)
@@ -73,4 +73,2 @@
 	else return 0;
 }
-
-
Index: /issm/trunk/src/c/UpdateFromInputsx/UpdateFromInputsx.cpp
===================================================================
--- /issm/trunk/src/c/UpdateFromInputsx/UpdateFromInputsx.cpp	(revision 7)
+++ /issm/trunk/src/c/UpdateFromInputsx/UpdateFromInputsx.cpp	(revision 8)
@@ -29,4 +29,6 @@
 	elements->UpdateFromInputs(inputs);
 	loads->UpdateFromInputs(inputs);
+	materials->UpdateFromInputs(inputs);
+	nodes->UpdateFromInputs(inputs);
 
 	return noerr;
Index: /issm/trunk/src/c/objects/Matice.cpp
===================================================================
--- /issm/trunk/src/c/objects/Matice.cpp	(revision 7)
+++ /issm/trunk/src/c/objects/Matice.cpp	(revision 8)
@@ -109,5 +109,5 @@
 void  Matice::UpdateFromInputs(ParameterInputs* inputs){
 	
-	throw ErrorException(__FUNCT__," not supported yet!");
+	//throw ErrorException(__FUNCT__," not supported yet!");
 
 }
Index: /issm/trunk/src/c/objects/Matpar.cpp
===================================================================
--- /issm/trunk/src/c/objects/Matpar.cpp	(revision 7)
+++ /issm/trunk/src/c/objects/Matpar.cpp	(revision 8)
@@ -160,5 +160,5 @@
 void  Matpar::UpdateFromInputs(ParameterInputs* inputs){
 	
-	throw ErrorException(__FUNCT__," not supported yet!");
+	//throw ErrorException(__FUNCT__," not supported yet!");
 
 }
Index: /issm/trunk/src/c/objects/Node.cpp
===================================================================
--- /issm/trunk/src/c/objects/Node.cpp	(revision 7)
+++ /issm/trunk/src/c/objects/Node.cpp	(revision 8)
@@ -14,4 +14,5 @@
 #include <string.h>
 #include "../EnumDefinitions/EnumDefinitions.h"
+#include "./ParameterInputs.h"
 #include "../shared/shared.h"
 
@@ -408,2 +409,10 @@
 	return new Node(*this); 
 }
+
+#undef __FUNCT__ 
+#define __FUNCT__ "Node::UpdateFromInputs"
+void  Node::UpdateFromInputs(ParameterInputs* inputs){
+	
+	//throw ErrorException(__FUNCT__," not supported yet!");
+
+}
Index: /issm/trunk/src/c/objects/Node.h
===================================================================
--- /issm/trunk/src/c/objects/Node.h	(revision 7)
+++ /issm/trunk/src/c/objects/Node.h	(revision 8)
@@ -8,4 +8,5 @@
 #include "./Object.h"
 #include "../toolkits/toolkits.h"
+#include "./ParameterInputs.h"
 
 #define MAXDOFSPERNODE 4
@@ -66,4 +67,5 @@
 		double GetZ();
 		Object* copy();
+		void  UpdateFromInputs(ParameterInputs* inputs);
 
 };
Index: /issm/trunk/src/c/objects/OptArgs.h
===================================================================
--- /issm/trunk/src/c/objects/OptArgs.h	(revision 8)
+++ /issm/trunk/src/c/objects/OptArgs.h	(revision 8)
@@ -0,0 +1,28 @@
+/*!\file:  OptArgs.h
+ * \brief place holder for optimization function arguments
+ */ 
+
+#ifndef OPTARGS_H_
+#define OPTARGS_H_
+
+#ifdef _SERIAL_
+
+#include "mex.h"
+
+struct OptArgs{
+
+	char* function_name;
+	mxArray* m;
+	mxArray* p_g;
+	mxArray* u_g_obs;
+	mxArray* grad_g;
+	mxArray* n;
+
+};
+#else
+struct OptArgs{
+
+};
+#endif
+
+#endif
Index: /issm/trunk/src/c/objects/OptPars.h
===================================================================
--- /issm/trunk/src/c/objects/OptPars.h	(revision 8)
+++ /issm/trunk/src/c/objects/OptPars.h	(revision 8)
@@ -0,0 +1,20 @@
+/*!\file:  OptPars.h
+ * \brief place holder for optimization parameters
+ */ 
+
+#ifndef _OPTPARS_H_
+#define _OPTPARS_H_
+
+struct OptPars{
+
+	double xmin;
+	double xmax;
+	double tolerance;
+	int maxiter;
+
+};
+
+#endif
+
+
+						    
Index: /issm/trunk/src/c/objects/objects.h
===================================================================
--- /issm/trunk/src/c/objects/objects.h	(revision 7)
+++ /issm/trunk/src/c/objects/objects.h	(revision 8)
@@ -31,4 +31,6 @@
 #include "./SolverEnum.h"
 #include "./FemModel.h"
+#include "./OptArgs.h"
+#include "./OptPars.h"
 
 #endif
Index: /issm/trunk/src/c/shared/Matlab/matlabshared.h
===================================================================
--- /issm/trunk/src/c/shared/Matlab/matlabshared.h	(revision 7)
+++ /issm/trunk/src/c/shared/Matlab/matlabshared.h	(revision 8)
@@ -5,4 +5,6 @@
 #ifndef _MATLAB_SHARED_H_
 #define _MATLAB_SHARED_H_
+
+#include "../../objects/objects.h"
 
 /*printf: */
Index: /issm/trunk/src/c/shared/Numerics/BrentSearch.cpp
===================================================================
--- /issm/trunk/src/c/shared/Numerics/BrentSearch.cpp	(revision 8)
+++ /issm/trunk/src/c/shared/Numerics/BrentSearch.cpp	(revision 8)
@@ -0,0 +1,251 @@
+/*!\file:  BrentSearch.cpp
+ * \brief optimization algorithm
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./numerics.h"
+#include "../../objects/objects.h"
+#include "../../include/macros.h"
+#include "../../shared/shared.h"
+#include <float.h>
+
+void BrentSearch(double* psearch_scalar,double* pJ,OptPars* optpars,double (*f)(double,OptArgs*), OptArgs* optargs){
+
+	/* This routine is optimizing a given function using Brent's method
+	 * (Golden or parabolic procedure)*/
+
+	/*optimization variable: */
+	double si;
+	double gold;
+	double intervalgold;
+	double oldintervalgold;
+	double parab_num,parab_den;
+	double distance;
+
+	/*function values: */
+	double fxmax,fxmin,fxbest,fval;
+	double fx,fx1,fx2;
+
+	/*x : */
+	double xmax,xmin,xbest;
+	double x,x1,x2,xm,xval;
+
+	/*tolerances: */
+	double tol1,tol2,seps,tolerance;
+	int    maxiter;
+
+	/*counters: */
+	int iter,goldenflag,loop;
+
+	/*Recover parameters:*/
+	xmin=optpars->xmin;
+	xmax=optpars->xmax;
+	tolerance=optpars->tolerance;
+	maxiter=optpars->maxiter;
+	
+	//initialize counter and boundaries
+	iter=0;
+
+	//get the value of the function at the first boundary
+	fxmin = (*f)(xmin,optargs);
+
+	//display result
+	_printf_("\n        Iteration       x           f(x)       Tolerance         Procedure\n\n");
+	_printf_("        %s   %12.6g  %12.6g  %s","   N/A",xmin,fxmin,"         N/A         boundary\n");
+
+	//get the value of the function at the first boundary xmax and display result
+	fxmax = (*f)(xmax,optargs);
+	_printf_("        %s   %12.6g  %12.6g  %s","   N/A",xmax,fxmax,"         N/A         boundary\n");
+
+	//initialize the other variables
+	seps=sqrt(DBL_EPSILON); //precision of a double
+	distance=0.0;              //new_x=old_x + distance
+	gold=0.5*(3.0-sqrt(5.0));  //gold = 1 - golden ratio
+	intervalgold=0.0;          //distance used by Golden procedure
+
+	//Compute initial point
+	
+	//1: initialize the value of the 4 x needed (x1,x2,x,xbest)
+	x1=xmin+gold*(xmax-xmin);
+	x2=x1;
+	xbest=x1;
+	x=xbest;
+
+	//2: call the function to be evaluated
+	fxbest = (*f)(x,optargs);
+	iter=iter+1;
+
+	//3: update the other variables
+	fx1=fxbest;
+	fx2=fxbest;
+	//xm is always in the middle of a and b
+	xm=0.5*(xmin+xmax);                           
+	//update tolerances
+	tol1=seps*sqrt(pow(xbest,2))+tolerance/3.0;
+	tol2=2.0*tol1;
+
+	//4: print result
+	_printf_("         %5i    %12.6g  %12.6g  %12.6g  %s\n",iter,xbest,fxbest,pow(pow(xbest-xm,2),0.5),"       initial");
+
+	//Main Loop
+	loop=1;
+	while(loop){
+
+		goldenflag=1;
+
+		// Is a parabolic fit possible ?
+		if (sqrt(pow(intervalgold,2))>tol1){
+
+			// Yes, so fit parabola
+			goldenflag=0;
+			parab_num=(xbest-x1)*(xbest-x1)*(fxbest-fx2)-(xbest-x2)*(xbest-x2)*(fxbest-fx1);;
+			parab_den=2.0*(xbest-x1)*(fxbest-fx2)-2.0*(xbest-x2)*(fxbest-fx1);
+
+			//reverse p if necessary
+			if(parab_den>0.0){ 
+				parab_num=-parab_num;
+			}
+			parab_den=sqrt(pow(parab_den,2));
+			oldintervalgold=intervalgold;
+			intervalgold=distance;
+
+			// Is the parabola acceptable
+			if (( sqrt(pow(parab_num,2)) < sqrt(pow(0.5*parab_den*oldintervalgold,2))) &&
+						(parab_num>parab_den*(xmin-xbest)) &&
+						(parab_num<parab_den*(xmax-xbest))){
+
+				// Yes, parabolic interpolation step
+				distance=parab_num/parab_den;
+				x=xbest+distance;
+
+				// f must not be evaluated too close to min_x or max_x
+				if (((x-xmin)<tol2) || ((xmax-x)<tol2)){
+
+					if ((xm-xbest)<0.0){
+						si=-1;
+					}
+					else{
+						si=1;
+					}
+
+					//compute new distance
+					distance=tol1*si;
+				}
+			}
+			else{
+
+				// Not acceptable, must do a golden section step
+				goldenflag=1;
+			}
+		}
+
+		//Golden procedure
+		if(goldenflag){
+
+			// compute the new distance d
+			if(xbest>=xm){
+				intervalgold=xmin-xbest;    
+			}
+			else{ 
+				intervalgold=xmax-xbest;  
+			}
+			distance=gold*intervalgold;
+		}
+
+		// The function must not be evaluated too close to xbest
+		if(distance<0){
+			si=-1;
+		}
+		else{
+			si=1;
+		}
+		if (sqrt(pow(distance,2))>tol1){
+			x=xbest+si*sqrt(pow(distance,2));
+		}
+		else{
+			x=xbest+si*tol1;
+		}
+
+		//evaluate function on x
+		fx = (*f)(x,optargs);
+		iter=iter+1;
+
+		// Update a, b, xm, x1, x2, tol1, tol2
+		if (fx<=fxbest){
+			if (x>=xbest){
+				xmin=xbest;
+			}
+			else{
+				xmax=xbest;
+			}
+			x1=x2;    fx1=fx2;
+			x2=xbest; fx2=fxbest;
+			xbest=x;  fxbest=fx;
+		}
+
+		else{ // fx > fxbest
+			if (x < xbest){
+				xmin=x;
+			}
+			else{
+				xmax=x;
+			}
+			if ((fx<=fx2) || (x2==xbest)){
+				x1=x2; fx1=fx2;
+				x2=x;  fx2=fx;
+			}
+			else if ( (fx <= fx1) || (x1 == xbest) || (x1 == x2) ){
+				x1=x;  fx1=fx;
+			}
+		}
+		xm = 0.5*(xmin+xmax);
+		tol1=seps*pow(pow(xbest,2),0.5)+tolerance/3.0;
+		tol2=2.0*tol1;
+
+		//print result
+		if (goldenflag){
+			_printf_("         %5i    %12.6g  %12.6g  %12.6g  %s\n",iter,x,fx,pow(pow(xbest-xm,2),0.5),"       golden");
+		}
+		else{
+			_printf_("         %5i    %12.6g  %12.6g  %12.6g  %s\n",iter,x,fx,pow(pow(xbest-xm,2),0.5),"       parabolic");
+		}
+
+		//Stop the optimization?
+		if (sqrt(pow(xbest-xm,2)) < (tol2-0.5*(xmax-xmin))){
+			_printf_("\nOptimization terminated:\nthe current x satisfies the termination criteria using 'tolx' of %g \n", tolerance);
+			loop=0;
+		}
+		else if (iter>=maxiter){
+			_printf_("\nExiting: Maximum number of iterations has been exceeded  - increase 'maxiter'\n");
+			loop=0;
+		}
+		else{
+			//continue
+			loop=1;
+		}
+	}//end while
+
+	//Now, check that the value on the boundaries are not better than current fxbest
+	if (fxbest>fxmin){
+		xval=xmin;
+		fval=fxmin;
+	}
+	else if (fxbest>fxmax){
+		xval=xmax;
+		fval=fxmax;
+	}
+	else{
+		xval=xbest;
+		fval=fxbest;
+	}
+
+	/*Assign output pointers: */
+	*psearch_scalar=xval;
+	*pJ=fval;
+	
+}
Index: /issm/trunk/src/c/shared/Numerics/OptFunc.cpp
===================================================================
--- /issm/trunk/src/c/shared/Numerics/OptFunc.cpp	(revision 8)
+++ /issm/trunk/src/c/shared/Numerics/OptFunc.cpp	(revision 8)
@@ -0,0 +1,50 @@
+/*!\file:  OptFunc.cpp
+ * \brief: "C" code wrapper to matlab objectivefunctionC call
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include "config.h"
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "../../objects/objects.h"
+#include "../../shared/shared.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__ "OptFunc"
+
+
+#ifdef _SERIAL_
+#include "mex.h"
+double OptFunc(double scalar, OptArgs* optargs){
+	
+	/*output: */
+	double J;
+
+	mxArray*   inputs[6];
+	mxArray*   psearch_scalar=NULL;
+	mxArray*   mxJ=NULL;
+
+
+	psearch_scalar=mxCreateDoubleScalar(scalar);
+	inputs[0]=psearch_scalar;
+	
+	inputs[1]=optargs->m;
+	inputs[2]=optargs->p_g;
+	inputs[3]=optargs->u_g_obs;
+	inputs[4]=optargs->grad_g;
+	inputs[5]=optargs->n;
+
+	mexCallMATLAB( 1, &mxJ, 6, (mxArray**)inputs, optargs->function_name);
+
+	/*extract misfit from mxArray*/
+	J=mxGetScalar(mxJ);
+
+	return J;
+}
+#else
+double OptFunc(double scalar, OptArgs* optargs){
+	throw ErrorException(__FUNCT__," not implemented yet");
+}
+#endif
Index: /issm/trunk/src/c/shared/Numerics/numerics.h
===================================================================
--- /issm/trunk/src/c/shared/Numerics/numerics.h	(revision 7)
+++ /issm/trunk/src/c/shared/Numerics/numerics.h	(revision 8)
@@ -7,7 +7,10 @@
 
 #include "./GaussPoints.h"
+#include "../../objects/objects.h"
 
 double min(double a,double b);
 double max(double a,double b);
+double OptFunc(double scalar, OptArgs* optargs);
+void BrentSearch(double* psearch_scalar,double* pJ,OptPars* optpars,double (*f)(double,OptArgs*), OptArgs* optargs);
 
 #endif //ifndef _NUMERICS_H_
Index: /issm/trunk/src/m/solutions/cielo/control.m
===================================================================
--- /issm/trunk/src/m/solutions/cielo/control.m	(revision 7)
+++ /issm/trunk/src/m/solutions/cielo/control.m	(revision 8)
@@ -48,5 +48,5 @@
 		
 		disp('      optimizing along gradient direction...'); 
-		[search_scalar c(n).J]=fminbnd('objectivefunctionC',-1,1,options,m,p_g,u_g_obs,c(n).grad_g,n);
+		[search_scalar c(n).J]=ControlOptimization('objectivefunctionC',-1,1,options,m,p_g,u_g_obs,c(n).grad_g,n);
 		disp('      done.');
 
Index: /issm/trunk/src/m/solutions/cielo/plot_direction.m
===================================================================
--- /issm/trunk/src/m/solutions/cielo/plot_direction.m	(revision 7)
+++ /issm/trunk/src/m/solutions/cielo/plot_direction.m	(revision 8)
@@ -1,4 +1,4 @@
 grad_g=c(n).grad_g;
 grad_gx=grad_g(1:2:end);grad_gy=grad_g(2:2:end); grad_g=sqrt(grad_gx.^2+grad_gy.^2);
-plotmodel(md,'data',grad_g,'title',['Normalized Direction for ' m.parameters.control_type],'figure',1,'colorbar#all','on'); pause(1);
+plotmodel(md,'data',grad_g,'title',['Normalized Direction for ' m.parameters.control_type],'figure',1,'colorbar#all','on'); drawnow;
 clear grad_g grad_gx grad_gy
Index: /issm/trunk/src/m/solutions/cielo/plot_newdistribution.m
===================================================================
--- /issm/trunk/src/m/solutions/cielo/plot_newdistribution.m	(revision 7)
+++ /issm/trunk/src/m/solutions/cielo/plot_newdistribution.m	(revision 8)
@@ -1,3 +1,3 @@
 p_gx=p_g(1:2:end);p_gy=p_g(2:2:end); p_g=sqrt(p_gx.^2+p_gy.^2);
-plotmodel(md,'data',p_g,'title',['Distribution of ' m.parameters.control_type 'at iteration' num2str(n)],'figure',1,'colorbar#all','on'); pause(1);
+plotmodel(md,'data',p_g,'title',['Distribution of ' m.parameters.control_type 'at iteration' num2str(n)],'figure',1,'colorbar#all','on'); drawnow;
 clear p_gx p_gy
Index: /issm/trunk/src/mex/ControlOptimization/ControlOptimization.cpp
===================================================================
--- /issm/trunk/src/mex/ControlOptimization/ControlOptimization.cpp	(revision 8)
+++ /issm/trunk/src/mex/ControlOptimization/ControlOptimization.cpp	(revision 8)
@@ -0,0 +1,75 @@
+/*\file ControlOptimization.c
+ *\brief: control optimization (replaces fmincon from matlab)
+ */
+ 
+
+#include "./ControlOptimization.h"
+
+void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){
+
+	/*diverse: */
+	int   noerr=1;
+
+	/*input datasets: */
+	char* function_name=NULL;
+	double xmin,xmax;
+	double tolerance;
+	int    maxiter;
+	OptArgs optargs;
+	OptPars optpars;
+
+	/*output: */
+	double search_scalar;
+	double J;
+
+	/*arguments to objectivefunctionC: */
+	mxArray* m=NULL;
+	mxArray* pg=NULL;
+	mxArray* u_g_obs=NULL;
+	mxArray* grad_g=NULL;
+	mxArray* n=NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*checks on arguments on the matlab side: */
+	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ControlOptimizationUsage);
+
+	/*Input datasets: */
+	FetchData((void**)&function_name,NULL,NULL,FUNCTIONNAME,"String",NULL);
+	FetchData((void**)&xmin,NULL,NULL,XMIN,"Scalar",NULL);
+	FetchData((void**)&xmax,NULL,NULL,XMAX,"Scalar",NULL);
+	FetchData((void**)&tolerance,NULL,NULL,mxGetField(OPTIONS,0,"TolX"),"Scalar",NULL);
+	FetchData((void**)&maxiter,NULL,NULL,mxGetField(OPTIONS,0,"MaxIter"),"Integer",NULL);
+
+	optargs.function_name=function_name;
+	optargs.m=MODEL;
+	optargs.p_g=PG;
+	optargs.u_g_obs=VELOBS;
+	optargs.grad_g=GRADIENT;
+	optargs.n=STEP;
+
+	optpars.xmin=xmin;
+	optpars.xmax=xmax;
+	optpars.tolerance=tolerance;
+	optpars.maxiter=maxiter;
+
+	BrentSearch(&search_scalar,&J,&optpars,&OptFunc,&optargs);
+
+	/*write output : */
+	WriteData(SEARCHSCALAR,&search_scalar,0,0,"Scalar",NULL);
+	WriteData(MISFIT,&J,0,0,"Scalar",NULL);
+
+	/*Free ressources: */
+	xfree((void**)&function_name);
+
+	/*end module: */
+	MODULEEND();
+}
+
+void ControlOptimizationUsage(void)
+{
+	_printf_("\n");
+	_printf_("   usage: [search_scalar J] = %s(function_name,xmin,xmax,options,m,p_g,u_g_obs,grad_g,step)\n");
+	_printf_("\n");
+}
Index: /issm/trunk/src/mex/ControlOptimization/ControlOptimization.h
===================================================================
--- /issm/trunk/src/mex/ControlOptimization/ControlOptimization.h	(revision 8)
+++ /issm/trunk/src/mex/ControlOptimization/ControlOptimization.h	(revision 8)
@@ -0,0 +1,42 @@
+
+/*
+	ControlOptimization.h
+*/
+
+
+#ifndef _CONTROLOPTIMIZATION_H
+#define _CONTROLOPTIMIZATION_H
+
+/* local prototypes: */
+void ControlOptimizationUsage(void);
+
+#include "../../c/issm.h"
+
+#undef __FUNCT__ 
+#define __FUNCT__  "ControlOptimization"
+
+/* serial input macros: */
+#define FUNCTIONNAME (mxArray*)prhs[0]
+#define XMIN (mxArray*)prhs[1]
+#define XMAX (mxArray*)prhs[2]
+#define OPTIONS (mxArray*)prhs[3]
+#define MODEL (mxArray*)prhs[4]
+#define PG (mxArray*)prhs[5]
+#define VELOBS (mxArray*)prhs[6]
+#define GRADIENT (mxArray*)prhs[7]
+#define STEP (mxArray*)prhs[8]
+
+/* serial output macros: */
+#define SEARCHSCALAR (mxArray**)&plhs[0]
+#define MISFIT (mxArray**)&plhs[1]
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  2
+#undef NRHS
+#define NRHS  9
+
+
+#endif  /* _CONTROLOPTIMIZATION_H */
+
+
