clear all

load('Z.dat');

 fid=fopen('lev01_silicate_ann-3d.bin','r','b');
%fid=fopen('glodap_preco2_fix_ann-3d.bin','r','b');
%fid=fopen('glodap_alk_ann-3d.bin','r','b');
%id=fopen('lev01_oxygen_micromolar_ann-3d.bin','r','b');

field=fread(fid,'float32'); fclose(fid);
field=reshape(field,360,160,23);
%
fi=find(field==0);
field(fi)=NaN;

tmp=squeeze(field(:,:,1));
figure, pcolor(tmp'); shading flat, colorbar
hold on
x1=290; x2=340; y1=110; y2=140;
plot([x1 x2 x2 x1 x1],[y1 y1 y2 y2 y1],'k-');

patch=squeeze(field(x1:x2,y1:y2,:));

for k=1:23,
 clear tmp, tmp=squeeze(patch(:,:,k));
 clear fi, fi=find(tmp>0);
 prof(k)=mean(tmp(fi));
end % for k

figure, plot(prof,Z);

fid=fopen('profile.dat','wt');
fprintf(fid,'%4.2f\n',prof); fclose(fid);
