--- MITgcm_contrib/mitgcm_tools/mitgcmhistory.m 2003/09/25 13:42:11 1.1.1.1 +++ MITgcm_contrib/mitgcm_tools/mitgcmhistory.m 2007/12/10 05:28:50 1.3 @@ -19,11 +19,32 @@ tfile=sprintf('/tmp/grepexpr%15.15f',rand); for k=1:nargin-1; try - eval(['!grep ' varargin{k} ' ' file ' | sed s/.\*=// | sed s/NAN/1.23456789/ >! ' tfile]) - vals(:,k)=textread(tfile,'%f'); + eval(['!grep ' varargin{k} ' ' file ' | sed s/.\*=// | sed s/NAN/1.23456789/ > ' tfile]) + + % vals(:,k)=textread(tfile,'%f'); + + % When output file is from an ongoing integration, one or more of + % the diagnostics may be missing at the last available time step. + % The code below accomodates this difference in length. + + if k==1 + vals(:,k)=textread(tfile,'%f'); + lngt=length(vals(:,k)); + else + tmp=textread(tfile,'%f'); + % allow + if abs(length(tmp)-lngt)>1 + error(sprintf('An error occured while scanning for: %s',varargin{k})); + else + lngt=min(lngt,length(tmp)); + vals(1:lngt,k)=tmp(1:lngt); + end + + end delete(tfile) catch delete(tfile) error(sprintf('An error occured while scanning for: %s',varargin{k})); end end +vals=vals(1:lngt,:);