Index: /issm/trunk-jpl/src/m/solve/solve.m
===================================================================
--- /issm/trunk-jpl/src/m/solve/solve.m	(revision 14351)
+++ /issm/trunk-jpl/src/m/solve/solve.m	(revision 14352)
@@ -101,13 +101,20 @@
 
 %wait on lock
-if md.settings.waitonlock>0,
-	%we wait for the done file
-	islock=waitonlock(md);
-	if islock==0, %no results to be loaded
-		disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
-	else          %load results
-		disp('loading results from cluster');
+if isnan(md.settings.waitonlock),
+	%load when user enters 'y'
+	disp('solution launched on remote cluster. log in to detect job completion.');
+	choice=input('Is the job successfully completed? (y/n)','s');
+	if ~strcmp(choice,'y'), 
+		disp('Results not loaded... exiting'); 
+	else
 		md=loadresultsfromcluster(md);
 	end
+elseif md.settings.waitonlock>0,
+	%we wait for the done file
+	done=waitonlock(md);
+	disp('loading results from cluster');
+	md=loadresultsfromcluster(md);
+elseif md.settings.waitonlock==0,
+	 disp('Model results must be loaded manually with md=loadresultsfromcluster(md);');
 end
 
Index: /issm/trunk-jpl/src/m/solve/waitonlock.m
===================================================================
--- /issm/trunk-jpl/src/m/solve/waitonlock.m	(revision 14351)
+++ /issm/trunk-jpl/src/m/solve/waitonlock.m	(revision 14352)
@@ -1,3 +1,3 @@
-function flag=waitonlock(md)
+function ispresent=waitonlock(md)
 %WAITONLOCK - wait for a file
 %
@@ -8,53 +8,55 @@
 %      flag=waitonlock(md)
 
+%Return if waitonlock < 0 (no need to wait)
+
 %Get filename (lock file) and options
-executionpath=md.cluster.executionpath;
-cluster=md.cluster.name;
-login=md.cluster.login;
-if isprop(md.cluster,'port') 
-	port=md.cluster.port;
+executionpath = md.cluster.executionpath;
+timelimit     = md.settings.waitonlock;
+filename      = [executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock'];
+cluster       = md.cluster;
+
+%If we are using the generic cluster in interactive mode, job is already complete
+if isa(cluster,'generic') & cluster.interactive
+	%We are in interactive mode, no need to check for job completion
+	ispresent=1;
+	return;
 end
-timelimit=md.settings.waitonlock;
-filename=[executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock'];
 
-%waitonlock will work if the lock is on the same machine only: 
+%initialize time and file presence test flag
+time=0; ispresent=0;
+disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
+
+%prepare command if the job is not running on the local machine
 if ~strcmpi(oshostname(),cluster),
+	login = cluster.login;
+	port  = 0;
+	if isprop(cluster,'port') 
+		port = cluster.port;
+	end
+	if port,
+		command = ['ssh -l ' login ' -p ' num2str(port) ' localhost " [ -f ' filename '  ]" 2>/dev/null'];
+	else
+		command = ['ssh -l ' login ' ' cluster.name ' " [ -f ' filename '  ]" 2>/dev/null'];
+	end
+end
 
-	disp('solution launched on remote cluster. log in to detect job completion.');
-	choice=input('Is the job successfully completed? (y/n)','s');
-	if ~strcmp(choice,'y'), 
-		disp('Results not loaded... exiting'); 
-		flag=0;
-	else
-		flag=1;
-	end
-
-%job is running on the same machine
-else
-
-	if ismember('interactive',properties(md.cluster)) & md.cluster.interactive
-		%We are in interactive mode, no need to check for job completion
-		flag=1;
-		return;
-	end
-	%initialize time and file presence test flag
-	time=0; ispresent=0;
-	disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
-
-	%loop till file .lock exist or time is up
-	while (ispresent==0 & time<timelimit)
+%loop till file .lock exist or time is up
+while (ispresent==0 & time<timelimit)
+	if strcmpi(oshostname(),cluster),
 		ispresent=exist(filename,'file');
 		pause(1);
 		time=time+1/60;
-	end
-
-	%build output
-	if (time>timelimit),
-		disp('Time limit exceeded. Increase md.settings.waitonlock');
-		disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
-		error(['waitonlock error message: time limit exceeded']);
-		flag=0;
 	else
-		flag=1;
+		pause(10);
+		fprintf('\rchecking for job completion (time = %3.2f min)    ',time);
+		ispresent=~system(command); if ispresent, fprintf('\n'); end
+		time=time+10/60;
 	end
 end
+
+%build output
+if (time>timelimit),
+	disp('Time limit exceeded. Increase md.settings.waitonlock');
+	disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
+	error(['waitonlock error message: time limit exceeded']);
+end
