function fld=readncom(fnam,Nt,Nx,Ny,Nz)

% Function fld=readncom(fnam,Nt,Nx,Ny,Nz)
% read and output real*4 model field from file fnam time step t
%
% INPUTS
% fnam  input path and file name
% Nt    number of time steps to read in (default 1)
% Nx*Ny*Nz  grid dimension (default 95*92*25)
%
% OUTPUTS
% fld   Nx*Ny*Nz*Nt*Nf output array, where Nf is the number of fields
%       to contour level k, time t use "contourf(fld(:,:,k,t,1)'), colorbar"
%       if input file name contains "vvc", output convention is
%       fld(:,:,:,:,1)  KPP viscosity
%       fld(:,:,:,:,2)  KPP temperature diffusivity
%       fld(:,:,:,:,3)  KPP salt diffusivity

if nargin<6, prec='real*4'; end
if nargin<5, Nz=25; end
if nargin<4, Ny=92; end
if nargin<3, Nx=95; end
if nargin<2, Nt=1; end
if nargin<1, error('please specify input file name'); end

fid=fopen(fnam,'r','ieee-be');

if isempty(findstr(fnam,'vvc'))

  fld=zeros(Nx,Ny,Nz,Nt);
  hbl=0;
  for t=1:Nt
    for y=1:Ny
      fld(:,y,:,t)=reshape(read_record(fid,prec,Nx*Nz*4),Nx,Nz);
    end
  end

else

  fld=zeros(Nx,Ny-1,Nz,Nt,3);
  for t=1:Nt
    for y=1:(Ny-1)
      tmp=read_record(fid,prec,(2+Nx*Nz*3)*4);
      fld(:,y,:,t,:)=reshape(tmp(3:length(tmp)),Nx,Nz,3);
    end
  end

end

fid=fclose(fid);
