Index: sm/trunk/src/m/classes/public/BuildQueueingScript.m
===================================================================
--- /issm/trunk/src/m/classes/public/BuildQueueingScript.m	(revision 2880)
+++ 	(revision )
@@ -1,25 +1,0 @@
-function BuildQueueingScript(md,executionpath,codepath)
-%BUILDQUEUEINGSCRIPT - 
-%
-%   Usage:
-%      BuildQueueingScript(md,executionpath,codepath)
-
-disp('building queueing script');
-
-%First try and figure out if there is a special script for thie particular cluster
-function_name=['BuildQueueingScript' md.cluster];
-
-%some specific treatment of identical cluster, gemini, castor and pollux
-if strcmpi(md.cluster,'castor') || strcmpi(md.cluster,'pollux'),
-	function_name='BuildQueueingScriptgemini';
-end
-
-if exist(function_name,'file'),
-
-	
-	%Call this function:
-	eval([function_name '(md,executionpath,codepath);']);
-else
-	%Call the generic BuildQueueingScript:
-	BuildQueueingScriptGeneric(md,executionpath,codepath);
-end
Index: sm/trunk/src/m/classes/public/BuildQueueingScriptGeneric.m
===================================================================
--- /issm/trunk/src/m/classes/public/BuildQueueingScriptGeneric.m	(revision 2880)
+++ 	(revision )
@@ -1,26 +1,0 @@
-function BuildQueueingScriptGeneric(md,executionpath,codepath)
-%BUILDQUEUEINGSCRIPTGENERIC - ...
-%
-%   Usage:
-%      BuildQueueingScriptGeneric(md,executionpath,codepath)
-
-global ISSM_DIR
-
-%Open queuing script file 
-scriptname=[md.name '.queue'];
-
-fid=fopen(scriptname,'w');
-if fid==-1,
-	error(['BuildQueueingScriptGenericerror message: could not open ' scriptname ' file for ascii writing']);
-end
-
-fprintf(fid,'#!/bin/sh\n');
-fprintf(fid,'rm -rf %s/%s.lock\n',executionpath,md.name);
-
-if md.mem_debug==0,
-fprintf(fid,'mpirun -np %i %s/%s.exe %s %s.bin %s.outbin %s.lock  2> %s.errlog >%s.outlog & ',md.np,codepath,AnalysisTypeFromEnum(md.analysis_type),executionpath,md.name,md.name,md.name,md.name,md.name);
-else
-fprintf(fid,'LD_PRELOAD=%s mpirun -np %i %s --leak-check=full %s/%s.exe %s %s.bin %s.outbin %s.lock  2> %s.errlog >%s.outlog & ',[ISSM_DIR '/externalpackages/valgrind/install/lib/libmpidebug.so'],md.np,[ISSM_DIR '/externalpackages/valgrind/install/bin/valgrind'],codepath,AnalysisTypeFromEnum(md.analysis_type),executionpath,md.name,md.name,md.name,md.name,md.name);
-end
-
-fclose(fid);
Index: sm/trunk/src/m/classes/public/BuildQueueingScriptcosmos.m
===================================================================
--- /issm/trunk/src/m/classes/public/BuildQueueingScriptcosmos.m	(revision 2880)
+++ 	(revision )
@@ -1,65 +1,0 @@
-function BuildQueueingScriptcosmos(md,executionpath,codepath)
-%BUILDQUEUEINGSCRIPTGEMINI - ...
-%
-%   Usage:
-%      BuildQueueingScriptcosmos(md,executionpath,codepath)
-
-scriptname=[md.name '.queue'];
-
-fid=fopen(scriptname,'w');
-if fid==-1,
-	error(['BuildQueueingScriptcosmos error message: could not open ' scriptname ' file for ascii writing']);
-end
-
-%check queue names: 
-available_queues={'debug','shortq','longq','specialq'};
-if  ~ismemberi(md.queue,available_queues),
-	error('BuildQueueingScriptcosmos error message: availables queues are debug, shortq, longq and specialq');
-end
-
-%test parameters for each queue: 
-if strcmpi(md.queue,'debug'),
-	if md.np>32,
-		error('BuildQueueingScriptcosmos error message: debug queue only allows 32 cpus');
-	end
-	if md.time>60,
-		error('BuildQueueingScriptcosmos error message: debug queue only allows 60 minutes');
-	end
-end
-
-if strcmpi(md.queue,'shortq'),
-	if md.np>128,
-		error('BuildQueueingScriptcosmos error message: shortq queue only allows 128 cpus');
-	end
-	if md.time>180,
-		error('BuildQueueingScriptcosmos error message: shortq queue only allows 180 minutes');
-	end
-end
-
-if strcmpi(md.queue,'longq'),
-	if md.np>128,
-		error('BuildQueueingScriptcosmos error message: longq queue only allows 128 cpus');
-	end
-	if md.time>720,
-		error('BuildQueueingScriptcosmos error message: longq queue only allows 720 minutes');
-	end
-end
-
-
-
-fprintf(fid,'#!/bin/bash\n');
-fprintf(fid,'#PBS -l select=%i:ncpus=1\n',md.np);
-fprintf(fid,'#PBS -l walltime=%i\n',md.time*60); %walltime is in seconds.
-if ~isempty(md.queue),
-	fprintf(fid,'#PBS -q %s\n',md.queue);
-end
-fprintf(fid,'#PBS -o %s.outlog \n',md.name);
-fprintf(fid,'#PBS -e %s.errlog \n',md.name);
-
-fprintf(fid,'export PBS_O_WORKDIR=%s\n',executionpath);
-fprintf(fid,'cd $PBS_O_WORKDIR\n');
-fprintf(fid,'export OMP_NUM_THREADS=1\n');
-fprintf(fid,'ulimit -s unlimited\n');
-fprintf(fid,'ulimit -c 0\n');
-fprintf(fid,'/opt/mpich/gm/intel10.1/bin/mpirun -np %i %s/%s.exe %s %s.bin %s.outbin %s.lock',md.np,codepath,AnalysisTypeFromEnum(md.analysis_type),executionpath,md.name,md.name,md.name);
-fclose(fid);
Index: sm/trunk/src/m/classes/public/BuildQueueingScriptgemini.m
===================================================================
--- /issm/trunk/src/m/classes/public/BuildQueueingScriptgemini.m	(revision 2880)
+++ 	(revision )
@@ -1,81 +1,0 @@
-function BuildQueueingScriptgemini(md,executionpath,codepath)
-%BUILDQUEUEINGSCRIPTGEMINI - ...
-%
-%   Usage:
-%      BuildQueueingScriptgemini(md,executionpath,codepath)
-
-scriptname=[md.name '.queue'];
-
-
-
-%check queue names: 
-if strcmpi(md.cluster,'gemini'),
-	available_queues={'debug','shortg','longg'};
-	if  ~ismemberi(md.queue,available_queues),
-		error('BuildQueueingScriptcosmos error message: availables queues are debug, shortg and longg');
-	end 
-
-	if strcmpi(md.queue,'debug'),
-		if md.np>50,
-			error('BuildQueueingScriptgeminierror error message: debug queue only allows for 50 cpus max');
-		end
-		
-		if md.time>60,
-			error('BuildQueueingScriptgeminierror error message: debug queue only allows for 60 minute runs');
-		end
-	end
-end
-
-if strcmpi(md.cluster,'castor'),
-	available_queues={'shortc','longc'};
-	if  ~ismemberi(md.queue,available_queues),
-		error('BuildQueueingScriptcosmos error message: availables queues are shortc and longc');
-	end 
-end
-
-if strcmpi(md.cluster,'pollux'),
-	available_queues={'shortp','longp'};
-	if  ~ismemberi(md.queue,available_queues),
-		error('BuildQueueingScriptcosmos error message: availables queues are shortp and longp');
-	end 
-end
-
-%test parameters valid for all queues
-if strcmpi(md.queue(1:5),'short'),
-	if md.np>128,
-		error('BuildQueueingScriptcosmos error message: short queue only allows 128 cpus');
-	end
-	if md.time>180,
-		error('BuildQueueingScriptcosmos error message: short queue only allows 180 minutes');
-	end
-end
-
-if strcmpi(md.queue(1:4),'long'),
-	if md.np>128,
-		error('BuildQueueingScriptcosmos error message: long queue only allows 128 cpus');
-	end
-	if md.time>720,
-		error('BuildQueueingScriptcosmos error message: long queue only allows 720 minutes');
-	end
-end
-
-fid=fopen(scriptname,'w');
-if fid==-1,
-	error(['BuildQueueingScriptgeminierror message: could not open ' scriptname ' file for ascii writing']);
-end
-
-fprintf(fid,'#!/bin/sh\n');
-fprintf(fid,'#PBS -l walltime=%i\n',md.time*60); %walltime is in seconds.
-fprintf(fid,'#PBS -l ncpus=%i\n',md.np);
-if ~isempty(md.queue),
-	fprintf(fid,'#PBS -q %s\n',md.queue);
-end
-fprintf(fid,'#PBS -o %s.outlog \n',md.name);
-fprintf(fid,'#PBS -e %s.errlog \n',md.name);
-
-fprintf(fid,'export PBS_O_WORKDIR=%s\n',executionpath);
-fprintf(fid,'cd $PBS_O_WORKDIR\n');
-fprintf(fid,'export OMP_NUM_THREADS=1\n');
-fprintf(fid,'dplace -s1 -c0-%i mpirun -np %i %s/%s.exe %s %s.bin %s.outbin %s.lock',md.np-1,md.np,codepath,AnalysisTypeFromEnum(md.analysis_type),executionpath,md.name,md.name,md.name);
-
-fclose(fid);
Index: sm/trunk/src/m/classes/public/BuildQueueingScriptgreenplanet.m
===================================================================
--- /issm/trunk/src/m/classes/public/BuildQueueingScriptgreenplanet.m	(revision 2880)
+++ 	(revision )
@@ -1,43 +1,0 @@
-function BuildQueueingScriptgreenplanet(md,executionpath,codepath)
-%BUILDQUEUEINGSCRIPTGEMINI - ...
-%
-%   Usage:
-%      BuildQueueingScriptgreenplanet(md,executionpath,codepath)
-
-scriptname=[md.name '.queue'];
-
-%check queue names: 
-if strcmpi(md.cluster,'greenplanet'),
-	available_queues={'rignot','default'};
-	if  ~ismemberi(md.queue,available_queues),
-		error('BuildQueueingScriptgreenplanet error message: availables queues are rignot and default');
-	end 
-
-	if strcmpi(md.queue,'rignot'),
-		if md.np>80,
-			error('BuildQueueingScriptgreenplaneterror error message: debug queue only allows for 80 cpus max');
-		end
-		
-		if md.time>60,
-			error('BuildQueueingScriptgreenplaneterror error message: debug queue only allows for 60 minute runs');
-		end
-	end
-end
-
-fid=fopen(scriptname,'w');
-if fid==-1,
-	error(['BuildQueueingScriptgreenplaneterror message: could not open ' scriptname ' file for ascii writing']);
-end
-
-fprintf(fid,'#!/bin/csh\n');
-fprintf(fid,'#PBS -N %s\n',md.name);
-fprintf(fid,'#PBS -l nodes=%i:ppn=%i\n',md.np/8,8);
-fprintf(fid,'#PBS -q %s\n',md.queue);
-fprintf(fid,'#PBS -m bea\n');
-fprintf(fid,'#PBS -M eric.larour@jpl.nasa.gov\n');
-fprintf(fid,'#PBS -l walltime=%i\n',md.time*60); %walltime is in seconds.
-
-fprintf(fid,'cd $PBS_O_WORKDIR\n');
-fprintf(fid,'mpirun -machinefile $PBS_NODEFILE -np %i %s/%s.exe %s %s.bin %s.outbin %s.lock > %s.outlog',md.np,codepath,AnalysisTypeFromEnum(md.analysis_type),executionpath,md.name,md.name,md.name,md.name);
-
-fclose(fid);
Index: sm/trunk/src/m/classes/public/LaunchQueueJob.m
===================================================================
--- /issm/trunk/src/m/classes/public/LaunchQueueJob.m	(revision 2880)
+++ 	(revision )
@@ -1,21 +1,0 @@
-function md=LaunchQueueJob(md,executionpath,options)
-%LAUNCHQUEUEJOB - ...
-%
-%   Usage:
-%      LaunchQueueJob(md,executionpath)
-
-%First try and figure out if there is a special script for thie particular cluster
-function_name=['LaunchQueueJob' md.cluster];
-
-%some specific treatment of identical cluster, gemini, castor and pollux
-if strcmpi(md.cluster,'castor') || strcmpi(md.cluster,'pollux'),
-	function_name='LaunchQueueJobgemini';
-end
-
-if exist(function_name,'file'),
-	%Call this function:
-	eval(['md=' function_name '(md,executionpath,options);']);
-else
-	%Call the generic LaunchQueueJob:
-	md=LaunchQueueJobGeneric(md,executionpath,options);
-end
Index: sm/trunk/src/m/classes/public/LaunchQueueJobGeneric.m
===================================================================
--- /issm/trunk/src/m/classes/public/LaunchQueueJobGeneric.m	(revision 2880)
+++ 	(revision )
@@ -1,34 +1,0 @@
-function md=LaunchQueueJobGeneric(md,executionpath,options)
-%LAUNCHQUEUEJOBGENERIC - Generic routine to launch queueing job
-%
-%   Usage:
-%      LaunchQueueJobGeneric(md,executionpath)
-
-%first, check we have the binary file and the queueing script
-if ~exist([ md.name '.bin'],'file'),
-	error('LaunchQueueJobGeneric error message: Binary input file missing, cannot go forward');
-end
-
-if ~exist([ md.name '.queue'],'file'),
-	error('LaunchQueueJobGeneric error message: queueing script issing, cannot go forward');
-end
-
-if ~strcmpi(options.batch,'yes'),
-
-	%what files are we sending?
-	packages={[md.name '.bin'],[md.name '.queue']};
-	if md.qmu_analysis,
-		packages{end+1}=[md.name '.qmu.in'];
-	end
-
-	disp('uploading input file and queueing script');
-	scpout(md.cluster,executionpath,packages);
-	
-	disp('launching solution sequence on remote cluster');
-	issmssh(md.cluster,['cd ' executionpath ' && source ' md.name '.queue ']);
-
-else
-	disp('batch mode requested: not launching job interactively');
-	disp(['launch solution sequence by copying files ' md.name '.bin' ',' md.name '.queue and ' md.name '.qmu.in, onto remote cluster ' md.cluster]);
-	disp(['   then log int ' md.cluster ' and source queue file ' md.name '.queue']);
-end
Index: sm/trunk/src/m/classes/public/LaunchQueueJobcosmos.m
===================================================================
--- /issm/trunk/src/m/classes/public/LaunchQueueJobcosmos.m	(revision 2880)
+++ 	(revision )
@@ -1,32 +1,0 @@
-function md=LaunchQueueJobcosmos(md,executionpath,options)
-%LAUNCHQUEUEJOBCOSMOS- Launch queue script for Cosmos cluster
-%
-%   Usage:
-%      LaunchQueueJobcosmos(md,executionpath)
-
-%first, check we have the binary file and the queueing script
-if ~exist([ md.name '.bin'],'file'),
-	error('LaunchQueueJobcosmos error message: Binary input file missing, cannot go forward');
-end
-
-if ~exist([ md.name '.queue'],'file'),
-	error('LaunchQueueJobcosmos error message: queueing script issing, cannot go forward');
-end
-
-%jpload both files to cluster
-if ~strcmpi(options.batch,'yes'),
-	disp('uploading input file,  queueing script and variables script');
-	if md.qmu_analysis, 
-		system(['scp ' md.name '.bin' ' ' md.name '.queue '  md.name '.qmu.in ' md.cluster ':' executionpath]);
-	else
-		system(['scp ' md.name '.bin' ' ' md.name '.queue '  md.cluster ':' executionpath]);
-	end
-
-	disp('launching solution sequence on remote cluster');
-	issmssh(md.cluster,['"cd ' executionpath ' && qsub -S/bin/sh ' md.name '.queue "']);
-else
-	disp('batch mode requested: not launching job interactively');
-
-	%new gemini cannot launch across cluster using ssh
-	disp(['launch solution sequence on remote cluster by logging into it and typing qsub -S/bin/sh ' md.name '.queue']);
-end
Index: sm/trunk/src/m/classes/public/LaunchQueueJobgemini.m
===================================================================
--- /issm/trunk/src/m/classes/public/LaunchQueueJobgemini.m	(revision 2880)
+++ 	(revision )
@@ -1,32 +1,0 @@
-function md=LaunchQueueJobgemini(md,executionpath,options)
-%LAUNCHQUEUEJOBGEMINI - Launch queueing script on Gemini cluster
-%
-%   Usage:
-%      LaunchQueueJobgemini(md,executionpath)
-
-%first, check we have the binary file and the queueing script
-if ~exist([ md.name '.bin'],'file'),
-	error('LaunchQueueJobgemini error message: Binary input file missing, cannot go forward');
-end
-
-if ~exist([ md.name '.queue'],'file'),
-	error('LaunchQueueJobgemini error message: queueing script issing, cannot go forward');
-end
-
-%jpload both files to cluster
-if ~strcmpi(options.batch,'yes'),
-	disp('uploading input file,  queueing script and variables script');
-	if md.qmu_analysis, 
-		system(['scp ' md.name '.bin' ' ' md.name '.queue '  md.name '.qmu.in ' md.cluster ':' executionpath]);
-	else
-		system(['scp ' md.name '.bin' ' ' md.name '.queue '  md.cluster ':' executionpath]);
-	end
-	
-	disp('launching solution sequence on remote cluster');
-	issmssh(md.cluster,['"cd ' executionpath ' && qsub ' md.name '.queue "']);
-else
-	disp('batch mode requested: not launching job interactively');
-
-	%new gemini cannot launch across cluster using ssh
-	disp(['launch solution sequence on remote cluster by logging into it and typing qsub < ' md.name '.queue']);
-end
Index: sm/trunk/src/m/classes/public/LaunchQueueJobgreenplanet.m
===================================================================
--- /issm/trunk/src/m/classes/public/LaunchQueueJobgreenplanet.m	(revision 2880)
+++ 	(revision )
@@ -1,29 +1,0 @@
-function md=LaunchQueueJobgreenplanet(md,executionpath,options)
-%LAUNCHQUEUEJOBGEMINI - ...
-%
-%   Usage:
-%      LaunchQueueJobgreenplanet(md,executionpath)
-
-%first, check we have the binary file and the queueing script
-if ~exist([ md.name '.bin'],'file'),
-	error('LaunchQueueJobgreenplanet error message: Binary input file missing, cannot go forward');
-end
-
-if ~exist([ md.name '.queue'],'file'),
-	error('LaunchQueueJobgreenplanet error message: queueing script issing, cannot go forward');
-end
-
-%jpload both files to cluster
-if ~strcmpi(options.batch,'yes'),
-	disp('uploading input file,  queueing script and variables script');
-	if md.qmu_analysis, 
-		system(['scp -P 1025 -o HostKeyAlias=huey.jpl.nasa.gov ' md.name '.bin' ' ' md.name '.queue '  md.name '.qmu.in elarour@localhost:' executionpath]);
-	else
-		system(['scp -P 1025 -o HostKeyAlias=huey.jpl.nasa.gov ' md.name '.bin' ' ' md.name '.queue elarour@localhost:' executionpath ]);
-	end
-else
-	disp('batch mode requested: not launching job interactively');
-end
-
-%new greenplanet cannot launch across cluster using ssh
-disp(['launch solution sequence on remote cluster by logging into it and typing qsub < ' md.name '.queue']);
Index: /issm/trunk/src/m/classes/public/PropagateFlagsUntilDistance.m
===================================================================
--- /issm/trunk/src/m/classes/public/PropagateFlagsUntilDistance.m	(revision 2881)
+++ /issm/trunk/src/m/classes/public/PropagateFlagsUntilDistance.m	(revision 2881)
@@ -0,0 +1,57 @@
+function new_flags=PropagateFlagsUntilDistance(md,flags,distance)
+%PROPAGATEFLAGSUNTILDISTANCE
+%
+% Usage: 
+%              flags=PropagateFlagsUntilDistance(md,flags,distance)
+%
+%
+
+
+	
+new_flags=flags;
+
+%find elements that are at the border of flags: 
+flag_elements=find(flags);
+conn=md.elementconnectivity(flag_elements,:);
+pos=find(conn);conn(pos)=~flags(conn(pos));
+sum_conn=sum(conn,2);
+border_elements=flag_elements(find(sum_conn>=1));
+
+
+%average x and y over elements: 
+x_elem=md.x(md.elements)*[1;1;1]/3;
+y_elem=md.y(md.elements)*[1;1;1]/3;
+
+while 1,
+
+	%keep copy of new_flags for this loop: 
+	new_flags_bak=new_flags;
+
+	%extend new flags by connectivity
+	pos=find(new_flags);
+
+	connected_elements=md.elementconnectivity(pos,:);
+	connected_elements=connected_elements(find(connected_elements));
+	new_flags(connected_elements)=1;
+
+	%get new elements: 
+	new_elements=find(new_flags & ~new_flags_bak);
+	if ~length(new_elements),
+		%we are done!
+		break;
+	end
+
+
+	%check which of these new elements are more than distance away from the border elements
+	for i=1:length(new_elements),
+		dist=sqrt(     (x_elem(border_elements)-x_elem(new_elements(i))).^2 + (y_elem(border_elements)-y_elem(new_elements(i))).^2)-distance;
+		if ~any(dist<0)
+			%none of the border elements are within distance, this element is outside out area of interest.
+			%ensure this element never gets found again in the connectivity.
+			pos=find(md.elementconnectivity==new_elements(i));
+			md.elementconnectivity(pos)=0;
+			%exclude this new element from the new_flags!
+			new_flags(new_elements(i))=0;
+		end
+	end
+end
Index: /issm/trunk/src/m/classes/public/display/displaycontrol.m
===================================================================
--- /issm/trunk/src/m/classes/public/display/displaycontrol.m	(revision 2880)
+++ /issm/trunk/src/m/classes/public/display/displaycontrol.m	(revision 2881)
@@ -26,4 +26,5 @@
 	fielddisplay(md,'cm_min','absolute minimum acceptable value of the inversed parameter');
 	fielddisplay(md,'cm_max','absolute maximum acceptable value of the inversed parameter');
+	fielddisplay(md,'cm_gradient','stop control method solution at gradient');
 	fielddisplay(md,'meanvel','velocity scaling factor when evaluating relative or logarithmic misfit');
 	fielddisplay(md,'epsvel','for relative fit, avoids misfit becoming infinity, for logarithmic fit, threshold for velocity');
Index: /issm/trunk/src/m/classes/public/effectivepressure.m
===================================================================
--- /issm/trunk/src/m/classes/public/effectivepressure.m	(revision 2881)
+++ /issm/trunk/src/m/classes/public/effectivepressure.m	(revision 2881)
@@ -0,0 +1,16 @@
+function Neff=effectivepressure(md)
+%EFFECTIVEPRESSURE - compute effective pressure
+%
+%   Usage:
+%      Neff=effectivepressure(md)
+%
+%   Example:
+%      Neff=effectivepressure(md)
+%
+
+
+Neff=md.rho_ice*md.g*md.thickness+md.rho_ice*md.g*md.bed;
+
+
+pos=find(Neff<0);
+Neff(pos)=0;
Index: /issm/trunk/src/m/classes/public/isresultconsistent.m
===================================================================
--- /issm/trunk/src/m/classes/public/isresultconsistent.m	(revision 2880)
+++ /issm/trunk/src/m/classes/public/isresultconsistent.m	(revision 2881)
@@ -61,41 +61,58 @@
 if analysis_type==DiagnosticAnalysisEnum() & md.control_analysis==1,
 
-	fields1={'results.diagnostic.vx','results.diagnostic.vy','results.diagnostic.vel','results.diagnostic.parameter'};
-	fields2={'results.diagnostic.vel','results.diagnostic.J'};
-
-	%check size
-	if ~testsize(md,fields1,md.numberofgrids),
-		bool=0; return
-	end
-
-	%no NAN
-	if ~testnan(md,fields1),
-		bool=0; return
-	end
-
-	%check value is real
-	if ~testreal(md,fields1),
-		bool=0; return
-	end
-
-	%check value>=0
-	if ~testpositive(md,fields2),
-		bool=0; return
-	end
-
-	%check inversed parameter
-	if ~isnan(md.cm_max),
-		if any(md.results.diagnostic.parameter>md.cm_max)
-			disp(['''control'' result not consistent: inverse parameter is greater than ' num2str(md.cm_max)]);
-			bool=0; return; 
-		end
-	end
-	if ~isnan(md.cm_min),
-		if any(md.results.diagnostic.parameter<md.cm_min)
-			disp(['''control'' result not consistent: inverse parameter is smaller than ' num2str(md.cm_min)]);
-			bool=0; return; 
-		end
-	end
-
+	if ~md.cm_gradient,
+		fields1={'results.diagnostic.vx','results.diagnostic.vy','results.diagnostic.vel','results.diagnostic.parameter'};
+		fields2={'results.diagnostic.vel','results.diagnostic.J'};
+
+		%check size
+		if ~testsize(md,fields1,md.numberofgrids),
+			bool=0; return
+		end
+
+		%no NAN
+		if ~testnan(md,fields1),
+			bool=0; return
+		end
+
+		%check value is real
+		if ~testreal(md,fields1),
+			bool=0; return
+		end
+
+		%check value>=0
+		if ~testpositive(md,fields2),
+			bool=0; return
+		end
+
+		%check inversed parameter
+		if ~isnan(md.cm_max),
+			if any(md.results.diagnostic.parameter>md.cm_max)
+				disp(['''control'' result not consistent: inverse parameter is greater than ' num2str(md.cm_max)]);
+				bool=0; return; 
+			end
+		end
+		if ~isnan(md.cm_min),
+			if any(md.results.diagnostic.parameter<md.cm_min)
+				disp(['''control'' result not consistent: inverse parameter is smaller than ' num2str(md.cm_min)]);
+				bool=0; return; 
+			end
+		end
+	else
+		fields={'results.diagnostic.gradient'};
+		%check size
+		if ~testsize(md,fields,md.numberofgrids),
+			bool=0; return
+		end
+
+		%no NAN
+		if ~testnan(md,fields),
+			bool=0; return
+		end
+
+		%check value is real
+		if ~testreal(md,fields),
+			bool=0; return
+		end
+	end
 end
 
Index: /issm/trunk/src/m/classes/public/loadresultsfromcluster.m
===================================================================
--- /issm/trunk/src/m/classes/public/loadresultsfromcluster.m	(revision 2880)
+++ /issm/trunk/src/m/classes/public/loadresultsfromcluster.m	(revision 2881)
@@ -28,5 +28,5 @@
 %read log files onto  fields
 md.errlog=char(textread([md.name '.errlog'],'%s','delimiter','\n'));
-md.outlog=char(textread([md.name '.outlog'],'%s','delimiter','\n'));
+%md.outlog=char(textread([md.name '.outlog'],'%s','delimiter','\n'));
 
 if ~isempty(md.errlog),
@@ -42,7 +42,11 @@
 delete([md.name '.outbin']);
 
-%erase input files
-delete([md.name '.bin']);
-delete([md.name '.queue']);
+%erase input file if run was carried out on same platform.
+hostname=oshostname();
+if strcmpi(hostname,md.cluster),
+	delete([md.name '.lock']);
+	delete([md.name '.bin']);
+	delete([md.name '.queue']);
+end
 
 %post solve phase
Index: /issm/trunk/src/m/classes/public/marshall.m
===================================================================
--- /issm/trunk/src/m/classes/public/marshall.m	(revision 2880)
+++ /issm/trunk/src/m/classes/public/marshall.m	(revision 2881)
@@ -119,4 +119,5 @@
 WriteData(fid,md.cm_min,'Scalar','cm_min');
 WriteData(fid,md.cm_max,'Scalar','cm_max');
+WriteData(fid,md.cm_gradient,'Integer','cm_gradient');
 WriteData(fid,md.eps_res,'Scalar','eps_res');
 WriteData(fid,md.eps_rel,'Scalar','eps_rel');
Index: /issm/trunk/src/m/classes/public/misfit.m
===================================================================
--- /issm/trunk/src/m/classes/public/misfit.m	(revision 2881)
+++ /issm/trunk/src/m/classes/public/misfit.m	(revision 2881)
@@ -0,0 +1,16 @@
+function J=misfit(md)
+%MISFIT - compute misfit
+%
+%   Usage:
+%      J=misfti(md)
+%
+%   Example:
+%      J=misfti(md)
+%
+
+
+areas=GetAreas(md.elements,md.x,md.y);
+deltav=1/2*sqrt(   (md.vx-md.vx_obs).^2+(md.vy-md.vy_obs).^2);
+deltav_elem=deltav(md.elements)*[1;1;1]/3;
+
+J=sum(deltav_elem.*areas);
Index: /issm/trunk/src/m/classes/public/multisolve.m
===================================================================
--- /issm/trunk/src/m/classes/public/multisolve.m	(revision 2881)
+++ /issm/trunk/src/m/classes/public/multisolve.m	(revision 2881)
@@ -0,0 +1,37 @@
+function md_list=multisolve(md_list,varargin)
+%SOLVE - apply solution sequence for  a list of models. Used in batch mode.
+%
+%   Usage:
+%      md_list=solve(md_list,varargin)
+%      where varargin is a lit of paired arguments. 
+%      arguments can be: 'analysis_type': 'diagnostic','thermal','prognostic','transient'
+%      arguments can be: 'sub_analysis_type': 'transient','steady','' (default if empty = 'steady')
+%
+%   Examples:
+%      md_list=solve(md_list,'analysis_type','diagnostic');
+%      md_list=solve(md_list,'analysis_type','thermal','sub_analysis_type','transient');
+%      md_list=solve(md_list,'analysis_type','thermal','sub_analysis_type','steady');
+%      md_list=solve(md_list,'analysis_type','thermal');
+
+%length of list
+nummodels=length(md_list);
+
+%solve in batch mode: 
+for i=1:nummodels,
+
+	%model
+	md=md_list{i};
+	md.name=[md.name '_' num2str(i) 'vs' num2str(nummodels)];
+
+	%call solve in batch mode:
+	md=solve(md,varargin{:},'batch','yes');
+end
+
+%now, tar all the files and then erase them.
+!find -iname '*_*vs*' > file_list.txt
+!tar zcvf ModelList.tar.gz --files-from file_list.txt
+!rm -rf *_*vs* file_list.txt
+
+%still have to build a launching script.
+
+%now, send to cluster and solve
Index: /issm/trunk/src/m/classes/public/plot/applyoptions.m
===================================================================
--- /issm/trunk/src/m/classes/public/plot/applyoptions.m	(revision 2880)
+++ /issm/trunk/src/m/classes/public/plot/applyoptions.m	(revision 2881)
@@ -229,4 +229,8 @@
 		set(gcf,'Position',[1604 4 1594 1177]);
 	end
+	if strcmpi(positionstring,'larour2'),
+		set(gcf,'Position',[813 226 750 623]);
+	end
+
 end
 
Index: /issm/trunk/src/m/classes/public/radarpower.m
===================================================================
--- /issm/trunk/src/m/classes/public/radarpower.m	(revision 2880)
+++ /issm/trunk/src/m/classes/public/radarpower.m	(revision 2881)
@@ -44,4 +44,5 @@
 	%Read and crop file
 	im=imread(jpgim);
+	save temp im geom
 	im=im(toplefty:toplefty+sizey,topleftx:topleftx+sizex);
 	md.sarpwr=double(flipud(im));
Index: /issm/trunk/src/m/classes/public/tres.m
===================================================================
--- /issm/trunk/src/m/classes/public/tres.m	(revision 2880)
+++ /issm/trunk/src/m/classes/public/tres.m	(revision 2881)
@@ -22,4 +22,6 @@
 	if isfield(md.results.diagnostic,'vz'),
 		md.vz=md.results.diagnostic.vz;
+	else
+		md.vz=zeros(md.numberofgrids,1);
 	end
 	md.vel=md.results.diagnostic.vel;
