Index: /issm/trunk-jpl/src/m/solve/waitonlock.m
===================================================================
--- /issm/trunk-jpl/src/m/solve/waitonlock.m	(revision 14355)
+++ /issm/trunk-jpl/src/m/solve/waitonlock.m	(revision 14356)
@@ -2,5 +2,7 @@
 %WAITONLOCK - wait for a file
 %
-%   This routine will return when a file named 'filename' is written to disk.
+%   This routine will return when a file named 'lockfilename' is written to disk.
+%   Also check for outlog file be cause it might bewritten several seconds
+%   after the lock file.
 %   If the time limit given in input is exceeded, return 0
 %
@@ -10,9 +12,10 @@
 %Return if waitonlock < 0 (no need to wait)
 
-%Get filename (lock file) and options
+%Get lockfilename (lock file) and options
 executionpath = md.cluster.executionpath;
 timelimit     = md.settings.waitonlock;
-filename      = [executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock'];
 cluster       = md.cluster;
+lockfilename  = [executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.lock'];
+logfilename   = [executionpath '/' md.private.runtimename '/' md.miscellaneous.name '.outlog'];
 
 %If we are using the generic cluster in interactive mode, job is already complete
@@ -24,6 +27,6 @@
 
 %initialize time and file presence test flag
-time=0; ispresent=0;
-disp(['waiting for ' filename ' hold on... (Ctrl+C to exit)'])
+time=0; ispresent=0; time0=clock;
+disp(['waiting for ' lockfilename ' hold on... (Ctrl+C to exit)'])
 
 %prepare command if the job is not running on the local machine
@@ -35,7 +38,7 @@
 	end
 	if port,
-		command = ['ssh -l ' login ' -p ' num2str(port) ' localhost " [ -f ' filename '  ]" 2>/dev/null'];
+		command = ['ssh -l ' login ' -p ' num2str(port) ' localhost "[ -f ' lockfilename ' ] && [ -f ' logfilename ' ]" 2>/dev/null'];
 	else
-		command = ['ssh -l ' login ' ' cluster.name ' " [ -f ' filename '  ]" 2>/dev/null'];
+		command = ['ssh -l ' login ' ' cluster.name ' "[ -f ' lockfilename ' ] && [ -f ' logfilename ' ]" 2>/dev/null'];
 	end
 end
@@ -44,12 +47,13 @@
 while (ispresent==0 & time<timelimit)
 	if strcmpi(oshostname(),cluster),
-		ispresent=exist(filename,'file');
 		pause(1);
-		time=time+1/60;
+		ispresent=(exist(lockfilename,'file') & exist(logfilename,'file'));
+		time=etime(clock,time0)/60;
 	else
 		pause(10);
+		time=etime(clock,time0)/60;
 		fprintf('\rchecking for job completion (time = %3.2f min)    ',time);
-		ispresent=~system(command); if ispresent, fprintf('\n'); end
-		time=time+10/60;
+		ispresent=~system(command);
+		if ispresent, fprintf('\n'); end
 	end
 end
