function a=read(varstr,ts,N,siz,form)
%--------------------------
% function a=read(extension,ts,N,siz,form)
% input:
%   varstr   : 'HEFF', 'AREA', etc.
%   ts       : timestep, integer
%   N        : number of tiles, 4? 8?
%   siz      : size of each tile, [10 8 1] for labsea
%   form     : 'real*4', 'real*8', etc.
% output:
%   a        : [20 16 1]
%   example: a=read('HEFF',4,[10 8 1],'real*4')
% ATN 18-Feb-2011
%-------------------------
ts_str=myint2str(ts,10);
nx=siz(1);ny=siz(2);if(length(siz)==3);nz=siz(3);else;nz=[];end;
if (N==4);
  nx_lim=N/2;ny_lim=N/2;
elseif(N==1);
  nx_lim=N;ny_lim=N;
end;

a=nan(nx*nx_lim,ny*ny_lim,nz);

for i=1:nx_lim
    stri=myint2str(i,3);
    ix1=(i-1)*nx+1;ix2=i*nx;

    for j=1:ny_lim;
      iy1=(j-1)*ny+1;iy2=j*ny;
      strj=myint2str(j,3);
      temp=readbin([varstr,'.',ts_str,'.',stri,'.',strj,'.data'],siz,1,form);
      a(ix1:ix2,iy1:iy2,1:nz)=temp;
      
    end;
end;

return
