| 1 |
function [data,xax,yax,zax,months,time,dim] = ... |
function [data,xax,yax,zax,months,time,dim] = ... |
| 2 |
DiagLoadGradsData(Grads,dad,fln) |
DiagLoadGradsData(Grads,dad,fln,DiagDebug) |
| 3 |
|
|
| 4 |
|
|
| 5 |
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 6 |
|
% Parse table file % |
| 7 |
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 8 |
|
|
| 9 |
|
format = 'NONSEQUENTIAL'; |
| 10 |
|
|
|
% Read table file. |
|
| 11 |
tablfile = [dad,'/',Grads,'.tabl']; |
tablfile = [dad,'/',Grads,'.tabl']; |
|
datafile = [dad,'/',Grads,'.data']; |
|
| 12 |
file = textread(tablfile,'%s','delimiter','\n','whitespace',''); |
file = textread(tablfile,'%s','delimiter','\n','whitespace',''); |
| 13 |
|
|
| 14 |
for iline = 1:length(file) |
for iline = 1:length(file) |
| 15 |
rem = file{iline}; tokens = {}; itoken = 0; |
rem = file{iline}; tokens = {}; itoken = 0; |
| 16 |
while isstr(rem) |
while isstr(rem) |
| 80 |
elseif isequal(monchar,'NOV'), inimonth = 11; |
elseif isequal(monchar,'NOV'), inimonth = 11; |
| 81 |
elseif isequal(monchar,'DEC'), inimonth = 12; end |
elseif isequal(monchar,'DEC'), inimonth = 12; end |
| 82 |
num = str2num(tokens{2}); |
num = str2num(tokens{2}); |
| 83 |
months=[inimonth:num]; time=months/12; nt = length(months); |
months=[inimonth:num+inimonth-1]; |
| 84 |
|
time=months/12; nt = length(months); |
| 85 |
|
|
| 86 |
end |
end |
| 87 |
|
|
| 89 |
nv = str2num(tokens{2}); |
nv = str2num(tokens{2}); |
| 90 |
VARSline = iline; |
VARSline = iline; |
| 91 |
end |
end |
|
|
|
| 92 |
if isequal(tokens{1},fln) |
if isequal(tokens{1},fln) |
| 93 |
FIELDline = iline; |
FIELDline = iline; |
| 94 |
index = iline - VARSline; |
ivar = iline - VARSline; |
| 95 |
end |
end |
| 96 |
|
|
| 97 |
if isequal(tokens{1},'UNDEF') |
if isequal(tokens{1},'UNDEF') |
| 98 |
undef = str2num(tokens{2}); |
undef = str2num(tokens{2}); |
| 99 |
end |
end |
| 100 |
|
|
| 101 |
|
if isequal(tokens{1},'FORMAT') |
| 102 |
|
if isequal(tokens{2},'SEQUENTIAL') |
| 103 |
|
format = 'SEQUENTIAL'; |
| 104 |
|
else |
| 105 |
|
disp(['Unrecognized grads FORMAT: ',tokens{2}]); |
| 106 |
|
end |
| 107 |
|
end |
| 108 |
|
|
| 109 |
|
if isequal(tokens{1},'DSET') |
| 110 |
|
datafile = [dad,tokens{2}(2:end)]; |
| 111 |
|
end |
| 112 |
|
|
| 113 |
end |
end |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 117 |
|
% Verification and debugging % |
| 118 |
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 119 |
|
|
| 120 |
|
if DiagDebug, disp([' Debug -- grads data format: ',format]); end |
| 121 |
|
|
| 122 |
% Verify that things are there. |
% Verify that things are there. |
| 123 |
parameters = {'xax' ,'yax' ,'zax' ,'time','nv' ,'undef','index'}; |
parameters = {'xax' ,'yax' ,'zax' ,'time','nv' ,'undef','ivar'}; |
| 124 |
GRADSnames = {'XDEF','YDEF','ZDEF','TDEF','VARS','UNDEF',fln }; |
GRADSnames = {'XDEF','YDEF','ZDEF','TDEF','VARS','UNDEF',fln }; |
| 125 |
for ii = 1:length(parameters) |
for ii = 1:length(parameters) |
| 126 |
try |
try |
| 127 |
eval([parameters{ii},';']); |
eval([parameters{ii},';']); |
| 130 |
end |
end |
| 131 |
end |
end |
| 132 |
|
|
| 133 |
% Read in grads data using axis infomation. |
|
| 134 |
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 135 |
|
% Read data file % |
| 136 |
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 137 |
|
|
| 138 |
tol = 1e-5; |
tol = 1e-5; |
| 139 |
fid=fopen(datafile,'r','b'); |
fid=fopen(datafile,'r','b'); |
| 140 |
data = fread(fid,'real*4'); |
data = fread(fid,'real*4'); |
| 141 |
fclose(fid); |
fclose(fid); |
| 142 |
|
if isequal(format,'SEQUENTIAL') |
| 143 |
|
index=true([nx*ny*nz*nv*nt+2*nv*nt,1]); |
| 144 |
|
index([1:nx*ny*nz+2:end])=false; |
| 145 |
|
index([2:nx*ny*nz+2:end])=false; |
| 146 |
|
data = data(index); |
| 147 |
|
end |
| 148 |
data = reshape(data,[nx,ny,nz,nv,nt]); |
data = reshape(data,[nx,ny,nz,nv,nt]); |
| 149 |
data = squeeze(data(:,:,:,index,:)); |
data = squeeze(data(:,:,:,ivar,:)); |
| 150 |
data( abs((data-undef)/undef) < tol ) = NaN; |
data( abs((data-undef)/undef) < tol ) = NaN; |