Index: /issm/trunk/src/m/classes/public/loadmultipleresultsfromcluster.m
===================================================================
--- /issm/trunk/src/m/classes/public/loadmultipleresultsfromcluster.m	(revision 2889)
+++ /issm/trunk/src/m/classes/public/loadmultipleresultsfromcluster.m	(revision 2889)
@@ -0,0 +1,39 @@
+function md_list=loadmultipleresultsfromcluster(md_list)
+%LOADMULTIPLERESULTSFROMCLUSTER - load multiple results of solution sequences from cluster
+%
+%   Usage:
+%      md_list=loadresultsfromcluster(md_list);
+
+nummodels=length(md_list);
+
+%Get cluster settings
+cluster=md_list{1}.cluster;
+name=md_list{1}.name;
+cluster_rc_location=which('cluster.rc');
+[codepath,executionpath]=ClusterParameters(cluster,cluster_rc_location);
+
+%Remote tar: 
+disp('tarring results');
+issmssh(cluster,['"cd ' executionpath ' && rm -rf file_list.txt ModelResults.tar.gz && find -iname ''*_*vs*.outbin'' > file_list.txt && tar zcvf ModelResults.tar.gz --files-from file_list.txt  && rm -rf file_list.txt "']);
+
+%copy results from cluster to present directory
+scpin(cluster, executionpath, {'ModelResults.tar.gz'});
+
+%untar:
+!tar -zxvf ModelResults.tar.gz
+
+%ok, go through list and load results from disk: 
+for i=1:nummodels,
+	%load  results for this model
+	%md_list{i}.analysis_type=DiagnosticAnalysisEnum();
+	%md_list{i}.sub_analysis_type=NoneAnalysisEnum();
+	%md_list{i}=loadresultsfromdisk(md_list{i},[md_list{i}.name '_' num2str(i) 'vs' num2str(nummodels) '.outbin']);
+	md_list{i}=loadresultsfromdisk(md_list{i},[md_list{i}.name '.outbin']);
+
+	%post solve phase
+	md_list{i}=postsolveparallel(md_list{i});
+	delete([name '.outbin']);
+end
+
+%erase files 
+delete('ModelResults.tar.gz');
Index: /issm/trunk/src/m/classes/public/modelsextract.m
===================================================================
--- /issm/trunk/src/m/classes/public/modelsextract.m	(revision 2889)
+++ /issm/trunk/src/m/classes/public/modelsextract.m	(revision 2889)
@@ -0,0 +1,84 @@
+function md_list=modelsextract(md,flags,minel,varargin)
+%modelsextract - extract several self contained models according to a list of element flags.
+%
+%   The difference between this routine and the modelextract.m routine (without an 's') is that 
+%   as many models are extracted as there are closed contours defined in area. 
+%   This routine is needed for example when doing data assimilation of ice shelves in Antarctica. 
+%   Many independent ice shelves are present, and we don't want data assimilation on one ice shelf 
+%   to be hindered by another totally independent ice shelf.
+%
+%   Usage:
+%      md_list=modelsextract(md,elementfalgs,minel);
+%
+%   Examples:
+%      md_list=modelsextract(md,md.elementoniceshelf,1000);
+%
+%   See also: EXTRUDE, COLLAPSE, MODELEXTRACT
+
+disp('selecting pools of elements');
+%go through flags and build as many independent element flags as there are groups of connected 1s
+%in flags.
+
+%2D or 3D?
+if strcmpi(md.type,'3d'),
+	numberofelements=md.numberofelements2d; %this will be forgotten when we get out.
+	flags=project2d(md,flags,1);
+else
+	numberofelements=md.numberofelements;
+end
+
+%recover extra arguments: 
+distance=0;
+if nargin==4,
+	distance=varargin{1};
+end
+
+flag_list=cell(0,1);
+
+for i=1:size(flags,1),
+
+	if (flags(i)),
+
+		%ok, we are sure element i is part of a new pool.
+		pool=zeros(numberofelements,1);
+		pool=PropagateFlagsFromConnectivity(md.elementconnectivity,pool,i,flags);
+		flag_list{end+1,1}=pool;
+		
+		%speed up rest of computation by taking pool out of flags: 
+		pos=find(pool);flags(pos)=0;
+
+	end
+end
+
+%go through flag_list and discard any pool of less than minel elements: 
+ex_pos=[];
+for i=1:length(flag_list),
+	if length(find(flag_list{i}))<minel,
+		ex_pos=[ex_pos; i];
+	end
+end
+flag_list(ex_pos)=[];
+
+%now, if distance was specified, expand the flag_list by distance km: 
+if distance,
+	for i=1:length(flag_list),
+		flag_list{i}=PropagateFlagsUntilDistance(md,flag_list{i},distance);
+	end
+end
+
+%now, go use the pools of flags to extract models: 
+disp(['extracting ' num2str(size(flag_list,1)) ' models']);
+md_list=cell(0,1);
+
+for i=1:size(flag_list,1),
+	disp(['   ' num2str(i) '/' num2str(size(flag_list,1))]);
+	if strcmpi(md.type,'3d'),
+		flags2d=flag_list{i};
+		realflags=project3d(md,flags2d,'element');
+	else
+		realflags=flag_list{i};
+	end
+	md_list{end+1,1}=modelextract(md,realflags);
+end
+
+end %end of this function
Index: /issm/trunk/src/m/classes/public/multisolve.m
===================================================================
--- /issm/trunk/src/m/classes/public/multisolve.m	(revision 2888)
+++ /issm/trunk/src/m/classes/public/multisolve.m	(revision 2889)
@@ -14,6 +14,22 @@
 %      md_list=solve(md_list,'analysis_type','thermal');
 
+%recover options
+options=pairoptions(varargin{:});
+
+%add default options
+options=process_solve_options(options);
+
 %length of list
 nummodels=length(md_list);
+
+%name of queue will be first name of list
+name=md_list{1}.name;
+
+%name of cluster will be first name of list
+cluster=md_list{1}.cluster;
+
+%Figure out parameters for this particular cluster
+cluster_rc_location=which('cluster.rc');
+[codepath,executionpath]=ClusterParameters(cluster,cluster_rc_location);
 
 %solve in batch mode: 
@@ -22,8 +38,16 @@
 	%model
 	md=md_list{i};
-	md.name=[md.name '_' num2str(i) 'vs' num2str(nummodels)];
+	
+	%recover some fields
+	md.analysis_type=options.analysis_type;
+	md.sub_analysis_type=options.sub_analysis_type;
+
+	md.name=[name '_' num2str(i) 'vs' num2str(nummodels)];
 
 	%call solve in batch mode:
 	md=solve(md,varargin{:},'batch','yes');
+
+	%feed back
+	md_list{i}=md;
 end
 
@@ -34,4 +58,10 @@
 
 %still have to build a launching script.
+BuildMultipleQueueingScript(cluster,name,executionpath,codepath);
 
-%now, send to cluster and solve
+%launch jobs on remote cluster
+LaunchMultipleQueueJob(cluster,name,executionpath);
+
+%erase files: 
+delete([name '.queue']);
+delete('ModelList.tar.gz');
Index: /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScript.m
===================================================================
--- /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScript.m	(revision 2889)
+++ /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScript.m	(revision 2889)
@@ -0,0 +1,23 @@
+function BuildMultipleQueueingScript(cluster,name,executionpath,codepath)
+%BUILDMULTIPLEQUEUEINGSCRIPT - 
+%
+%   Usage:
+%      BuildMultipleQueueingScript(executionpath,codepath)
+
+disp('building queueing script');
+
+%First try and figure out if there is a special script for this particular cluster
+function_name=['BuildMultipleQueueingScript' cluster];
+
+%some specific treatment of identical cluster, gemini, castor and pollux
+if strcmpi(cluster,'castor') || strcmpi(cluster,'pollux'),
+	function_name='BuildMultipleQueueingScriptgemini';
+end
+
+if exist(function_name,'file'),
+	%Call this function:
+	eval([function_name '(name,executionpath,codepath);']);
+else
+	%Call the generic BuildQueueingScript:
+	BuildMultipleQueueingScriptGeneric(name,executionpath,codepath);
+end
Index: /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScriptGeneric.m
===================================================================
--- /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScriptGeneric.m	(revision 2889)
+++ /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScriptGeneric.m	(revision 2889)
@@ -0,0 +1,12 @@
+function BuildMultipleQueueingScriptGeneric(name,executionpath,codepath)
+%BUILDMULTIPLEQUEUEINGSCRIPTGENERIC - ...
+%
+%   Usage:
+%      BuildMultipleQueueingScriptGeneric(executionpath,codepath)
+
+global ISSM_DIR
+
+
+%not done yet
+error('BuildMultipleQueueingScriptGenericerror message: not supported yet!');
+
Index: /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScriptgemini.m
===================================================================
--- /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScriptgemini.m	(revision 2889)
+++ /issm/trunk/src/m/classes/public/queue/BuildMultipleQueueingScriptgemini.m	(revision 2889)
@@ -0,0 +1,21 @@
+function BuildQueueingScriptgemini(name,executionpath,codepath)
+%BUILDQUEUEINGSCRIPTGEMINI - ...
+%
+%   Usage:
+%      BuildQueueingScriptgemini(md,executionpath,codepath)
+
+scriptname=[name '.queue'];
+
+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,'cd %s\n',executionpath);
+fprintf(fid,'rm -rf %s_*vs*\n',name);
+fprintf(fid,'tar -zxvf ModelList.tar.gz\n');
+fprintf(fid,'foreach i (%s_*vs*.queue)\n',name);
+fprintf(fid,'qsub $i\n');
+fprintf(fid,'end\n');
+fclose(fid);
Index: /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJob.m
===================================================================
--- /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJob.m	(revision 2889)
+++ /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJob.m	(revision 2889)
@@ -0,0 +1,21 @@
+function LaunchMultipleQueueJob(cluster,name,executionpath)
+%LAUNCHMULTIPLEQUEUEJOB - ...
+%
+%   Usage:
+%      LaunchMultipleQueueJob(executionpath)
+
+%First try and figure out if there is a special script for thie particular cluster
+function_name=['LaunchMultipleQueueJob' cluster];
+
+%some specific treatment of identical cluster, gemini, castor and pollux
+if strcmpi(cluster,'castor') || strcmpi(cluster,'pollux'),
+	function_name='LaunchMultipleQueueJobgemini';
+end
+
+if exist(function_name,'file'),
+	%Call this function:
+	eval([function_name '(cluster,name,executionpath);']);
+else
+	%Call the generic LaunchMultipleQueueJob:
+	LaunchMultipleQueueJobGeneric(cluster,name,executionpath);
+end
Index: /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJobGeneric.m
===================================================================
--- /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJobGeneric.m	(revision 2889)
+++ /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJobGeneric.m	(revision 2889)
@@ -0,0 +1,7 @@
+function LaunchMultipleQueueJobGeneric(cluster,name,executionpath)
+%LAUNCHMULTIPLEQUEUEJOBGENERIC - Generic routine to launch multiple queueing job
+%
+%   Usage:
+%      LaunchMultipleQueueJobGeneric(cluster,name,executionpath)
+
+error('LaunchMultipleQueueJobGeneric error message: not supported yet!');
Index: /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJobgemini.m
===================================================================
--- /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJobgemini.m	(revision 2889)
+++ /issm/trunk/src/m/classes/public/queue/LaunchMultipleQueueJobgemini.m	(revision 2889)
@@ -0,0 +1,22 @@
+function md=LaunchMultipleQueueJobgemini(cluster,name,executionpath)
+%LAUNCHMULTIPLEQUEUEJOBGEMINI - Launch multiple queueing script on Gemini cluster
+%
+%   Usage:
+%      LaunchMultipleQueueJobgemini(cluster,name,executionpath)
+
+
+%first, check we have the binary file and the queueing script
+if ~exist([ name '.queue'],'file'),
+	error('LaunchMultipleQueueJobgemini error message: queueing script issing, cannot go forward');
+end
+
+if ~exist('ModelList.tar.gz','file'),
+	error('LaunchMultipleQueueJobgemini error message: inputs models file missing, cannot go forward');
+end
+
+%upload both files to cluster
+disp('uploading input file,  queueing script and variables script');
+system(['scp ModelList.tar.gz ' name '.queue '  cluster ':' executionpath]);
+
+disp('launching solution sequence on remote cluster');
+issmssh(cluster,['"cd ' executionpath ' && source ' name '.queue "']);
