% meshmenu.m
% Designed to put together the files needed by quoddy.f to
% run a case.
% Aug 1995,   This version uses submesh and joinmesh routines

disp('Start of meshmenu.  You better have a mesh... loaded')
disp('Try running circlemaker.m if you have no mesh yet   ')
figure(1)

disp(' Set axis for first subset')
L = newaxis(meshnod)
lnod = inaxis(meshnod(:,2),meshnod(:,3),L);
[njoin,meshnod1,meshele1,bathy1,meshnodsub,meshelesub,bathysub] =...  
         submesh(lnod,meshnod,meshele,bathy)  ;

kquit = 8;
while (1)

k = menustay(' MESHMENU',...
'1 remove nodes','2 remove triangles','3 add nodes','4 move nodes',...
'5 make triangles','6 bathymetry set','7 New axis','8 quit');

 if k==kquit
  MFigH = findobj('Type','figure','Tag','Menu Figure');
  delete(MFigH)
  disp(' QUIT')
  break
 end

if k==1
disp(' Remove unwanted nodes by hand')
clf
[meshelesub]=rmvnod(L,meshelesub,meshnodsub);


elseif k==2
disp(' remove unwanted triangles by hand')
clf
[meshelesub]=rmvtri(L,meshelesub,meshnodsub);

elseif k==3
disp(' Add a few more points by hand')
clf
  [meshnodsub,bathysub]=putnodes(L,meshnodsub,bathysub);

elseif k==4
disp(' Move points about a bit')
clf
  [meshnodsub]=movenod(L,meshelesub,meshnodsub);

elseif k==5
disp(' Fill in triangles by hand')
clf
 [meshelesub]=maketri(L,meshelesub,meshnodsub);

elseif k==6
disp(' Set bathymetry')
clf
if exist('bathy')==0
bathy=bathyset(L,meshele,meshnod);
else
bathysub=bathyset(L,meshelesub,meshnodsub,bathysub);
end

elseif k==7
disp('Put back together the submesh and old mesh')
[meshnod,meshele,bathy]=...
   joinmesh(njoin,meshnod1,meshele1,bathy1,meshnodsub,meshelesub,bathysub);     
figure(1)
L = newaxis(meshnod)
lnod = inaxis(meshnod(:,2),meshnod(:,3),L);
[njoin,meshnod1,meshele1,bathy1,meshnodsub,meshelesub,bathysub] =...  
         submesh(lnod,meshnod,meshele,bathy)  ;
end


end

disp('Put back together the submesh and old mesh')
[meshnod,meshele,bathy]=...
   joinmesh(njoin,meshnod1,meshele1,bathy1,meshnodsub,meshelesub,bathysub);     

mesheleold = meshele;
meshnodold = meshnod;
bathyold = bathy;
bndeleold = bndele;

% remove unwanted triangles and nodes and check for righthandedness
[meshele,meshnod,bathy,bndele]=cleanup(meshele,meshnod,bathy,bndele);

% Make the boundary element array
bndele = findbndy(meshele,meshnod);
figure(2); plotmesh
paused('Paused:  Are the boundarys nice?')

% Tighten up the bandwidth of the mesh
[meshele,meshnod,bathy,bndele] = ...
        ordrmesh(meshele,meshnod,bathy,bndele);


% Make the boundary element array
bndele = findbndy(meshele,meshnod);

% amplitude and phase of sea surface for M2 forcing
bcs = ampphase(bndele,meshnod,bathy);

%  Add a few rivers to the boundaries
 [bcs,bndele] = bcsriver(bcs,meshnod,bndele);


filename = input('What is root name of the output mesh files >> ','s')
% call the file writing routine
fileout



