function [GP,GPx,GPy,GPz]=TestNXQ(gridpt,N,Ngp,Nxi3)
% This test function drops down grid points in a closure element and determines the
% NXQ array describing their connectivity.
%
% The NXQ array is then used to construct structured elements about the specified
% gridpt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set up grid point locations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GP = CreateGPLocs(N,Ngp,Nxi3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NXQ values
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NXQ = CreateNXQ(N,Ngp,Nxi3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Give structured elements surrounding specified grid point
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Apex case
if NXQ(1,1,gridpt) == 0 & NXQ(2,1,gridpt) < 0
fprintf(' apex\n');
type=1;
% Sector edge case
elseif NXQ(1,1,gridpt) == -1 & NXQ(2,1,gridpt) == -3
fprintf(' type 2\n');
type=2;
% General interior grid point case
elseif NXQ(1,1,gridpt) == -2 & NXQ(2,1,gridpt) == -2
fprintf(' type 5\n');
type=5;
% Grid point at xi1=1 and sector edge
elseif NXQ(1,1,gridpt) == -1
fprintf(' type 3\n');
type=3;
% Grid point at xi1 = 1
elseif NXQ(1,1,gridpt) == -2
fprintf(' type 4\n');
type=4;
% Otherwise
else
fprintf(' not a closure element grid point\n');
end;
e = SElem(type, gridpt, NXQ);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Setting up line arrays for drawing - not important!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% determine number of elements and number of vertices
[ne,nv]=size(e);
e = [e(:,1:2),e(:,4),e(:,3),e(:,5:6),e(:,8),e(:,7)];
indexn=reshape([[e(:,:);e(:,2:4),e(:,1),e(:,6:8),e(:,5)]';[e(:,1:4)',e(:,5:8)']],ne*12,2)';
tmp = GP(:,1);
GPx = tmp(indexn);
tmp = GP(:,2);
GPy = tmp(indexn);
tmp = GP(:,3);
GPz = tmp(indexn);