function [x,y]=halfcirclegeom(bs,s)
%CIRCLEG	Gives geometry data for the circleg PDE model
%
%   NE=CIRCLEG gives the number of boundary segment
%
%   D=CIRCLEG(BS) gives a matrix with one column for each boundary segment
%   specified in BS.
%   Row 1 contains the start parameter value.
%   Row 2 contains the end parameter value.
%   Row 3 contains the number of the left hand region.
%   Row 4 contains the number of the right hand region.
%
%   [X,Y]=CIRCLEG(BS,S) gives coordinates of boundary points. BS specifies the
%   boundary segments and S the corresponding parameter values. BS may be
%   a scalar.

 
 d=[
   0 0  % start parameter value
   1 1  % end parameter value
   1 1  % left hand region
   0 0  % right hand region
 ];
 
 
 nbs=size(d,2);

% return the number of segments. 

 if nargin==0,
   x=nbs; % number of boundary segments
   return
 end
 
 
 bs1=bs(:)';
 
 if find(bs1<1 | bs1>nbs),
   error('Non existent boundary segment number')
 end


% return the approproate part of d ?
 
 if nargin==1,
   x=d(:,bs1);
   return
 end


% now calculate the coordinates 

 x=zeros(size(s));
 y=zeros(size(s));
 [m,n]=size(bs);
 if m==1 & n==1,
   bs=bs*ones(size(s)); % expand bs
 elseif m~=size(s,1) | n~=size(s,2),
   error('bs must be scalar or of same size as s');
 end
 
 if ~isempty(s),

% boundary segment 1
% this is the halfcircle

 ii=find(bs==1);
 x(ii)=cos(pi*s(ii));
 y(ii)=sin(pi*s(ii));

% boundary segment 2
% this is the 

 ii=find(bs==2);
 x(ii)=2*s(ii)-1; 
 y(ii)=0*ii;

% note that the segments are oriented!
 end


