function test_dimid ( ncfile )
% TEST_DIMID
%
% tests netcdf2 function



[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

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

[dimid, status] = mexnc('DIMID', ncid, 'x');
if ( dimid ~= 0 )
	msg = sprintf ( 'DIMID should have returned 0, not %d', dimid );
	error ( msg );
end
if ( status < 0 )
	error ( 'DIMID return status failed on bogus test' );
end

if dimid ~= xdimid
	err_msg = sprintf ( '%s:  DIMID did not return the expected value.\n', mfilename, ncerr );
	error ( err_msg );
end

%
% Try a bad ncid.
[test_dimid, status] = mexnc ( 'dimid', -2, 'x' );
if ( status >= 0 )
	err_msg = sprintf ( '%s:  DIMID succeeded on a bad ncid\n', mfilename );
	error ( err_msg );
end


%
% Try a bad name.
[test_dimid, status] = mexnc ( 'dimid', ncid, 'y' );
if ( status >= 0 )
	err_msg = sprintf ( '%s:  DIMID succeeded on a bad name\n', mfilename );
	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, 'DIMID succeeded.\n' );


return















