Index: /issm/trunk/src/m/classes/public/waitonlock.m
===================================================================
--- /issm/trunk/src/m/classes/public/waitonlock.m	(revision 3174)
+++ /issm/trunk/src/m/classes/public/waitonlock.m	(revision 3175)
@@ -1,3 +1,3 @@
-function flag=waitonlock(md,executionpath)
+function flag=waitonlock(md,executionpath,login,port)
 %WAITONLOCK - wait for a file
 %
@@ -15,11 +15,35 @@
 %waitonlock will work if the lock is on the same machine only: 
 if ~strcmpi(oshostname(),cluster),
-	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;
+
+	if port, 
+		%there is a tunnel, so we have a short at looking for the lock file.
+
+		disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
+		time=0; ispresent=0;
+		while (ispresent==0 & time<timelimit)
+			[status, result]=system(['ssh -q -p ' num2str(port) ' ' login '@localhost "if ( -e ' executionpath '/' md.name '.lock ) echo 1"']);
+			ispresent=~isempty(result);
+			pause(10); %tunnel can be unstable, let's not use it too much
+			time=time+1/60;
+		end
+		
+		%build output
+		if (time>timelimit),
+			disp('Time limit exceeded. Increase md.waitonlock');
+			disp('The results must be loaded manually with md=loadresultsfromcluster(md).');
+			error(['waitonlock error message: time limit exceeded']);
+			flag=0;
+		else
+			flag=1;
+		end
 	else
-		flag=1;
+		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
 	end
 
