function test_def_var ( ncfile )
% TEST_DEF_VAR
%



[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

[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

%
% Try a bad ncid.
[test_dimid, status] = mexnc ( 'def_var', -2, 'x_double', 'double', 1, xdimid );
if ( status >= 0 )
	err_msg = sprintf ( '%s:  DEF_VAR succeeded on a bad ncid\n', mfilename );
	error ( err_msg );
end


%
% Try a bad dimid.
[test_dimid, status] = mexnc ( 'def_var', ncid, 'x_double', 'double', 1, -3 );
if ( status >= 0 )
	err_msg = sprintf ( '%s:  DEF_VAR succeeded on a bad ncid\n', mfilename );
	error ( err_msg );
end


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


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


fprintf ( 1, 'DEF_VAR succeeded.\n' );


return













