function test_inq_dim ( ncfile )
% TEST_INQ_DIM
%
% 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 )
	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('INQ_DIM', ncid, xdimid);
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  INQ_DIM failed, ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end

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



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




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

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



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




%
% INQ_DIMLEN
[dimlen, status] = mexnc('INQ_DIMLEN', ncid, xdimid);
if ( status < 0 )
	ncerr = mexnc ( 'strerror', status );
	err_msg = sprintf ( '%s:  INQ_DIMLEN failed, ''%s''\n', mfilename, ncerr );
	error ( err_msg );
end
if ( length ~= 20 )
	msg = sprintf ( 'INQ_DIMLEN returned %d as x''s length, but it should have been 20', length );
	error ( msg );
end



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





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



return











