function [yn, return_status] = nc_isvar ( ncfile, varname )
% NC_ISVAR:  yes if the given variable is in the netcdf file
%
% USAGE:  [yn, status] = nc_isvar ( ncfile, varname );
%
% PARAMETERS:
% Input:
%     ncfile:  
%        Input netcdf file name.
%     varname:  
%        variable to check
% Output:
%     yn:  
%        0 if the answer is no, 1 if yes.
%     status:  
%        -1 if the routine fails because of bad input
%         0 if the routine succeeds

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Name:  $
% $Id: nc_isvar.m,v 1.1 2005/06/29 16:07:00 brian Exp $
% AUTHOR:  johnevans@acm.org
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




% assume false until we know otherwise
yn = 0;
return_status = -1;




% Show usage if too few arguments.
%
if nargin~=2 
	fprintf ( 2, '%s:  must have two input arguments.\n', mfilename );
	return;
end


%
% Open netCDF file
%
[ncid,status ]=mexnc('open',ncfile, nc_nowrite_mode );
if status ~= 0
	fprintf ( 2, '%s:  mexnc:open failed on %s.\n', mfilename, ncfile );
	return
end

% Suppress warning messages from netCDF
[status]=mexnc('setopts',0);

[varid, status] = mexnc('INQ_VARID', ncid, varname);
if ( status < 0 )
	yn = 0;
	return_status = 0;
elseif varid >= 0
	yn = 1;
	return_status = 0;
else
	return_status = -1;
end

mexnc('close',ncid);
return




