function test_inq_varid ( ncfile )
% TEST_INQ_VARID
%
% Tests number of dimensions, variables, global attributes, record dimension for
% foo.nc.  Also tests helper routines, "nc_inq_ndims", "nc_inq_nvars", "nc_inq_ncatts".
%
% Tests bad ncid as well.
%

%
% Create a netcdf file with
[ncid, status] = mexnc ( 'create', ncfile, nc_clobber_mode );
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end


%
% DIMDEF
[xdimid, status] = mexnc ( 'def_dim', ncid, 'x', 20 );
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end
[ydimid, status] = mexnc ( 'def_dim', ncid, 'y', 24 );
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end
[zdimid, status] = mexnc ( 'def_dim', ncid, 'z', 32 );
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end


%
% VARDEF
[xdvarid, status] = mexnc ( 'def_var', ncid, 'x_double', 'double', 1, xdimid );
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end


[varid, status] = mexnc('INQ_VARID', ncid, 'x_double');
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end

if ( varid ~= xdvarid )
	err_msg = sprintf ( '%s:  INQ_VARID did not return the expected value\n', mfilename );
	error ( err_msg );
end

%
% test non existance "xx_double"
[varid, status] = mexnc('INQ_VARID', ncid, 'xx_double');
if ( status >= 0 )
	msg = sprintf ( '%s:  INQ_VARID returned non-negative status for non-existing variable\n', mfilename );
	error ( msg );
end
%
% test bad ncid
[varid, status] = mexnc('INQ_VARID', -20, 'x_double');
if ( status >= 0 )
	msg = sprintf ( '%s:  INQ_VARID returned non-negative status for non-existing variable\n', mfilename );
	error ( msg );
end

% ENDEF
[status] = mexnc ( 'end_def', ncid );
if ( status < 0 )
	error ( 'ENDEF failed with write' );
end



status = mexnc ( 'close', ncid );
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	msg = sprintf ( '%s:  %s\n', mfilename, ncerr );
	error ( msg );
end

return












