--- MITgcm_contrib/mitgcm_tools/mitgcmhistory.m 2003/09/25 13:42:11 1.1.1.1 +++ MITgcm_contrib/mitgcm_tools/mitgcmhistory.m 2007/12/12 23:42:46 1.4 @@ -19,11 +19,48 @@ 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'); + if abs(length(tmp)-lngt)>1 + % try to read one line at a time in order to deal with special case + % of values like, e.g.: " -2.9248686233802-321" + fid=fopen(tfile); + n=0; + while(~feof(fid)) + n=n+1; + tmp2=fgetl(fid); + val=sscanf(tmp2,'%f'); + if length(val)>1 + tmp(n)=0; + else + tmp(n)=val; + end + end + fid=fclose(fid); + tmp=tmp(1:n); + end + 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,:);