function values = nc_getlast(ncfile, var, num_records)
% NC_GETLAST:  Get last few datums from an unlimited NetCDF variable.
%
% USAGE: values = nc_getlast( netcdf_file, variable, n )
%
% PARAMETERS:
% Input:
%    netcdf_file:  
%        Name of input netcdf file.
%    variable:  
%        Name of NetCDF variable whose last few records we want.
%    n:  
%        Optional, default is 1.
%        This is the number of records to get, starting at the end
% Output:
%    values:  return data
%
% In case of an error, an exception is thrown.
%
%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Id: nc_getlast.m 1740 2006-08-29 16:15:23Z johnevans007 $
% $LastChangedDate: 2006-08-29 12:15:23 -0400 (Tue, 29 Aug 2006) $
% $LastChangedRevision: 1740 $
% $LastChangedBy: johnevans007 $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Show usage if too few arguments.
%
if (nargin <= 1)
	error ( '%s:  not enough input arguments.\n', mfilename );
end
if (nargin > 3) 
	error ( '%s:  must supply at least 2 and no more than 3 input arguments.\n', mfilename );
end

if ~ischar(ncfile) 
	error ( '%s:  First argument must be character.\n', mfilename );
end

if ~ischar(var) 
	error ( '%s:  2nd argument must be character.\n', mfilename );
end

if ( nargin == 2 )
	num_records = 1;
else
	if ~isnumeric(num_records) 
		error ( '%s:  3rd argument must be numeric.\n', mfilename );
	end
	if num_records <= 0
		error ( '%s:  3rd argument must be positive.\n', mfilename );
	end

end

varlist = { var };
nb = nc_getbuffer ( ncfile, varlist, -1, num_records );

values = nb.(var);

return

