Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/grepread.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
9bfa9538f6 Alis*0001 function [vals] = grepread(file,varargin)
                0002 % VALS = GREPREAD(FILE,EXPR1,...);
                0003 %
                0004 % Extracts the expressions "expr1","expr2",... from the file "file".
                0005 % This assumes output in the standard form defined by the MITgcm
                0006 % monitor package and is not a replacement for TEXTREAD.
7f0effbc3a Jean*0007 %
9bfa9538f6 Alis*0008 % e.g.
                0009 % >> vals=grepread('output.txt','time_secondsf','ke_mean','ke_max');
                0010 % >> plot(vals(:,1)/86400,vals(:,2:3));
                0011 
                0012 if nargin<2
                0013  error('You must supply a filename and at least one search expression!')
                0014 end
                0015 
                0016 tfile=sprintf('/tmp/grepexpr%15.15f',rand);
                0017 for k=1:nargin-1;
                0018  try
b9d1708fe8 Alis*0019   eval(['!grep ' varargin{k} ' ' file ' | sed s/.\*=// | sed s/NAN/1.23456789/ >! ' tfile])
9bfa9538f6 Alis*0020   vals(:,k)=textread(tfile,'%f');
                0021   delete(tfile)
                0022  catch
                0023   delete(tfile)
                0024   error(sprintf('An error occured while scanning for: %s',varargin{k}));
                0025  end
                0026 end