inputdir=['/home/stephdut/Input/input_ecco/'];

%%% read grid
 gridname=['grid_ecco.nc'];
 X=ncread(gridname,'X');
 Y=ncread(gridname,'Y');
%
 nx=length(X); ny=length(Y); 

% owsm  66N 2E
  fi=find(X>1.8 & X<2.6); ix=fi(1); 
  fi=find(Y>65.6 & Y<66.6); iy=fi(1);

for ilam=1:13,
 if (ilam<10), numstr=['0',num2str(ilam)]; end
 if (ilam>9),  numstr=[num2str(ilam)]; end
 for ie=1:2,
  if (ie==1), filestr=['ecco_oasim_edp']; end
  if (ie==2), filestr=['ecco_oasim_esp']; end
% read files
  fid=fopen([inputdir,filestr,numstr,'_below.bin'],'r','b');
  field=fread(fid,'float32'); fclose(fid);
  field=reshape(field,nx,ny,12);
%%
% extract output
  output=squeeze(field(ix,iy,:));
%
% write out
  fid=fopen([filestr,numstr,'_below.bin'],'w','b');
  fwrite(fid,output,'float32');
 end % for ie,
end % for ilam
