function test_dim_inq ( ncfile )
% TEST_DIM_INQ
%
% Tests number of dimensions, variables, global attributes, record dimension for
% foo.nc.  
%
% Tests bad ncid as well.
%

%
% Create a netcdf file with
[ncid, status] = mexnc ( 'create', ncfile, nc_clobber_mode );
if ( status < 0 )
	error ( 'CREATE failed' );
end


%
% DIMDEF
[xdimid, status] = mexnc ( 'def_dim', ncid, 'x', 20 );
if ( status < 0 )
	error ( 'DEF_DIM failed on X' );
end
[ydimid, status] = mexnc ( 'def_dim', ncid, 'y', 24 );
if ( status < 0 )
	error ( 'DEF_DIM failed on y' );
end
[zdimid, status] = mexnc ( 'def_dim', ncid, 'z', 32 );
if ( status < 0 )
	error ( 'DEF_DIM failed on z' );
end


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


%
% dimension 0 should have name 'x', length 20
[name, length, status] = mexnc('DIMINQ', ncid, xdimid);
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  DIMINQ failed, ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end

if ~strcmp ( name, 'x' )
	msg = sprintf ( 'DIMINQ returned ''%s'' as a name, but it should have been ''x''', name );
	error ( msg );
end
if ( length ~= 20 )
	msg = sprintf ( 'DIMINQ returned %d as x''s length, but it should have been 20', length );
	error ( msg );
end


%
% a test for a file that is not there
[name, length, status] = mexnc('DIMINQ', -3, xdimid);
if ( status >= 0 )
	error ( 'DIMINQ failed on bogus ncid' );
end

%
% a test for a dimension that is not there
[name, length, status] = mexnc('DIMINQ', ncid, -7);
if ( status >= 0 )
	error ( 'DIMINQ failed on bogus varid' );
end

fprintf ( 1, 'DIMINQ succeeded\n' );







status = mexnc ( 'close', ncid );
if ( status < 0 )
	error ( 'CLOSE failed on nowrite' );
end



return












