function test_get_var1_text ( ncfile )
%TEST_GET_VAR1_TEXT:  tests GET_VAR1_TEXT function
%
% Test expected to succeed:
%   Uses PUT_VAR_TEXT to write out the alphabet, then read back the letter b.
% Test expected to fail:
%   Try to retrieve from position -1.
%   Try to retrieve from position 27.
% 
%

[ncid, status] = mexnc ( 'create', ncfile, nc_clobber_mode );
if ( status ~= 0 )
	error ( 'OPEN failed with write' );
end




[xdimid, status] = mexnc ( 'def_dim', ncid, 'x', 26 );
if ( status ~= 0 )
	error ( 'DEF_DIM failed on X' );
end

[x_char_varid, status] = mexnc ( 'def_var', ncid, 'x_char', 'char', 1, xdimid );
if ( status ~= 0 )
	error ( 'DEF_VAR failed on x_char' );
end

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


[varid, status] = mexnc('INQ_VARID', ncid, 'x_char' );
if ( status ~= 0 )
	msg = sprintf ( '%s:  INQ_VARID failed on %s\n', mfilename, varnames{j} );
	error ( msg );
end
	
status = mexnc ( 'PUT_VAR_TEXT', ncid, varid, 'abcdefghijklmnopqrstuvwxyz' );
if ( status ~= 0 )
	msg = sprintf ( '%s:  PUT_VAR1_TEXT failed\n', mfilename );
	error ( msg );
end
	
status = mexnc ( 'SYNC', ncid );
if ( status ~= 0 )
	ncerr_mesg = mexnc ( 'strerror', status );
	msg = sprintf ( '%s:  PUT_VAR1_TEXT failed, (%s)\n', mfilename, ncerr_msg );
	error ( msg );
end
	
fprintf ( 1, '    testing x_char by GET_VAR1_TEXT...\n' );
[value,status] = mexnc ( 'GET_VAR1_TEXT', ncid, varid, [1] );
if ( status ~= 0 )
	msg = sprintf ( '%s:  GET_VAR1_TEXT failed\n', mfilename );
	error ( msg );
end
	
if ( ~strcmp(value,'b') )
	msg = sprintf ( '%s:  value returned by GET_VAR1_TEXT ''%s'' for x_char wasn''t what it should be, %s\n', mfilename, value, 'b'  );
	error ( msg );
end






%
% Test for a bad get
[value,status] = mexnc ( 'GET_VAR1_TEXT', ncid, varid, [-1] );
if ( status == 0 )
	msg = sprintf ( '%s:  GET_VAR1_TEXT succeeded when it should have failed\n', mfilename );
	error ( msg );
end
[value,status] = mexnc ( 'GET_VAR1_TEXT', ncid, varid, [27] );
if ( status == 0 )
	msg = sprintf ( '%s:  GET_VAR1_SCHAR succeeded when it should have failed\n', mfilename );
	error ( msg );
end








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

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

return






