1 |
adcroft |
1.1 |
function [vals] = mitgcmhistory(file,varargin) |
2 |
|
|
%vals = mitgcmhistory(FILE,EXPR1,...); |
3 |
|
|
% |
4 |
|
|
%Extracts the expressions "expr1","expr2",... from the file "file". |
5 |
|
|
%This assumes output in the standard form defined by the MITgcm |
6 |
|
|
%monitor package and is not a replacement for TEXTREAD. |
7 |
|
|
% |
8 |
|
|
%e.g. |
9 |
|
|
%>> vals=mitgcmhistory('output.txt','time_secondsf','ke_mean','ke_max'); |
10 |
|
|
%>> plot(vals(:,1)/86400,vals(:,2:3)); |
11 |
|
|
% |
12 |
|
|
% Written by adcroft@mit.edu, 2001 |
13 |
|
|
%$Header: |
14 |
|
|
|
15 |
|
|
if nargin<2 |
16 |
|
|
error('You must supply a filename and at least one search expression!') |
17 |
|
|
end |
18 |
|
|
|
19 |
|
|
tfile=sprintf('/tmp/grepexpr%15.15f',rand); |
20 |
|
|
for k=1:nargin-1; |
21 |
|
|
try |
22 |
dimitri |
1.2 |
eval(['!grep ' varargin{k} ' ' file ' | sed s/.\*=// | sed s/NAN/1.23456789/ > ' tfile]) |
23 |
dimitri |
1.3 |
|
24 |
|
|
% vals(:,k)=textread(tfile,'%f'); |
25 |
|
|
% When output file is from an ongoing integration, one or more of |
26 |
|
|
% the diagnostics may be missing at the last available time step. |
27 |
|
|
% The code below accomodates this difference in length. |
28 |
|
|
|
29 |
|
|
if k==1 |
30 |
|
|
vals(:,k)=textread(tfile,'%f'); |
31 |
|
|
lngt=length(vals(:,k)); |
32 |
|
|
else |
33 |
|
|
tmp=textread(tfile,'%f'); |
34 |
dimitri |
1.4 |
if abs(length(tmp)-lngt)>1 |
35 |
|
|
% try to read one line at a time in order to deal with special case |
36 |
|
|
% of values like, e.g.: " -2.9248686233802-321" |
37 |
|
|
fid=fopen(tfile); |
38 |
|
|
n=0; |
39 |
|
|
while(~feof(fid)) |
40 |
|
|
n=n+1; |
41 |
|
|
tmp2=fgetl(fid); |
42 |
|
|
val=sscanf(tmp2,'%f'); |
43 |
|
|
if length(val)>1 |
44 |
|
|
tmp(n)=0; |
45 |
|
|
else |
46 |
|
|
tmp(n)=val; |
47 |
|
|
end |
48 |
|
|
end |
49 |
|
|
fid=fclose(fid); |
50 |
|
|
tmp=tmp(1:n); |
51 |
|
|
end |
52 |
dimitri |
1.3 |
if abs(length(tmp)-lngt)>1 |
53 |
|
|
error(sprintf('An error occured while scanning for: %s',varargin{k})); |
54 |
|
|
else |
55 |
|
|
lngt=min(lngt,length(tmp)); |
56 |
|
|
vals(1:lngt,k)=tmp(1:lngt); |
57 |
|
|
end |
58 |
|
|
|
59 |
|
|
end |
60 |
adcroft |
1.1 |
delete(tfile) |
61 |
|
|
catch |
62 |
|
|
delete(tfile) |
63 |
|
|
error(sprintf('An error occured while scanning for: %s',varargin{k})); |
64 |
|
|
end |
65 |
|
|
end |
66 |
dimitri |
1.3 |
vals=vals(1:lngt,:); |