Meshtools December 18 1995
Bug fixes:
  insdbnd.m   Works now!  More efficient version under development still.
  findbndy.m  Includes a diagnostic for isolated empty elements.
  flatmesh.m  Extra input parameter for How Flat.
  ordrmesh.m  Took out time consuming plot of little value
  submesh.m   A few extra diagnostics are listed when it runs
   
Included now, but barely supported:  
moviemake.m     General purpose output program
fundyout.m      Outputs a file legible to TRIGTOFUNDY4.f
drogin.m        Reads in a fundy5 velocity file
drogplot.m      Plots fundy5 tidal ellipse


Meshtools                             November 1995.
***********************************************************
            by:
            Tom Gross
            Skidaway Inst. Oceanography,
            10 Ocean Science Circle,
            Savannah, GA, 31411
            tom@skio.peachnet.edu

Meshtools is a Matlab toolbox of functions for the generation
and manipulation of 2-D triangular element grids.  Tools are
provided to read in, manipulate and write out files of format
specific to the QUODDY FEM program.  Grids can be created from
an arbitrary input set of x,y,depth points or various fields of
points can be easily generated from within Matlab.  The
philosophy of Meshtools is that of a toolbox rather than a full
GUI'ed application.  However the script meshmenu.m launches an
interactive editing session where grid manipulations by mousing
about the screen is provided.  

Meshtools works only with Matlab version 4.1 or higher. 
Function names have been limited to 8 characters to make it
compatable with MS-DOS and Windows 3.1.  But developement was
performed on a Sun Sparc workstation so fewer guarantees apply
to Windows Matlab.  This is a sort of beta version.  Your
mileage may vary.  A few of the routines use functions provided
by the SaGA toolbox (See below).

***********************************************************
How to Obtain Copies:

Copies of these toolboxes can be obtained by FTP to
ftp.moby.peachnet.edu
login anonymous
cd pub/tom/meshtools
ls
-rw-r--r--  1 tom         52892 Nov  2 11:54 meshtool.tar.Z
-rw-r--r--  1 tom         52936 Nov  2 11:55 meshtool.zip
-rw-r--r--  1 tom        353026 Nov  2 11:07 saga.tar.Z
-rw-r--r--  1 tom        263385 Nov  2 11:02 saga.zip


  Refer questions and suggestions to:
            Tom Gross
            Skidaway Inst. Oceanography,
            10 Ocean Science Circle,
            Savannah, GA, 31411
            tom@skio.peachnet.edu

The triangulation routine, makeeles.m, uses calls
to some routines from the SaGA  - Spacial and Geometric 
Analysis toolbox.  SaGA, version 1.0 is SHAREWARE.
It may be distributed freely as such and used
for a trial period of 15 days free of charge.
After that it must be registered.
Kirill K. Pankratov,
Center of Meteorology and Physical Oceanography
Atmospheric & Planetary Sciences (EAPS)
Massachusetts Institute of Technology

***********************************************************
Data Types

The fundamental data types correspond to the standard
file types of QUODDY.  In matlab all variables are matrices
without labels, so the header information of the file types
is lost.  Although the matlab functions can take arbitrary
names for these variables, I usually use the names: meshnod,
meshele, bathy, bcs, bndele, meshcd.  Those names are assumed 
for the matlab scripts which are not functions.

Matlab variable,    column data      Quoddy file
meshnod            i, x(i),y(i)      mesh.nod
meshele            iele, ia,ib,ic    mesh.ele
bathy              i, depth(i)       mesh.bat
bcs                inode, amplitude, phase    mesh.bcs.s2c
bndele             i, node1,node2, 0, (1-land, 5-openwater)    mesh.bel
meshcd             i, Cd(i)          mesh.cd


***********************************************************
Listing of All Functions 
(except for saga toolbox).  

These are functions with passed variables, except for "scripts"
as indicated.  The string 'foo' or 'mesh' is used to indicate an
arbitrary root file name.  When L appears as a function
argument, it is an axis vector to define the area to be plotted,
e.g.  plot(x,y); axis(L); 

--------------------------------------------------------
File Input/Output

filein.m     [meshnod,meshele,bathy,bndele,bcs]=filein('mesh');
             Reads a set of Quoddy files with root file name 
fileout.m   Script which writes out to Quoddy files the default variable
            names of meshnod, meshele, bathy, bcs, bndele, meshcd.
            The root name is specified by:  filename='mesh';
            It also writes all of them to 'meshall.mat'.
reads2r.m  [ s2r ]=reads2r('foo');   % Reads foo.s2r file.  
reads3r.m  [ s3r,nlevels ]=reads3r('foo');  % Reads foo.s3r file.
readv1r.m  [ zt ]=readv1r('foo');  % Reads foo.v1r file.
readv2r.m  [ uvt ]=readv2r('foo');  % Reads foo.v2r file.
readv3r.m  [ v3r,nlevels ]=readv3r('foo');  % Reads foo.v3r file.

--------------------------------------------------------
Mesh Menu Editing Tools

meshmenu.m   Main script for editing existing meshes.  Default variable names.
             Meshmenu.m calls most of the following edit routines.
submesh.m    Seperates a mesh into two meshes which can be edited more quickly
              One of the slowest routines.
joinmesh.m   Joins back to one mesh the results of submesh.m
bathyset.m   bathynew = bathyset(L,meshele,meshnod,bathy);  %Edits Bathymetry
findnod.m    l = findnod(L,meshnod); % Identify nodes by pointing mouse
maketri.m    [meshelenew]=maketri(L,meshele,meshnod); %Join nodes into triangle
movenod.m    [meshnodnew]=movenod(L,meshele,meshnod); % Nudge nodes with mouse
newaxis.m    L = newaxis(meshnod); % Rubberband box used to set new axis
picknode.m    No longer used.
putnodes.m   [meshnodnew,bathynew]=putnodes(L,meshnod,bathy); 
             %Create nodes with mouse
rmvnod.m     [meshelenew]=rmvnod(L,meshele,meshnod); 
             %Removes the elements which use the mouse selected node.  
              Does not remove the node from the meshnod list.  
rmvtri.m    [meshelenew]=rmvtri(L,meshele,meshnod); 
             %Removes mouse selected elements.
rmtrinod.m  meshnodnew = rmtrinod(L,meshnod);
             %Removes a lot of nodes at once by clicking on a triangular area.
rmwinnod.m  meshnodnew = rmwinnod(meshnod,lhighlight);
             %Uses a rubberband box to remove a lot of nodes
sprngnod.m  [meshnodnew,S]=sprngnod(meshele,meshnod,bndele,[nrelaxes]);
             %  Like nodes with springs between this will relax all the 
             nodes to centers of their connections

--------------------------------------------------------
Mesh Cleaning Tools

reorder.m   [meshele2,meshnod2,bathy2,meshcd2,bndele2] = ...
                 reorder(meshele,meshnod,bathy,meshcd,bndele);
            % Reorders the mesh to achieve a narrow bandwidth by
            using SYMRCM Reverse Cuthill-McKee ordering.
rghthand.m  meshelenew = rghthand(meshele,meshnod);
            % Fixes lefthanded elements and removes degenerate elements.
              One of the slowest routines
reelems.m   [meshelenew,meshnodnew,bathynew,meshcdnew,bndelenew]= ...
                 reelems(meshele,meshnod,bathy,meshcd,bndele);
            % Eliminate nodes not used in elements and renumbers everything
cleanup.m   Combines rghthand and reelems
flatmesh.m  [lgood, lbad] = flatmesh(meshele,meshnod);
            % Identify elements which are "too flat" .02pi>angle or .98pi<angle
ordrmesh.m  [elems2,nodes2,bathy2,bndele2] =ordrmesh(elems,nodes,bathy,bndele);
            % Same as reorder, but without meshcd.

--------------------------------------------------------
Mesh Initial Creation Tools:

circ2.m      Script to create circular mesh. Uses makeeles
makeeles.m   [meshele] = makeeles(meshnod);
             % Uses Saga toolbox to create an element mesh
              One of the slowest routines
gridmake.m   [ meshele]=gridmake(meshnodold);
             % A nicer interface to makeeles to eliminate extra 
             elements created in a convex boundary.
pullnods.m   [meshnodnew]= pullnods(meshele,meshnod,bndele,Radius,Xc,Yc);
             %Moves the outermost nodes to a surrounding circle. Used by circ2
smoobathy.m  [bathynew, D] = smoobathy(meshele,meshnod,bathy);
             % Smooths bathymetry by applying a distance weighted average.
trigrid.m    [x,y,meshele,meshnod]=trigrid(dx,dy,lx,ly,angle);
             % Creates a hexagon area of mesh.
bumpcos.m    [bathy]=bumpcos(meshnod,dep,hh,hl,hs,hw)
bumpexp.m    [bathy]=bumpexp(meshnod,dep,hh,hl,hs,hw)
             % Creates bumps in topography for use by circ2


--------------------------------------------------------
Special Usage Boundary Conditions.  

Individual copies of these are usually kept in the directories
containing the mesh data.  In that manner they are called rather
than the default versions.

ampphase.m  [bcs] = ampphase(bndele,meshnod,bathy);
            User designed routine to create amplitude and phase at B.C's
findbndy.m  [bndelenew] = findbndy(meshele,meshnod);
             Creates the boundary of the mesh.  Needs to be altered
             to determine land and water boundaries.
             % Add statements to get indexs of ocean in lopen, e.g.
                 lopen = find(meshnod(:,3)<40000);
                 bndelenew(lopen,5)=ones(length(lopen),1)*5; % open sea
bcsriver.m  [bcsnew, bndelenew] = bcsriver(bcs,meshnod,bndele);
            % This is used to specify Riverine B.C.'s

--------------------------------------------------------
Graphics:

contmesh.m  contmesh(L,meshele,meshnod,fieldnod,fieldcontours);
            % Plots contours of fieldnod on the triangular grid 
depthmap.m  Script to plot a nice bathymetry of WassawSound.  Example.
fieldmap.m  fieldmap(L,meshele,meshnod,fieldnod,fieldrange); 
            %  plots a colored field to triangular grid 
plot3prj.m  plot3prj(x,y,z,L) 
            % plots x,y,z with projections to the walls.
ploteles.m  [ax] = ploteles(meshele,meshnod);
            A very useful plot of the triangles of the mesh.
plotmap.m   plotmap(L,meshele,meshnod,scalarnod,'interp');
            %  Another color contour map of scalar
plotmesh.m  A useful script because I am forever doing  
             plot(meshnod(:,2),meshnod(:,3),'o')
plottest.m  Another useful script to check on the mesh.


--------------------------------------------------------
Miscellaneous Tools:

inaxis.m     [yesno] = inaxis(x,y); 
              % Returns 1 if x,y is inside current axis
interior.m   [yesno] = interior(x,y,x3,y3); 
             % Returns 1 if x,y is inside triangle made up of x3(1:3),y3(1:3)
intersec.m   z = intersec(x,y); %Form the intersection of the 'sets' x and y
union.m      z = union(x,y);    %Form the union of the 'sets' x and y
startup.m    Special use matlab startup to add meshtools, saga to matlabpath.
menustay.m   Adaptation of menu.m which keeps window open, but not active.
insdmesh.m   [lout, lin] = insdmesh(bndele,meshnod); 
             % Indices of meshnod which are inside or outside of bndele. 
              Useful when adding nodes.
insdbnd.m    ln = insdbnd(bndx,bndy,x,y); 
             Indices of x,y inside bndx,bndy


